gvsig-projects-pool / org.gvsig.online / trunk / org.gvsig.online / org.gvsig.online.swing / org.gvsig.online.swing.impl / src / main / java / org / gvsig / online / swing / impl / OnlineSwingCommons.java @ 9512
History | View | Annotate | Download (20.2 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2020 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
18 |
*
|
19 |
* For any additional information, do not hesitate to contact us
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
21 |
*/
|
22 |
|
23 |
package org.gvsig.online.swing.impl; |
24 |
|
25 |
import java.awt.Color; |
26 |
import java.awt.Component; |
27 |
import java.awt.Font; |
28 |
import java.awt.font.TextAttribute; |
29 |
import java.io.IOException; |
30 |
import java.io.InputStream; |
31 |
import java.net.URL; |
32 |
import java.util.HashMap; |
33 |
import java.util.List; |
34 |
import java.util.Map; |
35 |
import java.util.Objects; |
36 |
import java.util.Properties; |
37 |
import java.util.Set; |
38 |
import javax.swing.ImageIcon; |
39 |
import javax.swing.JOptionPane; |
40 |
import javax.swing.SwingUtilities; |
41 |
import org.apache.commons.io.FilenameUtils; |
42 |
import org.apache.commons.lang3.StringUtils; |
43 |
import org.gvsig.fmap.dal.DALLocator; |
44 |
import org.gvsig.fmap.dal.DataManager; |
45 |
import org.gvsig.fmap.dal.DataStoreParameters; |
46 |
import org.gvsig.fmap.dal.StoresRepository; |
47 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
48 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
49 |
import org.gvsig.fmap.geom.Geometry; |
50 |
import org.gvsig.fmap.geom.GeometryUtils; |
51 |
import org.gvsig.fmap.geom.primitive.Envelope; |
52 |
import org.gvsig.online.lib.api.OnlineLocator; |
53 |
import org.gvsig.online.lib.api.OnlineManager; |
54 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_AUTHENTICATION_EXPIRED; |
55 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_CANT_AUTHENTICATE_USER; |
56 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_INVALID_AUTHENTICATION_TOKEN; |
57 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_INVALID_USERCODE; |
58 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_USER_NOT_AUTHORIZED; |
59 |
import static org.gvsig.online.lib.api.OnlineManager.OP_DELETE; |
60 |
import static org.gvsig.online.lib.api.OnlineManager.OP_INSERT; |
61 |
import static org.gvsig.online.lib.api.OnlineManager.OP_UPDATE; |
62 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_CONFLICT; |
63 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_CORRUPT; |
64 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_DISCONNECTED; |
65 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_LOCAL_MODIFIED; |
66 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_LOCAL_NEW; |
67 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_LOCAL_OUTDATED; |
68 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_LOCAL_OUTDATED_AND_MODIFIED; |
69 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_LOCAL_UNMODIFIED; |
70 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_NOT_IN_LOCAL_OR_REMOTE; |
71 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_REMOTE_NEW; |
72 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_UNKNOWN; |
73 |
import org.gvsig.online.lib.api.OnlineRuntimeException; |
74 |
import org.gvsig.online.lib.api.workingcopy.OnlineEntity; |
75 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy; |
76 |
import org.gvsig.online.swing.api.OnlineSwingLocator; |
77 |
import org.gvsig.online.swing.api.OnlineSwingManager; |
78 |
import org.gvsig.tools.ToolsLocator; |
79 |
import org.gvsig.tools.dataTypes.Coercion; |
80 |
import org.gvsig.tools.dataTypes.CoercionException; |
81 |
import org.gvsig.tools.i18n.I18nManager; |
82 |
import org.gvsig.tools.swing.api.DataTypes; |
83 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
84 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
85 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
86 |
import org.gvsig.tools.util.MapBuilder; |
87 |
import org.slf4j.LoggerFactory; |
88 |
|
89 |
/**
|
90 |
*
|
91 |
* @author gvSIG Team
|
92 |
*/
|
93 |
public class OnlineSwingCommons { |
94 |
public static final String BOOKMARKSANDHISTORY_SITE_URL = "OnlineSiteURL"; |
95 |
|
96 |
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(OnlineSwingCommons.class); |
97 |
|
98 |
private static final String ID_COLOR_LOCAL_NEW = "COLOR_LOCAL_NEW"; |
99 |
private static final String ID_COLOR_LOCAL_MODIFIED = "COLOR_LOCAL_MODIFIED"; |
100 |
private static final String ID_COLOR_LOCAL_UNMODIFIED = "COLOR_LOCAL_UNMODIFIED"; |
101 |
private static final String ID_COLOR_LOCAL_AND_REPOSITORY_MODIFIED = "COLOR_LOCAL_AND_REPOSITORY_MODIFIED"; |
102 |
private static final String ID_COLOR_REPOSITORY_NEW = "COLOR_REPOSITORY_NEW"; |
103 |
private static final String ID_COLOR_REPOSITORY_MODIFIED = "COLOR_REPOSITORY_MODIFIED"; |
104 |
private static final String ID_COLOR_CONFLICT = "COLOR_CONFLICT"; |
105 |
private static final String ID_COLOR_UNKNOWN_STATE = "COLOR_UNKNOWN_STATE"; |
106 |
private static final String ID_COLOR_DISCONNECTED_STATE = "COLOR_DISCONNETED_STATE"; |
107 |
|
108 |
private static final Color COLOR_LOCAL_NEW = Color.GREEN.darker(); |
109 |
private static final Color COLOR_LOCAL_MODIFIED = Color.BLUE.darker(); |
110 |
private static final Color COLOR_LOCAL_UNMODIFIED = Color.BLACK; |
111 |
private static final Color COLOR_LOCAL_AND_REPOSITORY_MODIFIED = Color.RED.brighter(); |
112 |
private static final Color COLOR_REPOSITORY_NEW = Color.ORANGE.darker().darker(); |
113 |
private static final Color COLOR_REPOSITORY_MODIFIED = Color.MAGENTA.darker(); |
114 |
private static final Color COLOR_CONFLICT = Color.RED; |
115 |
private static final Color COLOR_UNKNOWN_STATE = Color.LIGHT_GRAY; |
116 |
private static final Color COLOR_DISCONNECTED_STATE = Color.DARK_GRAY; |
117 |
|
118 |
private static final Map<Integer,String> OPERATION_LABELS_UI = new MapBuilder<Integer,String>() |
119 |
.add(OP_DELETE, "_Online_operation_delete")
|
120 |
.add(OP_UPDATE, "_Online_operation_update")
|
121 |
.add(OP_INSERT, "_Online_operation_insert")
|
122 |
// .add(OP_ADD_ENTITY, "_Online_operation_add_entity")
|
123 |
.build(); |
124 |
|
125 |
private static Map<String, Color> entityColors = null; |
126 |
|
127 |
static {
|
128 |
loadColors(); |
129 |
} |
130 |
|
131 |
public static String getHTMLColorTag(Color color, String text) { |
132 |
return getHTMLColorTag(color, false, text); |
133 |
} |
134 |
|
135 |
public static String getHTMLColorTag(Color color, boolean bold, String text) { |
136 |
return getHTMLColorTag(color, bold, false, text); |
137 |
} |
138 |
|
139 |
public static String getHTMLColorTag(Color color, boolean bold, boolean strikethrough, String text) { |
140 |
String pattern;
|
141 |
if( bold && strikethrough ) {
|
142 |
pattern = "<html><font color='rgb(%s, %s, %s)'><b><s>%s</b></s></font></html>";
|
143 |
} else if( bold ) { |
144 |
pattern = "<html><font color='rgb(%s, %s, %s)'><b>%s</b></font></html>";
|
145 |
} else if( strikethrough ) { |
146 |
pattern = "<html><font color='rgb(%s, %s, %s)'><s>%s</s></font></html>";
|
147 |
} else {
|
148 |
pattern = "<html><font color='rgb(%s, %s, %s)'>%s</font></html>";
|
149 |
} |
150 |
String tag = String.format(pattern, |
151 |
color.getRed(), |
152 |
color.getGreen(), |
153 |
color.getBlue(), |
154 |
text |
155 |
); |
156 |
return tag;
|
157 |
} |
158 |
|
159 |
public static String getHTMLFontColorTag(Color color, boolean bold, boolean strikethrough, String text) { |
160 |
String pattern;
|
161 |
if( bold && strikethrough ) {
|
162 |
pattern = "<font color='rgb(%s, %s, %s)'><b><s>%s</b></s></font>";
|
163 |
} else if( bold ) { |
164 |
pattern = "<font color='rgb(%s, %s, %s)'><b>%s</b></font>";
|
165 |
} else if( strikethrough ) { |
166 |
pattern = "<font color='rgb(%s, %s, %s)'><s>%s</s></font>";
|
167 |
} else {
|
168 |
pattern = "<font color='rgb(%s, %s, %s)'>%s</font>";
|
169 |
} |
170 |
String tag = String.format(pattern, |
171 |
color.getRed(), |
172 |
color.getGreen(), |
173 |
color.getBlue(), |
174 |
text |
175 |
); |
176 |
return tag;
|
177 |
} |
178 |
|
179 |
public static String getHTMLColorTag(int state, String text) { |
180 |
switch (state) {
|
181 |
case STATE_CORRUPT:
|
182 |
case STATE_CORRUPT+STATE_DISCONNECTED:
|
183 |
return getHTMLColorTag(entityColors.get(ID_COLOR_DISCONNECTED_STATE), false, true, text); |
184 |
case STATE_DISCONNECTED:
|
185 |
return getHTMLColorTag(entityColors.get(ID_COLOR_DISCONNECTED_STATE), false, text); |
186 |
case STATE_LOCAL_UNMODIFIED:
|
187 |
return getHTMLColorTag(entityColors.get(ID_COLOR_LOCAL_UNMODIFIED), false, text); |
188 |
case STATE_LOCAL_NEW:
|
189 |
return getHTMLColorTag(entityColors.get(ID_COLOR_LOCAL_NEW), false, text); |
190 |
case STATE_LOCAL_MODIFIED:
|
191 |
return getHTMLColorTag(entityColors.get(ID_COLOR_LOCAL_MODIFIED), false, text); |
192 |
case STATE_LOCAL_OUTDATED:
|
193 |
return getHTMLColorTag(entityColors.get(ID_COLOR_REPOSITORY_MODIFIED), false, text); |
194 |
case STATE_LOCAL_OUTDATED_AND_MODIFIED:
|
195 |
return getHTMLColorTag(entityColors.get(ID_COLOR_LOCAL_AND_REPOSITORY_MODIFIED), false, text); |
196 |
case STATE_CONFLICT:
|
197 |
return getHTMLColorTag(entityColors.get(ID_COLOR_CONFLICT), false, text); |
198 |
case STATE_REMOTE_NEW:
|
199 |
return getHTMLColorTag(entityColors.get(ID_COLOR_REPOSITORY_NEW), false, text); |
200 |
default:
|
201 |
return getHTMLColorTag(entityColors.get(ID_COLOR_UNKNOWN_STATE), false, text); |
202 |
} |
203 |
} |
204 |
|
205 |
public static String getHTMLColorTag(OnlineWorkingcopy workspace, String entityName) { |
206 |
if( workspace == null ) { |
207 |
return entityName;
|
208 |
} |
209 |
OnlineEntity lentity = workspace.getWorkspaceEntity(entityName); |
210 |
if( lentity==null ) { |
211 |
return getHTMLColorTag(STATE_REMOTE_NEW,entityName);
|
212 |
} |
213 |
return getHTMLColorTag(lentity.getState(),entityName);
|
214 |
} |
215 |
|
216 |
public static String getStateDescription(OnlineWorkingcopy workspace, String entityName) { |
217 |
if( workspace == null ) { |
218 |
return getStateDescription(STATE_UNKNOWN);
|
219 |
} |
220 |
OnlineEntity lentity = workspace.getWorkspaceEntity(entityName); |
221 |
if( lentity==null ) { |
222 |
return getStateDescription(STATE_REMOTE_NEW);
|
223 |
} |
224 |
return getStateDescription(lentity.getState());
|
225 |
} |
226 |
|
227 |
public static String getStateDescription(int state) { |
228 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
229 |
switch (state) {
|
230 |
case STATE_DISCONNECTED:
|
231 |
return i18n.getTranslation("_Disconnected"); |
232 |
case STATE_CORRUPT:
|
233 |
return i18n.getTranslation("_Corrupt"); |
234 |
case STATE_CORRUPT+STATE_DISCONNECTED:
|
235 |
return i18n.getTranslation("_Corrupt")+"/"+i18n.getTranslation("_Disconnected"); |
236 |
case STATE_LOCAL_UNMODIFIED:
|
237 |
return i18n.getTranslation("_Unmodified_locally"); |
238 |
case STATE_LOCAL_NEW:
|
239 |
return i18n.getTranslation("_New_locally"); |
240 |
case STATE_LOCAL_MODIFIED:
|
241 |
return i18n.getTranslation("_Modified_locally"); |
242 |
case STATE_LOCAL_OUTDATED:
|
243 |
return i18n.getTranslation("_Modified_in_the_remote"); |
244 |
case STATE_LOCAL_OUTDATED_AND_MODIFIED:
|
245 |
return i18n.getTranslation("_Modified_in_the_remote_and_locally"); |
246 |
case STATE_CONFLICT:
|
247 |
return i18n.getTranslation("_Conflict"); |
248 |
case STATE_REMOTE_NEW:
|
249 |
return i18n.getTranslation("_New_in_the_remote"); |
250 |
case STATE_NOT_IN_LOCAL_OR_REMOTE:
|
251 |
return i18n.getTranslation("_It_is_not_in_local_or_in_the_remote"); |
252 |
default:
|
253 |
return i18n.getTranslation("_Unknow_state"); |
254 |
} |
255 |
} |
256 |
|
257 |
public static void setColorCompoment(Component c, Color color, boolean bold) { |
258 |
setColorCompoment(c, color, bold, false);
|
259 |
} |
260 |
|
261 |
public static void setColorCompoment(Component c, Color color, boolean bold, boolean strikethrough) { |
262 |
if( bold ) {
|
263 |
Font f = c.getFont();
|
264 |
Map attributes = f.getAttributes();
|
265 |
attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); |
266 |
c.setFont(c.getFont().deriveFont(attributes)); |
267 |
} |
268 |
c.setForeground(color); |
269 |
} |
270 |
|
271 |
public static void setColorCompoment(Component c, int state) { |
272 |
switch (state) {
|
273 |
case STATE_CORRUPT:
|
274 |
case STATE_CORRUPT+STATE_DISCONNECTED:
|
275 |
setColorCompoment(c, entityColors.get(ID_COLOR_DISCONNECTED_STATE), false, true); |
276 |
break;
|
277 |
case STATE_DISCONNECTED:
|
278 |
setColorCompoment(c, entityColors.get(ID_COLOR_DISCONNECTED_STATE), false);
|
279 |
break;
|
280 |
case STATE_LOCAL_UNMODIFIED:
|
281 |
setColorCompoment(c, entityColors.get(ID_COLOR_LOCAL_UNMODIFIED), false);
|
282 |
break;
|
283 |
case STATE_LOCAL_NEW:
|
284 |
setColorCompoment(c, entityColors.get(ID_COLOR_LOCAL_NEW), false);
|
285 |
break;
|
286 |
case STATE_LOCAL_MODIFIED:
|
287 |
setColorCompoment(c, entityColors.get(ID_COLOR_LOCAL_MODIFIED), false);
|
288 |
break;
|
289 |
case STATE_LOCAL_OUTDATED:
|
290 |
setColorCompoment(c, entityColors.get(ID_COLOR_REPOSITORY_MODIFIED), false);
|
291 |
break;
|
292 |
case STATE_LOCAL_OUTDATED_AND_MODIFIED:
|
293 |
setColorCompoment(c, entityColors.get(ID_COLOR_LOCAL_AND_REPOSITORY_MODIFIED), false);
|
294 |
break;
|
295 |
case STATE_CONFLICT:
|
296 |
setColorCompoment(c, entityColors.get(ID_COLOR_CONFLICT), false);
|
297 |
break;
|
298 |
case STATE_REMOTE_NEW:
|
299 |
setColorCompoment(c, entityColors.get(ID_COLOR_REPOSITORY_NEW), false);
|
300 |
break;
|
301 |
default:
|
302 |
setColorCompoment(c, entityColors.get(ID_COLOR_UNKNOWN_STATE), false);
|
303 |
break;
|
304 |
} |
305 |
} |
306 |
|
307 |
public static boolean notInSwingThreadInvokeLater(Runnable x) { |
308 |
if( SwingUtilities.isEventDispatchThread() ) { |
309 |
return false; |
310 |
} |
311 |
SwingUtilities.invokeLater(x);
|
312 |
return true; |
313 |
} |
314 |
|
315 |
public static void cleanHighligthed() { |
316 |
OnlineManager manager = OnlineLocator.getOnlineManager(); |
317 |
OnlineSwingManager swingManager = OnlineSwingLocator.getOnlineSwingManager(); |
318 |
swingManager.getDefaultServices().cleanHighligthed(); |
319 |
} |
320 |
|
321 |
public static void refreshDocument(FeatureStore store) { |
322 |
// OnlineManager manager = OnlineLocator.getOnlineManager();
|
323 |
OnlineSwingManager swingManager = OnlineSwingLocator.getOnlineSwingManager(); |
324 |
swingManager.getDefaultServices().refreshDocument(store); |
325 |
} |
326 |
|
327 |
public static void refreshDocument(Set<FeatureStore> stores) { |
328 |
// OnlineManager manager = OnlineLocator.getOnlineManager();
|
329 |
OnlineSwingManager swingManager = OnlineSwingLocator.getOnlineSwingManager(); |
330 |
swingManager.getDefaultServices().refreshDocument(stores); |
331 |
} |
332 |
|
333 |
public static Geometry createBBox(Geometry geom1, Geometry geom2){ |
334 |
if(geom1 == null && geom2 == null){ |
335 |
return null; |
336 |
} |
337 |
Envelope env = GeometryUtils.createEnvelope(Geometry.SUBTYPES.GEOM2D); |
338 |
if(geom1 != null){ |
339 |
env.add(geom1); |
340 |
} |
341 |
if(geom2 != null){ |
342 |
env.add(geom2); |
343 |
} |
344 |
return env.getGeometry();
|
345 |
} |
346 |
|
347 |
public static boolean showAuthenticationErrors(String title, OnlineRuntimeException ex) { |
348 |
return showAuthenticationErrors(title, ex.getErrnum(), ex.getMessage());
|
349 |
} |
350 |
|
351 |
public static boolean showAuthenticationErrors(String title, int errNum) { |
352 |
return showAuthenticationErrors(title, errNum, null); |
353 |
} |
354 |
|
355 |
public static boolean showAuthenticationErrors(String title, int errNum, String message) { |
356 |
if(StringUtils.isBlank(message)){
|
357 |
message = OnlineLocator.getOnlineManager().getErrorMessage(errNum); |
358 |
} |
359 |
switch (errNum) {
|
360 |
case ERR_CANT_AUTHENTICATE_USER:
|
361 |
case ERR_INVALID_AUTHENTICATION_TOKEN:
|
362 |
case ERR_USER_NOT_AUTHORIZED:
|
363 |
case ERR_AUTHENTICATION_EXPIRED:
|
364 |
case ERR_INVALID_USERCODE:
|
365 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
366 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
367 |
dialogs.messageDialog( |
368 |
"[" + errNum + "] " + message, |
369 |
i18n.getTranslation(title), |
370 |
JOptionPane.WARNING_MESSAGE
|
371 |
); |
372 |
return true; |
373 |
} |
374 |
return false; |
375 |
} |
376 |
|
377 |
public static boolean showAuthenticationRequiredMessage(String title) { |
378 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
379 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
380 |
dialogs.messageDialog( |
381 |
i18n.getTranslation("_Authorization_required_for_this_operation"),
|
382 |
i18n.getTranslation(title), |
383 |
JOptionPane.WARNING_MESSAGE
|
384 |
); |
385 |
return true; |
386 |
} |
387 |
|
388 |
private static void loadColors() { |
389 |
entityColors = new HashMap<>(); |
390 |
entityColors.put(ID_COLOR_LOCAL_NEW,COLOR_LOCAL_NEW); |
391 |
entityColors.put(ID_COLOR_LOCAL_MODIFIED,COLOR_LOCAL_MODIFIED); |
392 |
entityColors.put(ID_COLOR_LOCAL_UNMODIFIED,COLOR_LOCAL_UNMODIFIED); |
393 |
entityColors.put(ID_COLOR_LOCAL_AND_REPOSITORY_MODIFIED,COLOR_LOCAL_AND_REPOSITORY_MODIFIED); |
394 |
entityColors.put(ID_COLOR_REPOSITORY_NEW,COLOR_REPOSITORY_NEW); |
395 |
entityColors.put(ID_COLOR_REPOSITORY_MODIFIED,COLOR_REPOSITORY_MODIFIED); |
396 |
entityColors.put(ID_COLOR_CONFLICT,COLOR_CONFLICT); |
397 |
entityColors.put(ID_COLOR_UNKNOWN_STATE,COLOR_UNKNOWN_STATE); |
398 |
entityColors.put(ID_COLOR_DISCONNECTED_STATE,COLOR_DISCONNECTED_STATE); |
399 |
InputStream x = OnlineSwingCommons.class.getClassLoader().getResourceAsStream("/VCSGisEntityColors.properties"); |
400 |
Coercion toColor = ToolsLocator.getDataTypesManager().getCoercion(DataTypes.COLOR); |
401 |
if(x != null){ |
402 |
try {
|
403 |
Properties prop = new Properties(); |
404 |
prop.load(x); |
405 |
for (Map.Entry<Object, Object> entry : prop.entrySet()) { |
406 |
try {
|
407 |
entityColors.put((String)entry.getKey(), (Color) toColor.coerce(entry.getValue())); |
408 |
} catch (CoercionException ex) {
|
409 |
LOGGER.trace("Can't parse color "+Objects.toString(entry.getKey()), ex);
|
410 |
//DO NOTHING
|
411 |
} |
412 |
} |
413 |
} catch (IOException ex) { |
414 |
LOGGER.trace("Can't load colors.", ex);
|
415 |
//DO NOTHING
|
416 |
} |
417 |
} |
418 |
|
419 |
} |
420 |
|
421 |
public static boolean hasConflictTheDatamodelWithOtherModelAlreadyRegistered(OnlineWorkingcopy workspace, String dataModelName) { |
422 |
DataManager dataManager = DALLocator.getDataManager(); |
423 |
String wsUrl = workspace.getExplorerParameters().getUrl();
|
424 |
StoresRepository globalRepository = dataManager.getStoresRepository(); |
425 |
for (OnlineEntity entity : workspace.getWorkspaceEntities()) {
|
426 |
List<String> entityModels = entity.getDataModelsAsList(); |
427 |
if( entityModels.contains(dataModelName) ) {
|
428 |
DataStoreParameters params = globalRepository.get(entity.getEntityName()); |
429 |
if( params instanceof JDBCStoreParameters ) { |
430 |
String registeredUrl = ((JDBCStoreParameters) params).getUrl();
|
431 |
if( !StringUtils.equals(wsUrl, registeredUrl)) {
|
432 |
return true; |
433 |
} |
434 |
} |
435 |
} |
436 |
} |
437 |
return false; |
438 |
} |
439 |
|
440 |
public static ImageIcon loadImage(String imageName) { |
441 |
String name = FilenameUtils.getBaseName(imageName);
|
442 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
443 |
if (theme.exists(name)) {
|
444 |
return theme.get(name);
|
445 |
} |
446 |
URL url = OnlineSwingCommons.class.getResource("images/"+name + ".png"); |
447 |
if (url == null) { |
448 |
return null; |
449 |
} |
450 |
return new ImageIcon(url); |
451 |
} |
452 |
|
453 |
public static String getOperationLabel(int operation) { |
454 |
return OPERATION_LABELS_UI.getOrDefault(operation, "unknown"); |
455 |
} |
456 |
|
457 |
|
458 |
} |