KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > jdev > EnhydraAppWizard


1 package org.enhydra.kelp.jdev;
2 import oracle.ide.Ide;
3 import oracle.ide.addin.Addin;
4 import java.lang.String JavaDoc;
5 import oracle.ide.util.MenuSpec;
6 import oracle.ide.addin.Context;
7 import javax.swing.Icon JavaDoc;
8 import java.net.URL JavaDoc;
9 import javax.swing.ImageIcon JavaDoc;
10 import oracle.ide.addin.Wizard;
11 import javax.swing.JMenuItem JavaDoc;
12 import oracle.ide.IdeAction;
13 import oracle.ide.addin.Controller;
14 import oracle.ide.ContextMenu;
15 import oracle.ide.addin.ContextMenuListener;
16 import javax.swing.JOptionPane JavaDoc;
17
18 public class EnhydraAppWizard implements Addin, Wizard, Controller//, ContextMenuListener
19
{
20   private static JMenuItem JavaDoc contextMenuItem = null;
21
22   // %%TODO: Change this ID to something related to your command
23
public static final int ENHYDRA_APP_WIZARD_ID = Ide.newCmd("org.enhydra.kelp.jdev.EnhydraAppWizard.ENHYDRA_APP_WIZARD_ID");
24   private final static String JavaDoc GALLERY_ICON = "/media/gallery_16x16.gif";
25   
26   private JMenuItem JavaDoc menuItem = null;
27   private Icon JavaDoc _icon;
28
29   public EnhydraAppWizard()
30   {
31   }
32
33   public void initialize()
34   {
35     // Do not do major initialization here, it can slow down the startup of JDeveloper
36
// Ide.getNavigatorManager().addContextMenuListener(this, null);
37
}
38
39   public void shutdown()
40   {
41     // Do any necessary cleanup here
42
}
43
44   public float version()
45   {
46     // return the version of your extension
47
return 1.0f;
48   }
49
50   public float ideVersion()
51   {
52     return Ide.IDE_VERSION;
53   }
54
55   public boolean canShutdown()
56   {
57     return true;
58   }
59
60   public String JavaDoc getName()
61   {
62     return "EnhydraAppWizard";
63   }
64
65   public String JavaDoc getMenuLabel()
66   {
67     return null;
68   }
69
70   public MenuSpec getMenuSpecification()
71   {
72     return null;
73   }
74
75   public boolean isAvailable(Context context)
76   {
77     return true;
78   }
79
80   public Icon JavaDoc getIcon()
81   {
82     if (_icon == null)
83     {
84       URL JavaDoc url = getClass().getResource(GALLERY_ICON);
85       if (url != null)
86       {
87         _icon = new ImageIcon JavaDoc(url);
88       }
89     }
90     return _icon;
91   }
92
93   public boolean invoke(Context context, String JavaDoc[] params)
94   {
95     // Invocation: Display message dialog
96
if (Ide.getActiveWorkspace() != null)
97     {
98       System.out.println("Current Workspace : " + Ide.getActiveWorkspace().getShortLabel());
99       new RealWizard(context);
100     }
101     else
102     {
103       JOptionPane.showMessageDialog(null,
104                                     "Please select a Workspace",
105                                     "Ooops",
106                                     JOptionPane.WARNING_MESSAGE);
107     }
108     return true;
109   }
110
111   private Icon JavaDoc loadIcon(String JavaDoc iconName)
112   {
113     URL JavaDoc url = getClass().getResource(iconName);
114     Icon JavaDoc icon = null;
115     if (url != null)
116     {
117       icon = new ImageIcon JavaDoc(url);
118     }
119     return icon;
120   }
121
122   private JMenuItem JavaDoc createMenu_ENHYDRA_APP_WIZARD_ID(String JavaDoc iconName, String JavaDoc menuLabel, int mnemonic)
123   {
124     // String class name which extends oracle.ide.addin.AbstractCommand or null
125
String JavaDoc cmdClass = null;
126     // Category of the keymap to which this entry belongs
127
String JavaDoc category = null;
128     // Icon for the menu item
129
Icon JavaDoc icon = loadIcon(iconName);
130     // Data to be associated with the Action
131
Object JavaDoc data = null;
132     // Should the action be enabled by default
133
boolean enabled = true;
134
135     IdeAction action;
136     // Create the IdeAction
137
action = IdeAction.get(ENHYDRA_APP_WIZARD_ID, cmdClass, menuLabel, category, new Integer JavaDoc(mnemonic), icon, data, enabled);
138     // Set the default controller for this action
139
action.setController(this);
140     // Create MenuItem
141
JMenuItem JavaDoc menuItem = Ide.getMenubar().createMenuItem(action);
142     return menuItem;
143   }
144
145   public Controller supervisor()
146   {
147     return null;
148   }
149
150   public boolean handleEvent(IdeAction action, Context context)
151   {
152     final int cmdId = action.getCommandId();
153     if (cmdId == org.enhydra.kelp.jdev.EnhydraAppWizard.ENHYDRA_APP_WIZARD_ID)
154     {
155       invoke(context, null);
156       return true;
157     }
158     return false;
159   }
160
161   public boolean update(IdeAction action, Context context)
162   {
163     final int cmdId = action.getCommandId();
164     if (cmdId == org.enhydra.kelp.jdev.EnhydraAppWizard.ENHYDRA_APP_WIZARD_ID)
165     {
166       action.setEnabled(is_ENHYDRA_APP_WIZARD_ID_Available(context));
167       return true;
168     }
169     return false;
170   }
171
172   private boolean is_ENHYDRA_APP_WIZARD_ID_Available(Context context)
173   {
174     // %%TODO: Modify this method to the enabled state of the command.
175
return true;
176   }
177
178   public void checkCommands(Context action, Controller controller)
179   {
180     // If your command is on the main menu and has an accelerator you need to call update from here
181
// If your command is on the toolbar then you also must call update from here
182
}
183
184 }
Popular Tags