001: /**
002: * <copyright>
003: * </copyright>
004: *
005: * $Id: LayerItemProvider.java 23845 2007-01-12 22:38:27Z jeichar $
006: */package net.refractions.udig.project.internal.provider;
007:
008: import java.util.Collection;
009: import java.util.HashMap;
010: import java.util.List;
011: import java.util.Map;
012:
013: import net.refractions.udig.project.ILayer;
014: import net.refractions.udig.project.IMap;
015: import net.refractions.udig.project.internal.Layer;
016: import net.refractions.udig.project.internal.ProjectPackage;
017: import net.refractions.udig.project.internal.ProjectPlugin;
018: import net.refractions.udig.project.internal.impl.LayerImpl;
019: import net.refractions.udig.project.internal.render.CompositeRenderContext;
020: import net.refractions.udig.project.preferences.PreferenceConstants;
021: import net.refractions.udig.project.render.IRenderManager;
022: import net.refractions.udig.project.render.IRenderer;
023:
024: import org.eclipse.emf.common.notify.AdapterFactory;
025: import org.eclipse.emf.common.notify.Notification;
026: import org.eclipse.emf.common.util.ResourceLocator;
027: import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
028: import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
029: import org.eclipse.emf.edit.provider.IItemLabelProvider;
030: import org.eclipse.emf.edit.provider.IItemPropertySource;
031: import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
032: import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
033: import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
034: import org.eclipse.emf.edit.provider.ItemProviderAdapter;
035: import org.eclipse.emf.edit.provider.ViewerNotification;
036: import org.eclipse.jface.resource.ImageDescriptor;
037: import org.eclipse.jface.viewers.IColorProvider;
038: import org.eclipse.swt.SWT;
039: import org.eclipse.swt.graphics.Color;
040: import org.eclipse.swt.graphics.Image;
041: import org.eclipse.swt.widgets.Display;
042: import org.eclipse.ui.PlatformUI;
043: import org.eclipse.ui.preferences.ScopedPreferenceStore;
044:
045: /**
046: * This is the item provider adapter for a {@link net.refractions.udig.project.internal.Layer}
047: * object. <!-- begin-user-doc --> The handling of this class is very important:
048: * <ul>
049: * <li>No method can block
050: * <li>if you have to catch an IOException you are doing it wrong
051: * <li>Responsible for providing an ImageDescriptor (not an Image)
052: * </ul>
053: * <!-- end-user-doc -->
054: *
055: * @generated
056: */
057: public class LayerItemProvider extends ItemProviderAdapter implements
058: IEditingDomainItemProvider, IStructuredItemContentProvider,
059: ITreeItemContentProvider, IItemLabelProvider, IColorProvider,
060: IItemPropertySource {
061:
062: /** Properties Key used to cache generated name in layer.getProperties() */
063: public static final String GENERATED_NAME = "generated title"; //$NON-NLS-1$
064:
065: /** Propeties Key used to cache generated icon in layer.getProperties() */
066: public static final String GENERATED_ICON = "generated icon"; //$NON-NLS-1$
067:
068: /**
069: * <!-- begin-user-doc --> <!-- end-user-doc -->
070: *
071: * @generated
072: */
073: public static final String copyright = "uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004, Refractions Research Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details."; //$NON-NLS-1$
074:
075: /**
076: * This constructs an instance from a factory and a notifier. <!-- begin-user-doc --> <!--
077: * end-user-doc -->
078: *
079: * @generated
080: */
081: public LayerItemProvider(AdapterFactory adapterFactory) {
082: super (adapterFactory);
083: }
084:
085: /**
086: * This returns the property descriptors for the adapted class. <!-- begin-user-doc --> <!--
087: * end-user-doc -->
088: *
089: * @generated NOT
090: */
091: public List getPropertyDescriptors(Object object) {
092: if (itemPropertyDescriptors == null) {
093: super .getPropertyDescriptors(object);
094:
095: addZorderPropertyDescriptor(object);
096: addNamePropertyDescriptor(object);
097: addVisiblePropertyDescriptor(object);
098: addGlyphPropertyDescriptor(object);
099: addSelectablePropertyDescriptor(object);
100: addFilterPropertyDescriptor(object);
101: addStatusPropertyDescriptor(object);
102: addCRSPropertyDescriptor(object);
103: // FIXME: Add new layer properties such as applicable
104: }
105: return itemPropertyDescriptors;
106: }
107:
108: /**
109: * This adds a property descriptor for the Zorder feature. <!-- begin-user-doc --> <!--
110: * end-user-doc -->
111: *
112: */
113: @SuppressWarnings("unchecked")
114: protected void addZorderPropertyDescriptor(Object object) {
115: itemPropertyDescriptors
116: .add(createItemPropertyDescriptor(
117: ((ComposeableAdapterFactory) adapterFactory)
118: .getRootAdapterFactory(),
119: getResourceLocator(),
120: getString("_UI_Layer_zorder_feature"), //$NON-NLS-1$
121: getString(
122: "_UI_PropertyDescriptor_description", "_UI_Layer_zorder_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
123: ProjectPackage.eINSTANCE.getLayer_Zorder(),
124: true,
125: ItemPropertyDescriptor.INTEGRAL_VALUE_IMAGE,
126: null, null));
127: }
128:
129: /**
130: * This adds a property descriptor for the Name feature. <!-- begin-user-doc --> <!--
131: * end-user-doc -->
132: *
133: * @generated
134: */
135: protected void addNamePropertyDescriptor(Object object) {
136: itemPropertyDescriptors
137: .add(createItemPropertyDescriptor(
138: ((ComposeableAdapterFactory) adapterFactory)
139: .getRootAdapterFactory(),
140: getResourceLocator(),
141: getString("_UI_Layer_name_feature"), //$NON-NLS-1$
142: getString(
143: "_UI_PropertyDescriptor_description", "_UI_Layer_name_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
144: ProjectPackage.eINSTANCE.getLayer_Name(), true,
145: ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
146: null, null));
147: }
148:
149: /**
150: * This adds a property descriptor for the ID feature. <!-- begin-user-doc --> <!-- end-user-doc
151: * -->
152: *
153: * @generated
154: */
155: protected void addIDPropertyDescriptor(Object object) {
156: itemPropertyDescriptors
157: .add(createItemPropertyDescriptor(
158: ((ComposeableAdapterFactory) adapterFactory)
159: .getRootAdapterFactory(),
160: getResourceLocator(),
161: getString("_UI_Layer_iD_feature"), //$NON-NLS-1$
162: getString(
163: "_UI_PropertyDescriptor_description", "_UI_Layer_iD_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
164: ProjectPackage.eINSTANCE.getLayer_ID(), true,
165: ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
166: null, null));
167: }
168:
169: /**
170: * This adds a property descriptor for the Visible feature. <!-- begin-user-doc --> <!--
171: * end-user-doc -->
172: *
173: * @generated
174: */
175: protected void addVisiblePropertyDescriptor(Object object) {
176: itemPropertyDescriptors
177: .add(createItemPropertyDescriptor(
178: ((ComposeableAdapterFactory) adapterFactory)
179: .getRootAdapterFactory(),
180: getResourceLocator(),
181: getString("_UI_Layer_visible_feature"), //$NON-NLS-1$
182: getString(
183: "_UI_PropertyDescriptor_description", "_UI_Layer_visible_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
184: ProjectPackage.eINSTANCE.getLayer_Visible(),
185: true,
186: ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE,
187: null, null));
188: }
189:
190: /**
191: * This adds a property descriptor for the Geo Resource feature. <!-- begin-user-doc --> <!--
192: * end-user-doc -->
193: *
194: * @generated
195: */
196: protected void addGeoResourcePropertyDescriptor(Object object) {
197: itemPropertyDescriptors
198: .add(createItemPropertyDescriptor(
199: ((ComposeableAdapterFactory) adapterFactory)
200: .getRootAdapterFactory(),
201: getResourceLocator(),
202: getString("_UI_Layer_geoResource_feature"), //$NON-NLS-1$
203: getString(
204: "_UI_PropertyDescriptor_description", "_UI_Layer_geoResource_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
205: ProjectPackage.eINSTANCE.getLayer_GeoResource(),
206: true,
207: ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
208: null, null));
209: }
210:
211: /**
212: * This adds a property descriptor for the Glyph feature. <!-- begin-user-doc --> <!--
213: * end-user-doc -->
214: *
215: * @generated
216: */
217: protected void addGlyphPropertyDescriptor(Object object) {
218: itemPropertyDescriptors
219: .add(createItemPropertyDescriptor(
220: ((ComposeableAdapterFactory) adapterFactory)
221: .getRootAdapterFactory(),
222: getResourceLocator(),
223: getString("_UI_Layer_glyph_feature"), //$NON-NLS-1$
224: getString(
225: "_UI_PropertyDescriptor_description", "_UI_Layer_glyph_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
226: ProjectPackage.eINSTANCE.getLayer_Glyph(),
227: true,
228: ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
229: null, null));
230: }
231:
232: /**
233: * This adds a property descriptor for the Selectable feature. <!-- begin-user-doc --> <!--
234: * end-user-doc -->
235: *
236: * @generated NOT
237: */
238: protected void addSelectablePropertyDescriptor(Object object) {
239: itemPropertyDescriptors
240: .add(new ItemPropertyDescriptor(
241: ((ComposeableAdapterFactory) adapterFactory)
242: .getRootAdapterFactory(),
243: getResourceLocator(),
244: getString("_UI_Layer_selectable_feature"), //$NON-NLS-1$
245: getString(
246: "_UI_PropertyDescriptor_description", "_UI_Layer_selectable_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
247: ProjectPackage.eINSTANCE.getLayer_Selectable(),
248: false,
249: ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE));
250: }
251:
252: /**
253: * This adds a property descriptor for the Geo Resources feature. <!-- begin-user-doc --> <!--
254: * end-user-doc -->
255: *
256: * @generated
257: */
258: protected void addGeoResourcesPropertyDescriptor(Object object) {
259: itemPropertyDescriptors
260: .add(createItemPropertyDescriptor(
261: ((ComposeableAdapterFactory) adapterFactory)
262: .getRootAdapterFactory(),
263: getResourceLocator(),
264: getString("_UI_Layer_geoResources_feature"), //$NON-NLS-1$
265: getString(
266: "_UI_PropertyDescriptor_description", "_UI_Layer_geoResources_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
267: ProjectPackage.eINSTANCE
268: .getLayer_GeoResources(), false,
269: ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
270: null, null));
271: }
272:
273: /**
274: * This adds a property descriptor for the Catalog Ref feature. <!-- begin-user-doc --> <!--
275: * end-user-doc -->
276: *
277: * @generated
278: */
279: protected void addCatalogRefPropertyDescriptor(Object object) {
280: itemPropertyDescriptors
281: .add(createItemPropertyDescriptor(
282: ((ComposeableAdapterFactory) adapterFactory)
283: .getRootAdapterFactory(),
284: getResourceLocator(),
285: getString("_UI_Layer_catalogRef_feature"), //$NON-NLS-1$
286: getString(
287: "_UI_PropertyDescriptor_description", "_UI_Layer_catalogRef_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
288: ProjectPackage.eINSTANCE.getLayer_CatalogRef(),
289: true,
290: ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
291: null, null));
292: }
293:
294: /**
295: * This adds a property descriptor for the Filter feature. <!-- begin-user-doc --> <!--
296: * end-user-doc -->
297: *
298: * @generated
299: */
300: protected void addFilterPropertyDescriptor(Object object) {
301: itemPropertyDescriptors
302: .add(createItemPropertyDescriptor(
303: ((ComposeableAdapterFactory) adapterFactory)
304: .getRootAdapterFactory(),
305: getResourceLocator(),
306: getString("_UI_Layer_filter_feature"), //$NON-NLS-1$
307: getString(
308: "_UI_PropertyDescriptor_description", "_UI_Layer_filter_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
309: ProjectPackage.eINSTANCE.getLayer_Filter(),
310: false,
311: ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
312: null, null));
313: }
314:
315: /**
316: * This adds a property descriptor for the Status feature. <!-- begin-user-doc --> <!--
317: * end-user-doc -->
318: *
319: * @generated
320: */
321: protected void addStatusPropertyDescriptor(Object object) {
322: itemPropertyDescriptors
323: .add(createItemPropertyDescriptor(
324: ((ComposeableAdapterFactory) adapterFactory)
325: .getRootAdapterFactory(),
326: getResourceLocator(),
327: getString("_UI_Layer_status_feature"), //$NON-NLS-1$
328: getString(
329: "_UI_PropertyDescriptor_description", "_UI_Layer_status_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
330: ProjectPackage.eINSTANCE.getLayer_Status(),
331: true,
332: ItemPropertyDescriptor.INTEGRAL_VALUE_IMAGE,
333: null, null));
334: }
335:
336: /**
337: * This adds a property descriptor for the CRS feature. <!-- begin-user-doc --> <!--
338: * end-user-doc -->
339: *
340: * @generated
341: */
342: protected void addCRSPropertyDescriptor(Object object) {
343: itemPropertyDescriptors
344: .add(createItemPropertyDescriptor(
345: ((ComposeableAdapterFactory) adapterFactory)
346: .getRootAdapterFactory(),
347: getResourceLocator(),
348: getString("_UI_Layer_cRS_feature"), //$NON-NLS-1$
349: getString(
350: "_UI_PropertyDescriptor_description", "_UI_Layer_cRS_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
351: ProjectPackage.eINSTANCE.getLayer_CRS(), true,
352: ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
353: null, null));
354: }
355:
356: /**
357: * This adds a property descriptor for the Properties feature. <!-- begin-user-doc --> <!--
358: * end-user-doc -->
359: *
360: * @generated
361: */
362: protected void addPropertiesPropertyDescriptor(Object object) {
363: itemPropertyDescriptors
364: .add(createItemPropertyDescriptor(
365: ((ComposeableAdapterFactory) adapterFactory)
366: .getRootAdapterFactory(),
367: getResourceLocator(),
368: getString("_UI_Layer_properties_feature"), //$NON-NLS-1$
369: getString(
370: "_UI_PropertyDescriptor_description", "_UI_Layer_properties_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
371: ProjectPackage.eINSTANCE.getLayer_Properties(),
372: false, null, null, null));
373: }
374:
375: /**
376: * This adds a property descriptor for the Colour Scheme feature. <!-- begin-user-doc --> <!--
377: * end-user-doc -->
378: *
379: * @generated
380: */
381: protected void addColourSchemePropertyDescriptor(Object object) {
382: itemPropertyDescriptors
383: .add(createItemPropertyDescriptor(
384: ((ComposeableAdapterFactory) adapterFactory)
385: .getRootAdapterFactory(),
386: getResourceLocator(),
387: getString("_UI_Layer_colourScheme_feature"), //$NON-NLS-1$
388: getString(
389: "_UI_PropertyDescriptor_description", "_UI_Layer_colourScheme_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
390: ProjectPackage.eINSTANCE
391: .getLayer_ColourScheme(), true,
392: ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
393: null, null));
394: }
395:
396: /**
397: * This adds a property descriptor for the Default Color feature. <!-- begin-user-doc --> <!--
398: * end-user-doc -->
399: *
400: * @generated
401: */
402: protected void addDefaultColorPropertyDescriptor(Object object) {
403: itemPropertyDescriptors
404: .add(createItemPropertyDescriptor(
405: ((ComposeableAdapterFactory) adapterFactory)
406: .getRootAdapterFactory(),
407: getResourceLocator(),
408: getString("_UI_Layer_defaultColor_feature"), //$NON-NLS-1$
409: getString(
410: "_UI_PropertyDescriptor_description", "_UI_Layer_defaultColor_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
411: ProjectPackage.eINSTANCE
412: .getLayer_DefaultColor(), true,
413: ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
414: null, null));
415: }
416:
417: /**
418: * This adds a property descriptor for the Feature Changes feature. <!-- begin-user-doc --> <!--
419: * end-user-doc -->
420: *
421: * @generated
422: */
423: protected void addFeatureChangesPropertyDescriptor(Object object) {
424: itemPropertyDescriptors
425: .add(createItemPropertyDescriptor(
426: ((ComposeableAdapterFactory) adapterFactory)
427: .getRootAdapterFactory(),
428: getResourceLocator(),
429: getString("_UI_Layer_featureChanges_feature"), //$NON-NLS-1$
430: getString(
431: "_UI_PropertyDescriptor_description", "_UI_Layer_featureChanges_feature", "_UI_Layer_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
432: ProjectPackage.eINSTANCE
433: .getLayer_FeatureChanges(), true,
434: ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
435: null, null));
436: }
437:
438: /**
439: * This specifies how to implement {@link #getChildren} and is used to deduce an appropriate
440: * feature for an {@link org.eclipse.emf.edit.command.AddCommand},
441: * {@link org.eclipse.emf.edit.command.RemoveCommand} or
442: * {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}. <!--
443: * begin-user-doc --> <!-- end-user-doc -->
444: *
445: * @generated NOT
446: */
447: public Collection getChildrenFeatures(Object object) {
448: if (childrenFeatures == null) {
449: super .getChildrenFeatures(object);
450: }
451: return childrenFeatures;
452: }
453:
454: private Map<Layer, Data> cache = new HashMap<Layer, Data>();
455:
456: private static class Data {
457: ImageDescriptor desc;
458: Image image;
459:
460: public Data(ImageDescriptor desc, Image image2) {
461: super ();
462: this .desc = desc;
463: image = image2;
464: }
465:
466: @Override
467: public int hashCode() {
468: final int PRIME = 31;
469: int result = 1;
470: result = PRIME * result
471: + ((desc == null) ? 0 : desc.hashCode());
472: return result;
473: }
474:
475: @Override
476: public boolean equals(Object obj) {
477: if (this == obj)
478: return true;
479: if (obj == null)
480: return false;
481: if (getClass() != obj.getClass())
482: return false;
483: final Data other = (Data) obj;
484: if (desc == null) {
485: if (other.desc != null)
486: return false;
487: } else if (!desc.equals(other.desc))
488: return false;
489: return true;
490: }
491:
492: }
493:
494: /**
495: * This returns Layer.gif. <!-- begin-user-doc --> Returns layers glyph property, requesting WMS
496: * Legend Graphic will be handled by a decorator. <!-- end-user-doc -->
497: *
498: * @generated NOT
499: */
500: public Object getImage(Object object) {
501: Layer layer = (Layer) object;
502:
503: // Check for generated image - generated by our decorators
504: // (lightweight decorators only seem to work with ImageDecorator)
505: //
506: // Decorator should try out any icon given to it by a third party and make us a image
507: // (We don't want the ImageDescriptor to block on an external WMS)
508: //
509: ImageDescriptor image = layer.getGlyph();
510:
511: if (image == null) {
512: image = (ImageDescriptor) layer.getProperties().get(
513: GENERATED_ICON);
514: }
515:
516: if (image != null) {
517: return image;
518: }
519:
520: // Okay I give up have a default ...
521: return ProjectEditPlugin.INSTANCE.getImage("full/obj16/Layer"); //$NON-NLS-1$
522: }
523:
524: @Override
525: public void dispose() {
526: Collection<Data> values = cache.values();
527: for (Data data : values) {
528: try {
529: if (data.image != null && !data.image.isDisposed())
530: data.image.dispose();
531: } catch (Throwable e) {
532: ProjectEditPlugin.log(
533: "Error disposing LayerItemProvider", e); //$NON-NLS-1$
534: }
535: }
536: cache.clear();
537:
538: super .dispose();
539: }
540:
541: /**
542: * This returns the label text for the adapted class. <!-- begin-user-doc --> Makes use of layer
543: * label, will use name of GeoResource URL by default. A decorator can request the GeoResoruce's
544: * title in thread. <!-- end-user-doc -->
545: *
546: * @generated NOT
547: */
548: public String getText(Object object) {
549: Layer layer = (Layer) object;
550: String label = layer.getName();
551:
552: if (label != null && label.length() != 0)
553: return label;
554:
555: String title = (String) layer.getProperties().get(
556: "generated title"); //$NON-NLS-1$
557: if (title != null)
558: return title;
559:
560: // Okay have a default
561: //
562: // return "Untitled";
563: return "Layer";
564: }
565:
566: /**
567: * This handles model notifications by calling {@link #updateChildren} to update any cached
568: * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
569: * <!-- begin-user-doc --> <!-- end-user-doc -->
570: *
571: * @generated NOT
572: */
573: public void notifyChanged(Notification notification) {
574: updateChildren(notification);
575:
576: switch (notification.getFeatureID(Layer.class)) {
577: case ProjectPackage.LAYER__NAME:
578: case ProjectPackage.LAYER__ID:
579: case ProjectPackage.LAYER__GEO_RESOURCE:
580: case ProjectPackage.LAYER__PROPERTIES:
581: case ProjectPackage.LAYER__STATUS:
582: case ProjectPackage.LAYER__GLYPH:
583: fireNotifyChanged(new ViewerNotification(notification,
584: notification.getNotifier(), false, true));
585: return;
586: case ProjectPackage.LAYER__ZORDER:
587: fireNotifyChanged(new ViewerNotification(notification,
588: ((ILayer) notification.getNotifier()).getMap(),
589: true, false));
590: return;
591: case ProjectPackage.LAYER__STYLE_BLACKBOARD:
592: fireNotifyChanged(new ViewerNotification(notification,
593: notification.getNotifier(), true, false));
594: return;
595: }
596: super .notifyChanged(notification);
597: }
598:
599: /**
600: * Return the resource locator for this item provider's resources. <!-- begin-user-doc --> <!--
601: * end-user-doc -->
602: *
603: * @generated
604: */
605: public ResourceLocator getResourceLocator() {
606: return ProjectEditPlugin.INSTANCE;
607: }
608:
609: /**
610: * @see net.refractions.udig.tool.info.internal.InfoView2
611: */
612: public Color getBackground(Object element) {
613: if (element instanceof LayerImpl) {
614: ScopedPreferenceStore store = ProjectPlugin.getPlugin()
615: .getPreferenceStore();
616: String highlightPref = store
617: .getString(PreferenceConstants.P_HIGHLIGHT);
618: if (highlightPref
619: .equals(PreferenceConstants.P_HIGHLIGHT_NONE)) {
620: return null;
621: }
622: LayerImpl layer = (LayerImpl) element;
623: java.awt.Color awtColor = layer.getDefaultColor();
624: if (awtColor == null)
625: return null;
626: if (highlightPref
627: .equals(PreferenceConstants.P_HIGHLIGHT_FOREGROUND)) {
628: return null; //not used yet (flip between black and white?)
629: } else if (highlightPref
630: .equals(PreferenceConstants.P_HIGHLIGHT_BACKGROUND)) {
631: return new Color(
632: PlatformUI.getWorkbench().getDisplay(),
633: awtColor.getRed(), awtColor.getGreen(),
634: awtColor.getBlue());
635: }
636: }
637: return null;
638: }
639:
640: /**
641: * @see net.refractions.udig.tool.info.internal.InfoView2
642: */
643: public Color getForeground(Object element) {
644: if (element instanceof LayerImpl) {
645:
646: LayerImpl layer = (LayerImpl) element;
647: IMap map = layer.getMap();
648: if (map == null)
649: return null;
650: Object mylar = map.getBlackboard().get("MYLAR"); //$NON-NLS-1$
651: boolean mylarIsOn = mylar != null
652: && ((Boolean) mylar).booleanValue();
653:
654: if (mylarIsOn) {
655: IRenderManager rm = map.getRenderManager();
656: if (rm != null) {
657: List<IRenderer> renderers = rm.getRenderers();
658: for (IRenderer renderer : renderers) {
659: if (renderer.getContext() instanceof CompositeRenderContext) {
660: CompositeRenderContext context = (CompositeRenderContext) renderer
661: .getContext();
662: if (context.getLayers().contains(layer)) {
663: // if the renderer contains this layer and the selected layer then turn off greying of layer
664: mylarIsOn = !context
665: .getLayers()
666: .contains(
667: map
668: .getEditManager()
669: .getSelectedLayer());
670: break;
671: }
672: } else {
673: if (renderer.getContext().getLayer() == layer) {
674: // if this is the selected layer then turn off greying of layer
675: mylarIsOn = map.getEditManager()
676: .getSelectedLayer() != layer;
677: break;
678: }
679: }
680: }
681: }
682: }
683:
684: ScopedPreferenceStore store = ProjectPlugin.getPlugin()
685: .getPreferenceStore();
686: String highlightPref = store
687: .getString(PreferenceConstants.P_HIGHLIGHT);
688:
689: if (highlightPref
690: .equals(PreferenceConstants.P_HIGHLIGHT_NONE)) {
691: if (mylarIsOn)
692: return Display.getCurrent().getSystemColor(
693: SWT.COLOR_GRAY);
694: return null;
695: }
696:
697: float mylarEffect = 1.0f;
698: java.awt.Color awtColor = layer.getDefaultColor();
699: if (awtColor == null)
700: return null;
701: if (highlightPref
702: .equals(PreferenceConstants.P_HIGHLIGHT_FOREGROUND)) {
703: return new Color(
704: PlatformUI.getWorkbench().getDisplay(),
705: (int) mylarEffect * awtColor.getRed(),
706: (int) mylarEffect * awtColor.getGreen(),
707: (int) mylarEffect * awtColor.getBlue());
708: } else if (highlightPref
709: .equals(PreferenceConstants.P_HIGHLIGHT_BACKGROUND)) {
710: if (awtColor.getRed() + awtColor.getGreen()
711: + awtColor.getBlue() > 512) {
712: if (mylarIsOn) {
713: return Display.getCurrent().getSystemColor(
714: SWT.COLOR_GRAY);
715: } else {
716: return Display.getCurrent().getSystemColor(
717: SWT.COLOR_BLACK);
718: }
719: } else {
720: return new Color(PlatformUI.getWorkbench()
721: .getDisplay(), (int) mylarEffect * 255,
722: (int) mylarEffect * 255,
723: (int) mylarEffect * 255);
724: }
725: }
726: }
727: return null;
728: }
729:
730: }
|