Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/vinculum/processeditor/ProcesseditorPlugin.java


1   /* * ** **  BEGIN LICENSE BLOCK * ** **
2    * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3    *
4    * The contents of this file are subject to the Mozilla Public License Version 
5    * 1.1 (the "License"); you may not use this file except in compliance with 
6    * the License. You may obtain a copy of the License at 
7    * http://www.mozilla.org/MPL/
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis,
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11   * for the specific language governing rights and limitations under the
12   * License.
13   *
14   * The Original Code is Vinculum Open Source.
15   *
16   * The Initial Developer of the Original Code is
17   * Gerard Toonstra.
18   * Portions created by the Initial Developer are Copyright (C) 2003
19   * the Initial Developer. All Rights Reserved.
20   *
21   * Contributor(s):
22   *
23   * Alternatively, the contents of this file may be used under the terms of
24   * either the GNU General Public License Version 2 or later (the "GPL"), or
25   * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26   * in which case the provisions of the GPL or the LGPL are applicable instead
27   * of those above. If you wish to allow use of your version of this file only
28   * under the terms of either the GPL or the LGPL, and not to allow others to
29   * use your version of this file under the terms of the MPL, indicate your
30   * decision by deleting the provisions above and replace them with the notice
31   * and other provisions required by the GPL or the LGPL. If you do not delete
32   * the provisions above, a recipient may use your version of this file under
33   * the terms of any one of the MPL, the GPL or the LGPL.
34   *
35   * ** ** * END LICENSE BLOCK * ** **
36   */
37  
38  package com.vinculum.processeditor;
39  
40  import org.eclipse.ui.plugin.*;
41  import org.eclipse.core.runtime.*;
42  import org.eclipse.core.resources.*;
43  
44  import java.net.MalformedURLException;
45  import java.net.URL;
46  import java.util.*;
47  
48  import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
49  import org.eclipse.gef.palette.ConnectionCreationToolEntry;
50  import org.eclipse.gef.palette.MarqueeToolEntry;
51  import org.eclipse.gef.palette.PaletteContainer;
52  import org.eclipse.gef.palette.PaletteDrawer;
53  import org.eclipse.gef.palette.PaletteGroup;
54  import org.eclipse.gef.palette.PaletteRoot;
55  import org.eclipse.gef.palette.PaletteSeparator;
56  import org.eclipse.gef.palette.PaletteTemplateEntry;
57  import org.eclipse.gef.palette.SelectionToolEntry;
58  import org.eclipse.gef.palette.ToolEntry;
59  import org.eclipse.gef.requests.SimpleFactory;
60  import org.eclipse.gef.ui.palette.customize.PaletteGroupFactory;
61  import org.eclipse.jface.resource.ImageDescriptor;
62  
63  import com.vinculum.processeditor.model.ProcessDiagramFactory;
64  import com.vinculum.processeditor.model.ProcessFlowEnd;
65  import com.vinculum.processeditor.model.ProcessFlowStart;
66  import com.vinculum.processeditor.model.ProcessJSP;
67  import com.vinculum.processeditor.model.ProcessLabel;
68  import com.vinculum.processeditor.model.ProcessTransition;
69  
70  /**
71   * The main plugin class to be used in the desktop.
72   */
73  public class ProcesseditorPlugin extends AbstractUIPlugin 
74  {
75    private static ProcesseditorPlugin singleton;
76    //Resource bundle.
77    private ResourceBundle resourceBundle;
78    public final static String PLUGIN_ID = "com.vinculum.processeditor";
79    public static URL URL;
80      
81    static
82    {
83      try
84      {
85        URL = new URL("http://com.vinculum.processeditor"); //$NON-NLS-1$
86      }
87      catch (MalformedURLException e)
88      {
89      }
90    }
91      
92    public ProcesseditorPlugin(IPluginDescriptor desc)
93    {
94      super(desc);
95      if( singleton == null )
96      {
97        singleton = this;
98      }
99      try 
100     {
101       resourceBundle= ResourceBundle.getBundle("com.vinculum.processeditor.ProcesseditorPluginResources");
102     } 
103     catch (MissingResourceException x) 
104     {
105       resourceBundle = null;
106     }    
107   }
108 
109   public static ProcesseditorPlugin getDefault()
110   {
111     return singleton;
112   }
113 
114   static private List createCategories(PaletteRoot root)
115   {
116     List categories = new ArrayList();
117   
118     // TODO: Add complex parts category
119     categories.add(createControlGroup(root));
120     categories.add(createComponentsDrawer());
121 //    categories.add(createComplexPartsDrawer());
122 
123     return categories;
124   }
125 
126   static private PaletteContainer createComplexPartsDrawer()
127   {
128     // TODO: reset icon for complex parts drawer
129     PaletteDrawer drawer = new PaletteDrawer(ProcessMessages.ProcessPlugin_Category_ComplexParts_Label,
130       ImageDescriptor.createFromFile(ProcesseditorPlugin.class, "/icons/can.gif")); //$NON-NLS-1$
131 
132     List entries = new ArrayList();
133 
134     // TODO: add entries to drawer
135 /*
136     CombinedTemplateCreationEntry combined = new CombinedTemplateCreationEntry(
137       ProcessMessages.LogicPlugin_Tool_CreationTool_HalfAdder_Label,
138       ProcessMessages.LogicPlugin_Tool_CreationTool_HalfAdder_Description,
139       TemplateConstants.TEMPLATE_HALF_ADDER,
140       ProcessDiagramFactory.getHalfAdderFactory(),
141       ImageDescriptor.createFromFile(Circuit.class, "icons/halfadder16.gif"), //$NON-NLS-1$
142       ImageDescriptor.createFromFile(Circuit.class, "icons/halfadder24.gif") //$NON-NLS-1$
143     );
144     entries.add(combined);
145 
146     combined = new CombinedTemplateCreationEntry(
147       ProcessMessages.LogicPlugin_Tool_CreationTool_FullAdder_Label,
148       ProcessMessages.LogicPlugin_Tool_CreationTool_FullAdder_Description,
149       TemplateConstants.TEMPLATE_FULL_ADDER,
150       ProcessDiagramFactory.getFullAdderFactory(),
151       ImageDescriptor.createFromFile(Circuit.class, "icons/fulladder16.gif"), //$NON-NLS-1$
152       ImageDescriptor.createFromFile(Circuit.class, "icons/fulladder24.gif") //$NON-NLS-1$
153     );
154     entries.add(combined);
155 */
156     drawer.addAll(entries);
157     return drawer;
158   }
159 
160   static private PaletteContainer createComponentsDrawer()
161   {
162     // TODO: Reset icon for components drawer
163     PaletteDrawer drawer = new PaletteDrawer(
164       ProcessMessages.ProcessPlugin_Category_Components_Label,
165       ImageDescriptor.createFromFile(ProcesseditorPlugin.class, "/icons/comp.gif"));//$NON-NLS-1$
166 
167     List entries = new ArrayList();
168 
169     CombinedTemplateCreationEntry combined = new CombinedTemplateCreationEntry(
170       ProcessMessages.ProcessPlugin_Tool_CreationTool_ProcessFlowStart_Label,
171       ProcessMessages.ProcessPlugin_Tool_CreationTool_ProcessFlowStart_Description,
172       TemplateConstants.TEMPLATE_START_FLOW,
173       new SimpleFactory(ProcessFlowStart.class),
174       ImageDescriptor.createFromFile(ProcesseditorPlugin.class, "/icons/start16.gif"), //$NON-NLS-1$
175       ImageDescriptor.createFromFile(ProcesseditorPlugin.class, "/icons/start24.gif")//$NON-NLS-1$
176     );
177     entries.add(combined);
178 
179     combined = new CombinedTemplateCreationEntry(
180       ProcessMessages.ProcessPlugin_Tool_CreationTool_ProcessTransition_Label,
181       ProcessMessages.ProcessPlugin_Tool_CreationTool_ProcessTransition_Description,
182       TemplateConstants.TEMPLATE_TRANSITION,
183       new SimpleFactory(ProcessTransition.class),
184       ImageDescriptor.createFromFile(ProcesseditorPlugin.class, "/icons/transition16.gif"),//$NON-NLS-1$
185       ImageDescriptor.createFromFile(ProcesseditorPlugin.class, "/icons/transition24.gif")//$NON-NLS-1$
186     );
187     entries.add(combined);
188 
189     combined = new CombinedTemplateCreationEntry(
190       ProcessMessages.ProcessPlugin_Tool_CreationTool_ProcessJSP_Label,
191       ProcessMessages.ProcessPlugin_Tool_CreationTool_ProcessJSP_Description,
192       TemplateConstants.TEMPLATE_JSP,
193       new SimpleFactory(ProcessJSP.class),
194       ImageDescriptor.createFromFile(ProcesseditorPlugin.class, "/icons/jsp16.gif"),//$NON-NLS-1$
195       ImageDescriptor.createFromFile(ProcesseditorPlugin.class, "/icons/jsp24.gif")//$NON-NLS-1$
196     );
197     entries.add(combined);
198 
199     // entries.add(new PaletteSeparator());
200 
201     combined = new CombinedTemplateCreationEntry(
202       ProcessMessages.ProcessPlugin_Tool_CreationTool_ProcessFlowEnd_Label,
203       ProcessMessages.ProcessPlugin_Tool_CreationTool_ProcessFlowEnd_Description,
204       TemplateConstants.TEMPLATE_END_FLOW,
205       new SimpleFactory(ProcessFlowEnd.class),
206       ImageDescriptor.createFromFile(ProcesseditorPlugin.class, "/icons/end16.gif"), //$NON-NLS-1$
207       ImageDescriptor.createFromFile(ProcesseditorPlugin.class, "/icons/end24.gif")  //$NON-NLS-1$
208     );
209     entries.add(combined);
210     
211     combined = new CombinedTemplateCreationEntry(
212       ProcessMessages.ProcessPlugin_Tool_CreationTool_Label_Label,
213       ProcessMessages.ProcessPlugin_Tool_CreationTool_Label_Description,
214       TemplateConstants.TEMPLATE_LABEL,
215       new SimpleFactory(ProcessLabel.class),
216       ImageDescriptor.createFromFile(ProcesseditorPlugin.class, "/icons/label16.gif"), //$NON-NLS-1$
217       ImageDescriptor.createFromFile(ProcesseditorPlugin.class, "/icons/label24.gif")  //$NON-NLS-1$
218     );
219     entries.add(combined);    
220 
221     drawer.addAll(entries);
222     return drawer;
223   }
224 
225   static private PaletteContainer createControlGroup(PaletteRoot root)
226   {
227     PaletteGroup controlGroup = new PaletteGroup(
228       ProcessMessages.ProcessPlugin_Category_ControlGroup_Label);
229 
230     List entries = new ArrayList();
231 
232     ToolEntry tool = new SelectionToolEntry();
233     entries.add(tool);
234     root.setDefaultEntry(tool);
235 
236     tool = new MarqueeToolEntry();
237     entries.add(tool);
238   
239     PaletteSeparator sep = new PaletteSeparator(
240         "com.vinculum.processeditor.sep2"); //$NON-NLS-1$
241     sep.setUserModificationPermission(PaletteSeparator.PERMISSION_NO_MODIFICATION);
242     entries.add(sep); //$NON-NLS-1$
243 
244     tool = new ConnectionCreationToolEntry(
245       ProcessMessages.ProcessPlugin_Tool_ConnectionCreationTool_ConnectionCreationTool_Label,
246       ProcessMessages.ProcessPlugin_Tool_ConnectionCreationTool_ConnectionCreationTool_Description,
247       null,
248       ImageDescriptor.createFromFile(ProcesseditorPlugin.class, "/icons/connection16.gif"),//$NON-NLS-1$
249       ImageDescriptor.createFromFile(ProcesseditorPlugin.class, "/icons/connection24.gif")//$NON-NLS-1$
250     );
251     entries.add(tool);
252 
253     controlGroup.addAll(entries);
254     return controlGroup;
255   }
256 
257   public static PaletteRoot createPalette() 
258   {
259     PaletteRoot processPalette = new PaletteRoot();
260     processPalette.addAll(createCategories(processPalette));
261     return processPalette;
262   }
263   
264   public static IWorkspace getWorkspace() 
265   {
266     return ProcesseditorPlugin.getWorkspace();
267   }  
268   
269   /**
270    * Returns the string from the plugin's resource bundle,
271    * or 'key' if not found.
272    */
273   public static String getResourceString(String key) 
274   {
275     ResourceBundle bundle= ProcesseditorPlugin.getDefault().getResourceBundle();
276     try 
277     {
278       return bundle.getString(key);
279     } 
280     catch (MissingResourceException e) 
281     {
282       return key;
283     }
284   }
285 
286   /**
287    * Returns the plugin's resource bundle,
288    */
289   public ResourceBundle getResourceBundle() 
290   {
291     return resourceBundle;
292   }  
293   
294 }