1 package org.enhydra.kelp.forte; 2 3 import java.io.*; 4 5 import org.openide.TopManager; 6 import org.openide.filesystems.FileUtil; 7 import org.openide.loaders.*; 8 import org.openide.modules.ModuleInstall; 9 import org.openide.util.NbBundle; 10 import org.openide.util.Utilities; 11 12 import org.enhydra.kelp.forte.actions.AppWizardAction; 13 import org.enhydra.kelp.forte.actions.XMLCAction; 14 import org.enhydra.kelp.forte.actions.DeploymentAction; 15 import org.enhydra.kelp.forte.actions.DODSAction; 16 17 import java.io.File ; 19 23 public class KelpInstaller extends ModuleInstall { 24 25 27 public void installed () { 28 try { 30 createAction (AppWizardAction.class, DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().menus (), "File"), 31 "New", true, false, false, false, false); 32 InstanceDataObject.create (DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().actions (), "File"), 33 "AppWizardAction", AppWizardAction.class); 34 35 createAction (DODSAction.class, DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().menus (), "Tools"), 37 "", true, false, true, false, false); 38 InstanceDataObject.create (DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().actions (), "Tools"), 39 "DODSAction", DODSAction.class); 40 41 createAction (XMLCAction.class, DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().menus (), "Tools"), 42 "DODSAction", true, false, true, false, false); 43 InstanceDataObject.create (DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().actions (), "Tools"), 44 "XMLCAction", XMLCAction.class); 45 createAction (DeploymentAction.class, DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().menus (), "Tools"), 46 "XMLCAction", true, false, false, false, true); 47 InstanceDataObject.create (DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().actions (), "Tools"), 48 "DeploymentAction", DeploymentAction.class); 49 50 } catch (IOException ioe) { 51 if (Boolean.getBoolean ("netbeans.debug.exceptions")) 52 ioe.printStackTrace (); 53 } 54 restored (); 55 } 56 57 58 public void uninstalled () { 59 try { 61 removeAction (AppWizardAction.class, 62 DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().menus (), "File"), 63 false); 64 InstanceDataObject.remove (DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().actions (), "File"), 65 "AppWizardAction", AppWizardAction.class); 66 67 removeAction (DODSAction.class, 69 DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().menus (), "Tools"), 70 false); 71 InstanceDataObject.remove (DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().actions (), "Tools"), 72 "DODSAction", XMLCAction.class); 73 74 removeAction (XMLCAction.class, 75 DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().menus (), "Tools"), 76 false); 77 InstanceDataObject.remove (DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().actions (), "Tools"), 78 "XMLCAction", XMLCAction.class); 79 removeAction (DeploymentAction.class, 80 DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().menus (), "Tools"), 81 false); 82 InstanceDataObject.remove (DataFolder.create (TopManager.getDefault ().getPlaces ().folders ().actions (), "Tools"), 83 "DeploymentAction", DeploymentAction.class); 84 85 } catch (IOException ioe) { 86 if (Boolean.getBoolean ("netbeans.debug.exceptions")) 87 ioe.printStackTrace (); 88 } 89 } 90 91 public boolean closing() { 93 uninstalled(); 94 95 char sep = File.separatorChar; 96 97 File f = new File (System.getProperty("netbeans.user")+sep+"system"+sep+"Modules"+sep+"org-enhydra-kelp-forte.xml"); 98 f.delete(); 99 100 return true; 101 } 102 103 112 113 126 private void createAction (Class actionClass, DataFolder folder, String relativeTo, boolean after, boolean isToolbar, 127 boolean skipSeparator, boolean separatorBefore, boolean separatorAfter) throws IOException { 128 String actionShortName = Utilities.getShortClassName (actionClass); 129 String actionName = actionClass.getName (); 130 131 if (InstanceDataObject.find (folder, actionShortName, actionName) != null) return; 132 133 DataObject[] children = folder.getChildren (); 134 int indexToUse = -1; 135 for (int i = 0; i < children.length; i++) { 136 if (children[i] instanceof InstanceDataObject && 137 children[i].getPrimaryFile ().getName ().indexOf (relativeTo) != -1) { 138 indexToUse = i; 139 break; 140 } 141 } 142 InstanceDataObject actionInstance = InstanceDataObject.create (folder, actionShortName, actionName); 143 144 if (indexToUse != -1) { 145 if (after) { 146 indexToUse += 1; 147 if (skipSeparator) { 148 if ((indexToUse < children.length) && 149 (children[indexToUse].getPrimaryFile ().getName ().indexOf ("Separator") != -1)) { 150 indexToUse += 1; 151 } 152 } 153 } else { 154 if (skipSeparator) { 155 if ((indexToUse > 0) && 156 (children[indexToUse - 1].getPrimaryFile ().getName ().indexOf ("Separator") != -1)) { 157 indexToUse -= 1; 158 } 159 } 160 } 161 162 InstanceDataObject beforeSeparator = separatorBefore ? 163 InstanceDataObject.create (folder, "Separator1-" + actionShortName, sepClass (isToolbar)) : 164 null; 165 InstanceDataObject afterSeparator = separatorAfter ? 166 InstanceDataObject.create (folder, "Separator2-" + actionShortName, sepClass (isToolbar)) : 167 null; 168 169 int itemsAdded = 0; 170 if (separatorBefore) itemsAdded ++; 171 if (separatorAfter) itemsAdded ++; 172 int currentIndex = indexToUse; 173 174 DataObject[] newOrder = new DataObject [children.length + 1 + itemsAdded]; 175 System.arraycopy (children, 0, newOrder, 0, indexToUse); 176 177 if (separatorBefore) newOrder[currentIndex++] = beforeSeparator; 178 newOrder[currentIndex++] = actionInstance; 179 if (separatorAfter) newOrder[currentIndex++] = afterSeparator; 180 181 System.arraycopy (children, indexToUse, newOrder, indexToUse + 1 + itemsAdded, children.length - indexToUse); 182 folder.setOrder (newOrder); 183 } 184 } 185 186 192 private void removeAction (Class actionClass, DataFolder folder, boolean isToolbar) throws IOException { 193 String actionShortName = Utilities.getShortClassName (actionClass); 194 if (! InstanceDataObject.remove (folder, actionShortName, actionClass.getName ())) 195 throw new IOException ("Note: removal of " + actionShortName + " from " + 196 folder.getPrimaryFile ().getPackageName ('/') + " failed"); 197 InstanceDataObject.remove (folder, "Separator1-" + actionShortName, sepClass (isToolbar)); 198 InstanceDataObject.remove (folder, "Separator2-" + actionShortName, sepClass (isToolbar)); 199 } 200 201 private String sepClass (boolean isToolbar) { 202 return isToolbar ? "javax.swing.JToolBar$Separator" : "javax.swing.JSeparator"; 203 } 204 205 } 206 | Popular Tags |