001: package newprocess.diagram.part;
002:
003: import java.util.ArrayList;
004: import java.util.List;
005:
006: import newprocess.provider.NewprocessItemProviderAdapterFactory;
007:
008: import org.eclipse.core.runtime.IPath;
009: import org.eclipse.core.runtime.IStatus;
010: import org.eclipse.core.runtime.Path;
011: import org.eclipse.core.runtime.Platform;
012: import org.eclipse.core.runtime.Status;
013: import org.eclipse.emf.common.notify.AdapterFactory;
014: import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
015: import org.eclipse.emf.edit.provider.IItemLabelProvider;
016: import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
017: import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
018: import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
019: import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
020: import org.eclipse.jface.resource.ImageDescriptor;
021: import org.eclipse.swt.graphics.Image;
022: import org.eclipse.ui.plugin.AbstractUIPlugin;
023: import org.osgi.framework.BundleContext;
024:
025: /**
026: * @generated
027: */
028: public class New_processDiagramEditorPlugin extends AbstractUIPlugin {
029:
030: /**
031: * @generated
032: */
033: public static final String ID = "org.concept.diagram"; //$NON-NLS-1$
034:
035: /**
036: * @generated
037: */
038: public static final PreferencesHint DIAGRAM_PREFERENCES_HINT = new PreferencesHint(
039: ID);
040:
041: /**
042: * @generated
043: */
044: private static New_processDiagramEditorPlugin instance;
045:
046: /**
047: * @generated
048: */
049: private ComposedAdapterFactory adapterFactory;
050:
051: /**
052: * @generated
053: */
054: public New_processDiagramEditorPlugin() {
055: }
056:
057: /**
058: * @generated
059: */
060: public void start(BundleContext context) throws Exception {
061: super .start(context);
062: instance = this ;
063: PreferencesHint.registerPreferenceStore(
064: DIAGRAM_PREFERENCES_HINT, getPreferenceStore());
065: adapterFactory = createAdapterFactory();
066: }
067:
068: /**
069: * @generated
070: */
071: public void stop(BundleContext context) throws Exception {
072: adapterFactory.dispose();
073: adapterFactory = null;
074: instance = null;
075: super .stop(context);
076: }
077:
078: /**
079: * @generated
080: */
081: public static New_processDiagramEditorPlugin getInstance() {
082: return instance;
083: }
084:
085: /**
086: * @generated
087: */
088: protected ComposedAdapterFactory createAdapterFactory() {
089: List factories = new ArrayList();
090: fillItemProviderFactories(factories);
091: return new ComposedAdapterFactory(factories);
092: }
093:
094: /**
095: * @generated
096: */
097: protected void fillItemProviderFactories(List factories) {
098: factories.add(new NewprocessItemProviderAdapterFactory());
099: factories.add(new ResourceItemProviderAdapterFactory());
100: factories.add(new ReflectiveItemProviderAdapterFactory());
101: }
102:
103: /**
104: * @generated
105: */
106: public AdapterFactory getItemProvidersAdapterFactory() {
107: return adapterFactory;
108: }
109:
110: /**
111: * @generated
112: */
113: public ImageDescriptor getItemImageDescriptor(Object item) {
114: IItemLabelProvider labelProvider = (IItemLabelProvider) adapterFactory
115: .adapt(item, IItemLabelProvider.class);
116: if (labelProvider != null) {
117: return ExtendedImageRegistry.getInstance()
118: .getImageDescriptor(labelProvider.getImage(item));
119: }
120: return null;
121: }
122:
123: /**
124: * Returns an image descriptor for the image file at the given
125: * plug-in relative path.
126: *
127: * @generated
128: * @param path the path
129: * @return the image descriptor
130: */
131: public static ImageDescriptor getBundledImageDescriptor(String path) {
132: return AbstractUIPlugin.imageDescriptorFromPlugin(ID, path);
133: }
134:
135: /**
136: * Respects images residing in any plug-in. If path is relative,
137: * then this bundle is looked up for the image, otherwise, for absolute
138: * path, first segment is taken as id of plug-in with image
139: *
140: * @generated
141: * @param path the path to image, either absolute (with plug-in id as first segment), or relative for bundled images
142: * @return the image descriptor
143: */
144: public static ImageDescriptor findImageDescriptor(String path) {
145: final IPath p = new Path(path);
146: if (p.isAbsolute() && p.segmentCount() > 1) {
147: return AbstractUIPlugin.imageDescriptorFromPlugin(p
148: .segment(0), p.removeFirstSegments(1)
149: .makeAbsolute().toString());
150: } else {
151: return getBundledImageDescriptor(p.makeAbsolute()
152: .toString());
153: }
154: }
155:
156: /**
157: * Returns string from plug-in's resource bundle
158: * @generated
159: */
160: public static String getString(String key) {
161: return Platform.getResourceString(getInstance().getBundle(),
162: "%" + key); //$NON-NLS-1$
163: }
164:
165: /**
166: * Returns an image for the image file at the given plug-in relative path.
167: * Client do not need to dispose this image. Images will be disposed automatically.
168: *
169: * @generated
170: * @param path the path
171: * @return image instance
172: */
173: public Image getBundledImage(String path) {
174: Image image = getImageRegistry().get(path);
175: if (image == null) {
176: getImageRegistry().put(path,
177: getBundledImageDescriptor(path));
178: image = getImageRegistry().get(path);
179: }
180: return image;
181: }
182:
183: /**
184: * @generated
185: */
186: public void logError(String error) {
187: logError(error, null);
188: }
189:
190: /**
191: * @param throwable actual error or null could be passed
192: * @generated
193: */
194: public void logError(String error, Throwable throwable) {
195: if (error == null && throwable != null) {
196: error = throwable.getMessage();
197: }
198: getLog().log(
199: new Status(IStatus.ERROR,
200: New_processDiagramEditorPlugin.ID, IStatus.OK,
201: error, throwable));
202: debug(error, throwable);
203: }
204:
205: /**
206: * @generated
207: */
208: public void logInfo(String message) {
209: logInfo(message, null);
210: }
211:
212: /**
213: * @param throwable actual error or null could be passed
214: * @generated
215: */
216: public void logInfo(String message, Throwable throwable) {
217: if (message == null && throwable != null) {
218: message = throwable.getMessage();
219: }
220: getLog().log(
221: new Status(IStatus.INFO,
222: New_processDiagramEditorPlugin.ID, IStatus.OK,
223: message, throwable));
224: debug(message, throwable);
225: }
226:
227: /**
228: * @generated
229: */
230: private void debug(String message, Throwable throwable) {
231: if (!isDebugging()) {
232: return;
233: }
234: if (message != null) {
235: System.err.println(message);
236: }
237: if (throwable != null) {
238: throwable.printStackTrace();
239: }
240: }
241: }
|