--- title: Creating a Theme in Eclipse order: 6 layout: page --- [[themes.eclipse]] = Creating a Theme in Eclipse The Eclipse plugin automatically creates a theme stub for new Vaadin projects. It also includes a wizard for creating new custom themes. Do the following steps to create a new theme. . Select "File > New > Other..." in the main menu or right-click the [guilabel]#Project Explorer# and select "New > Other...". A window will open. . In the [guilabel]#Select a wizard# step, select the "Vaadin > Vaadin Theme" wizard. + image::img/eclipse-theme-new.png[] + Click [guibutton]#Next# to proceed to the next step. . In the [guilabel]#Create a new Vaadin theme# step, you have the following settings: [guilabel]#Project#(mandatory):: The project in which the theme should be created. [guilabel]#Theme name#(mandatory):: The theme name is used as the name of the theme folder and in a CSS tag (prefixed with " [literal]#++v-theme-++#"), so it must be a proper identifier. Only latin alphanumerics, underscore, and minus sign are allowed. [guilabel]#Modify application classes to use theme#(optional):: The setting allows the wizard to write a code statement that enables the theme in the constructor of the selected application (UI) class(es). If you need to control the theme with dynamic logic, you can leave the setting unchecked or change the generated line later. + image::img/eclipse-theme-settings.png[] + Click [guibutton]#Finish# to create the theme. The wizard creates the theme folder under the [filename]#WebContent/VAADIN/themes# folder and the actual style sheet as [filename]#mytheme.scss# and [filename]#styles.scss# files, as illustrated in <>. [[figure.eclipse.theme.created]] .Newly Created Theme image::img/eclipse-theme-created-annotated-hi.png[] The created theme extends a built-in base theme with an [literal]#++@import++# statement. See the explanation of theme inheritance in <>. Notice that the [filename]#reindeer# theme is not located in the [filename]#widgetsets# folder, but in the Vaadin JAR. See <> for information for serving the built-in themes. If you selected a UI class or classes in the [guilabel]#Modify application classes to use theme# in the theme wizard, the wizard will add the [literal]#++@Theme++# annotation to the UI class. If you later rename the theme in Eclipse, notice that changing the name of the folder will not automatically change the [literal]#++@Theme++# annotation. You need to change such references to theme names in the calls manually. ut-const'>add-default-request-timeout-const Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
blob: 8d99a268dc043a8b6013ae5dd7e1d2c2bd7a12a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php

/**
 * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
 * SPDX-License-Identifier: AGPL-3.0-only
 */
namespace OC\Files\Cache;

use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Storage\IStorage;
use OCP\IDBConnection;
use Psr\Log\LoggerInterface;

/**
 * Handle the mapping between the string and numeric storage ids
 *
 * Each storage has 2 different ids
 * 	a string id which is generated by the storage backend and reflects the configuration of the storage (e.g. 'smb://user@host/share')
 * 	and a numeric storage id which is referenced in the file cache
 *
 * A mapping between the two storage ids is stored in the database and accessible through this class
 *
 * @package OC\Files\Cache
 */
class Storage {
	/** @var StorageGlobal|null */
	private static $globalCache = null;
	private $storageId;
	private $numericId;

	/**
	 * @return StorageGlobal
	 */
	public static function getGlobalCache() {
		if (is_null(self::$globalCache)) {
			self::$globalCache = new StorageGlobal(\OC::$server->getDatabaseConnection());
		}
		return self::$globalCache;
	}

	/**
	 * @param \OC\Files\Storage\Storage|string $storage
	 * @param bool $isAvailable
	 * @throws \RuntimeException
	 */
	public function __construct($storage, $isAvailable, IDBConnection $connection) {
		if ($storage instanceof IStorage) {
			$this->storageId = $storage->getId();
		} else {
			$this->storageId = $storage;
		}
		$this->storageId = self::adjustStorageId($this->storageId);

		if ($row = self::getStorageById($this->storageId)) {
			$this->numericId = (int)$row['numeric_id'];
		} else {
			$available = $isAvailable ? 1 : 0;
			if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId, 'available' => $available])) {
				$this->numericId = $connection->lastInsertId('*PREFIX*storages');
			} else {
				if ($row = self::getStorageById($this->storageId)) {
					$this->numericId = (int)$row['numeric_id'];
				} else {
					throw new \RuntimeException('Storage could neither be inserted nor be selected from the database: ' . $this->storageId);
				}
			}
		}
	}

	/**
	 * @param string $storageId
	 * @return array
	 */
	public static function getStorageById($storageId) {
		return self::getGlobalCache()->getStorageInfo($storageId);
	}

	/**
	 * Adjusts the storage id to use md5 if too long
	 * @param string $storageId storage id
	 * @return string unchanged $storageId if its length is less than 64 characters,
	 *                else returns the md5 of $storageId
	 */
	public static function adjustStorageId($storageId) {
		if (strlen($storageId) > 64) {
			return md5($storageId);
		}
		return $storageId;
	}

	/**
	 * Get the numeric id for the storage
	 *
	 * @return int
	 */
	public function getNumericId() {
		return $this->numericId;
	}

	/**
	 * Get the string id for the storage
	 *
	 * @param int $numericId
	 * @return string|null either the storage id string or null if the numeric id is not known
	 */
	public static function getStorageId(int $numericId): ?string {
		$storage = self::getGlobalCache()->getStorageInfoByNumericId($numericId);
		return $storage['id'] ?? null;
	}

	/**
	 * Get the numeric of the storage with the provided string id
	 *
	 * @param $storageId
	 * @return int|null either the numeric storage id or null if the storage id is not known
	 */
	public static function getNumericStorageId($storageId) {
		$storageId = self::adjustStorageId($storageId);

		if ($row = self::getStorageById($storageId)) {
			return (int)$row['numeric_id'];
		} else {
			return null;
		}
	}

	/**
	 * @return array [ available, last_checked ]
	 */
	public function getAvailability() {
		if ($row = self::getStorageById($this->storageId)) {
			return [
				'available' => (int)$row['available'] === 1,
				'last_checked' => $row['last_checked']
			];
		} else {
			return [
				'available' => true,
				'last_checked' => time(),
			];
		}
	}

	/**
	 * @param bool $isAvailable
	 * @param int $delay amount of seconds to delay reconsidering that storage further
	 */
	public function setAvailability($isAvailable, int $delay = 0) {
		$available = $isAvailable ? 1 : 0;
		if (!$isAvailable) {
			\OC::$server->get(LoggerInterface::class)->info('Storage with ' . $this->storageId . ' marked as unavailable', ['app' => 'lib']);
		}

		$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
		$query->update('storages')
			->set('available', $query->createNamedParameter($available))
			->set('last_checked', $query->createNamedParameter(time() + $delay))
			->where($query->expr()->eq('id', $query->createNamedParameter($this->storageId)));
		$query->execute();
	}

	/**
	 * Check if a string storage id is known
	 *
	 * @param string $storageId
	 * @return bool
	 */
	public static function exists($storageId) {
		return !is_null(self::getNumericStorageId($storageId));
	}

	/**
	 * remove the entry for the storage
	 *
	 * @param string $storageId
	 */
	public static function remove($storageId) {
		$storageId = self::adjustStorageId($storageId);
		$numericId = self::getNumericStorageId($storageId);

		$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
		$query->delete('storages')
			->where($query->expr()->eq('id', $query->createNamedParameter($storageId)));
		$query->execute();

		if (!is_null($numericId)) {
			$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
			$query->delete('filecache')
				->where($query->expr()->eq('storage', $query->createNamedParameter($numericId)));
			$query->execute();
		}
	}

	/**
	 * remove the entry for the storage by the mount id
	 *
	 * @param int $mountId
	 */
	public static function cleanByMountId(int $mountId) {
		$db = \OC::$server->getDatabaseConnection();

		try {
			$db->beginTransaction();

			$query = $db->getQueryBuilder();
			$query->select('storage_id')
				->from('mounts')
				->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
			$storageIds = $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
			$storageIds = array_unique($storageIds);

			$query = $db->getQueryBuilder();
			$query->delete('filecache')
				->where($query->expr()->in('storage', $query->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY)));
			$query->executeStatement();

			$query = $db->getQueryBuilder();
			$query->delete('storages')
				->where($query->expr()->in('numeric_id', $query->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY)));
			$query->executeStatement();

			$query = $db->getQueryBuilder();
			$query->delete('mounts')
				->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
			$query->executeStatement();

			$db->commit();
		} catch (\Exception $e) {
			$db->rollBack();
			throw $e;
		}
	}
}