replaced "artistic" code to add the format action into the SystemAction array for appropriate nodes jalopy_1_0
authormoser@netbeans.org
Thu, 30 Jun 2005 12:58:04 +0000
changeset 62173ea5856513ff
parent 6216 f618b1419443
child 6218 b8342e22c660
replaced "artistic" code to add the format action into the SystemAction array for appropriate nodes
when the constructor of FormatAction is called by proper entries in layer.xml. This fixes an exception
which was reported on nbusers@netbeans.org:
http://www.netbeans.org/servlets/ReadMsg?list=nbusers&msgId=980048
de.hunsicker.jalopy.plugin.netbeans/src/de/hunsicker/jalopy/plugin/netbeans/FormatAction.java
de.hunsicker.jalopy.plugin.netbeans/src/de/hunsicker/jalopy/plugin/netbeans/resources/Layer.xml
     1.1 --- a/de.hunsicker.jalopy.plugin.netbeans/src/de/hunsicker/jalopy/plugin/netbeans/FormatAction.java	Thu Jun 30 12:51:14 2005 +0000
     1.2 +++ b/de.hunsicker.jalopy.plugin.netbeans/src/de/hunsicker/jalopy/plugin/netbeans/FormatAction.java	Thu Jun 30 12:58:04 2005 +0000
     1.3 @@ -15,8 +15,6 @@
     1.4  
     1.5  import org.openide.cookies.EditorCookie;
     1.6  import org.openide.loaders.DataFolder;
     1.7 -import org.openide.loaders.DataLoader;
     1.8 -import org.openide.loaders.DataLoaderPool;
     1.9  import org.openide.loaders.DataNode;
    1.10  import org.openide.loaders.DataObject;
    1.11  import org.openide.nodes.Node;
    1.12 @@ -24,13 +22,9 @@
    1.13  import org.openide.util.Lookup;
    1.14  import org.openide.util.NbBundle;
    1.15  import org.openide.util.actions.CookieAction;
    1.16 -import org.openide.util.actions.SystemAction;
    1.17 -
    1.18 -import java.util.Enumeration;
    1.19  
    1.20  import javax.swing.Action;
    1.21  import javax.swing.JEditorPane;
    1.22 -import javax.swing.SwingUtilities;
    1.23  
    1.24  
    1.25  /**
    1.26 @@ -54,9 +48,6 @@
    1.27  	 * Creates a new FormatAction object.
    1.28  	 */
    1.29  	public FormatAction() {
    1.30 -		// we have to register popups here, because otherwise users would have
    1.31 -		// to open the "Build" menu first in order to see the popup menus
    1.32 -		//		registerPopups();
    1.33  	}
    1.34  
    1.35  	/**
    1.36 @@ -98,82 +89,6 @@
    1.37  	}
    1.38  
    1.39  	/**
    1.40 -	 * Indicates whether the action should be enabled based on the currently
    1.41 -	 * activated nodes. The action will only be enabled for Java data objects
    1.42 -	 * (representing Java source files) and data folders.
    1.43 -	 *
    1.44 -	 * @param nodes the set of activated nodes.
    1.45 -	 *
    1.46 -	 * @return <code>true</code> if the action should be enabled.
    1.47 -	 */
    1.48 -	protected boolean enableOld(Node[] nodes) {
    1.49 -		if (!super.enable(nodes)) {
    1.50 -			return false;
    1.51 -		}
    1.52 -
    1.53 -		boolean enabled = false;
    1.54 -		boolean single = true;
    1.55 -
    1.56 -		if (nodes.length == 1) {
    1.57 -
    1.58 -			DataFolder dataFolder =
    1.59 -				(DataFolder) nodes[0].getCookie(DataFolder.class);
    1.60 -			DataObject dataObject =
    1.61 -				(DataObject) nodes[0].getCookie(DataObject.class);
    1.62 -
    1.63 -			single = dataFolder == null;
    1.64 -			enabled =
    1.65 -				!single ||
    1.66 -				(dataObject != null && NbHelper.isJavaFile(dataObject));
    1.67 -		}
    1.68 -		else if (nodes.length > 1) {
    1.69 -
    1.70 -			int javaDataObjectCount = 0;
    1.71 -
    1.72 -			for (int i = 0; i < nodes.length; i++) {
    1.73 -
    1.74 -				DataFolder dataFolder =
    1.75 -					(DataFolder) nodes[i].getCookie(DataFolder.class);
    1.76 -				DataObject dataObject =
    1.77 -					(DataObject) nodes[i].getCookie(DataObject.class);
    1.78 -
    1.79 -				if (dataFolder != null) {
    1.80 -					single = false;
    1.81 -					enabled = true;
    1.82 -				}
    1.83 -
    1.84 -				if (dataObject != null && NbHelper.isJavaFile(dataObject)) {
    1.85 -					enabled = true;
    1.86 -					javaDataObjectCount++;
    1.87 -				}
    1.88 -
    1.89 -				if (javaDataObjectCount > 1) {
    1.90 -					single = false;
    1.91 -				}
    1.92 -
    1.93 -				if (!single && enabled) {
    1.94 -					break;
    1.95 -				}
    1.96 -			}
    1.97 -		}
    1.98 -
    1.99 -		if (single) {
   1.100 -			_name =
   1.101 -				NbBundle.getMessage(
   1.102 -					FormatAction.class, "LBL_FormatSingleAction" /* NOI18N */);
   1.103 -		}
   1.104 -		else {
   1.105 -			_name =
   1.106 -				NbBundle.getMessage(
   1.107 -					FormatAction.class, "LBL_FormatAllAction" /* NOI18N */);
   1.108 -		}
   1.109 -
   1.110 -		System.out.println("name " + _name);
   1.111 -		System.out.println("enabled " + enabled);
   1.112 -		return enabled;
   1.113 -	}
   1.114 -
   1.115 -	/**
   1.116  	 * {@inheritDoc}
   1.117  	 */
   1.118  	protected void initialize() {
   1.119 @@ -251,100 +166,4 @@
   1.120  
   1.121  		return ((panes != null) && (panes.length > 0));
   1.122  	}
   1.123 -
   1.124 -	private void registerPopups() {
   1.125 -		SwingUtilities.invokeLater(
   1.126 -			new Runnable() {
   1.127 -				public void run() {
   1.128 -					registerPopups0();
   1.129 -				}
   1.130 -			});
   1.131 -	}
   1.132 -
   1.133 -	private void registerPopups0() {
   1.134 -
   1.135 -		/*
   1.136 -		 * @todo this code is ugly and subject to change but until the Looks
   1.137 -		 *          API is in place, I really like this better than the
   1.138 -		 *          SystemAction way to integrate items into the Tools submenu
   1.139 -		 */
   1.140 -		DataLoaderPool pool =
   1.141 -			(DataLoaderPool) Lookup.getDefault().lookup(DataLoaderPool.class);
   1.142 -		DataLoader loader = pool.firstProducerOf(DataFolder.class);
   1.143 -		SystemAction[] actions = loader.getActions();
   1.144 -
   1.145 -
   1.146 -
   1.147 -// add our action to the popup menu of folder nodes
   1.148 -SEARCH_FOLDER: 
   1.149 -		for (int i = 0; i < actions.length; i++) {
   1.150 -			if (actions[i] != null) // null means separator
   1.151 -			 {
   1.152 -
   1.153 -				String actionName = actions[i].getClass().getName();
   1.154 -
   1.155 -				// formerly org.openide.actions.BuildAction
   1.156 -				if (actionName.equals(NbHelper.REFACTORING_ACTION_CLASS_NAME)) {
   1.157 -
   1.158 -					SystemAction[] result =
   1.159 -						new SystemAction[actions.length + 2];
   1.160 -
   1.161 -					System.arraycopy(actions, 0, result, 0, i + 1);
   1.162 -					result[i + 2] = this; // add the action
   1.163 -					result[i + 3] = null; // and a separator
   1.164 -					System.arraycopy(
   1.165 -						actions, i + 2, result, i + 4, actions.length - i - 2);
   1.166 -					loader.setActions(result);
   1.167 -
   1.168 -					break SEARCH_FOLDER;
   1.169 -				}
   1.170 -			}
   1.171 -		}
   1.172 -
   1.173 -		// add our action to the popup menu of Java source file nodes
   1.174 -		for (Enumeration loaders = pool.allLoaders();
   1.175 -					loaders.hasMoreElements();) {
   1.176 -			loader = (DataLoader) loaders.nextElement();
   1.177 -
   1.178 -			String name = loader.getClass().getName();
   1.179 -
   1.180 -			/**
   1.181 -			 * @todo it would be cool to be able to format FormDataNodes
   1.182 -			 * 		 (org.netbeans.modules.form.FormDataLoader) as well, but I
   1.183 -			 * 		 don't how to bypass the guarded sections
   1.184 -			 */
   1.185 -			if (
   1.186 -				name.equals(NbHelper.JAVA_DATA_LOADER_CLASS_NAME) ||
   1.187 -						name.equals(NbHelper.SERVLET_DATA_LOADER_CLASS_NAME)) {
   1.188 -				actions = loader.getActions();
   1.189 -SEARCH_FILE: 
   1.190 -				for (int i = 0; i < actions.length; i++) {
   1.191 -					if (actions[i] != null) // null means separator
   1.192 -					 {
   1.193 -
   1.194 -						String actionName = actions[i].getClass().getName();
   1.195 -
   1.196 -						// formerly org.openide.actions.BuildAction
   1.197 -						if (
   1.198 -							actionName.equals(
   1.199 -										NbHelper.REFACTORING_ACTION_CLASS_NAME)) {
   1.200 -
   1.201 -							SystemAction[] result =
   1.202 -								new SystemAction[actions.length + 2];
   1.203 -
   1.204 -							System.arraycopy(actions, 0, result, 0, i + 1);
   1.205 -							result[i + 2] = this; // add the action
   1.206 -							result[i + 3] = null; // and a separator
   1.207 -							System.arraycopy(
   1.208 -								actions, i + 2, result, i + 4,
   1.209 -								actions.length - i - 2);
   1.210 -							loader.setActions(result);
   1.211 -
   1.212 -							break SEARCH_FILE;
   1.213 -						}
   1.214 -					}
   1.215 -				}
   1.216 -			}
   1.217 -		}
   1.218 -	}
   1.219  }
     2.1 --- a/de.hunsicker.jalopy.plugin.netbeans/src/de/hunsicker/jalopy/plugin/netbeans/resources/Layer.xml	Thu Jun 30 12:51:14 2005 +0000
     2.2 +++ b/de.hunsicker.jalopy.plugin.netbeans/src/de/hunsicker/jalopy/plugin/netbeans/resources/Layer.xml	Thu Jun 30 12:58:04 2005 +0000
     2.3 @@ -4,93 +4,104 @@
     2.4  
     2.5  <filesystem>
     2.6  
     2.7 -  <!-- Actions -->
     2.8 -  <folder name="Actions">
     2.9 -    <folder name="Tools">
    2.10 -      <file name="de-hunsicker-jalopy-plugin-netbeans-FormatAction.instance" />
    2.11 -      <file name="de-hunsicker-jalopy-plugin-netbeans-SettingsAction.instance" />
    2.12 -    </folder>
    2.13 -  </folder>
    2.14 +    <!-- ##################################################################### -->
    2.15  
    2.16 -  <!-- Menu -->
    2.17 -  <folder name="Menu">
    2.18 +    <folder name="Actions">
    2.19  
    2.20 -    <folder name="BuildProject">
    2.21 -      <!--attr name="org-netbeans-modules-project-ui-CompileSingle.instance/de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow" boolvalue="true" /-->
    2.22 -      <file name="de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow">
    2.23 -        <attr name="originalFile" stringvalue="Actions/Tools/de-hunsicker-jalopy-plugin-netbeans-FormatAction.instance" />
    2.24 -      </file>
    2.25 -    </folder>
    2.26 +	<folder name="Tools">
    2.27 +	    <file name="de-hunsicker-jalopy-plugin-netbeans-FormatAction.instance" />
    2.28 +	    <file name="de-hunsicker-jalopy-plugin-netbeans-SettingsAction.instance" />
    2.29 +	</folder>    <!--folder name="Tools"-->
    2.30  
    2.31 -    <folder name="Tools">
    2.32 -      <!--attr name="org-netbeans-core-actions-OptionsAction.instance/de-hunsicker-jalopy-plugin-netbeans-SettingsAction.shadow" boolvalue="true" /-->
    2.33 -      <file name="de-hunsicker-jalopy-plugin-netbeans-SettingsAction.shadow">
    2.34 -        <attr name="originalFile" stringvalue="Actions/Tools/de-hunsicker-jalopy-plugin-netbeans-SettingsAction.instance" />
    2.35 -      </file>
    2.36 -    </folder>
    2.37 +    </folder>  <!--folder name="Actions"-->
    2.38  
    2.39 -  </folder>
    2.40 +    <!-- ##################################################################### -->
    2.41  
    2.42 -  <!--folder name="System">
    2.43 +    <folder name="Menu">
    2.44 +
    2.45 +	<folder name="BuildProject">
    2.46 +	    <attr name="org-netbeans-modules-project-ui-CompileSingle.instance/de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow" boolvalue="true" />
    2.47 +	    <file name="de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow">
    2.48 +		<attr name="originalFile" stringvalue="Actions/Tools/de-hunsicker-jalopy-plugin-netbeans-FormatAction.instance" />
    2.49 +	    </file>
    2.50 +	</folder>    <!--folder name="BuildProject"-->
    2.51 +
    2.52 +	<folder name="Tools">
    2.53 +	    <attr name="org-netbeans-core-actions-OptionsAction.instance/de-hunsicker-jalopy-plugin-netbeans-SettingsAction.shadow" boolvalue="true" />
    2.54 +	    <file name="de-hunsicker-jalopy-plugin-netbeans-SettingsAction.shadow">
    2.55 +		<attr name="originalFile" stringvalue="Actions/Tools/de-hunsicker-jalopy-plugin-netbeans-SettingsAction.instance" />
    2.56 +	    </file>
    2.57 +	</folder>    <!--folder name="Tools"-->
    2.58 +
    2.59 +    </folder>  <!--folder name="Menu"-->
    2.60 +
    2.61 +    <!-- ##################################################################### -->
    2.62 +
    2.63 +    <!--folder name="System">
    2.64    
    2.65 -<file name="de-hunsicker-jalopy-plugin-netbeans-FormatAction.instance" />
    2.66 -<file name="de-hunsicker-jalopy-plugin-netbeans-SettingsAction.instance" />
    2.67 +    <file name="de-hunsicker-jalopy-plugin-netbeans-FormatAction.instance" />
    2.68 +    <file name="de-hunsicker-jalopy-plugin-netbeans-SettingsAction.instance" />
    2.69    
    2.70 -  </folder-->
    2.71 +    </folder-->
    2.72  
    2.73 -  <!-- Shortcuts -->
    2.74 -  <folder name="Shortcuts">
    2.75 -    <file name="CS-F10.shadow">
    2.76 -      <attr name="originalFile" stringvalue="Actions/Tools/de-hunsicker-jalopy-plugin-netbeans-FormatAction.instance" />
    2.77 -    </file>
    2.78 -  </folder>  <!--folder name="Shortcuts"-->
    2.79 +    <!-- ##################################################################### -->
    2.80  
    2.81 -  <!-- Editors-->
    2.82 -  <folder name="Editors">
    2.83 +    <folder name="Shortcuts">
    2.84  
    2.85 -    <folder name="AnnotationTypes">
    2.86 -      <file name="de-hunsicker-jalopy-plugin-netbeans-error.xml" url="error-annotation.xml" />
    2.87 -      <file name="de-hunsicker-jalopy-plugin-netbeans-warn.xml" url="warn-annotation.xml" />
    2.88 -    </folder>    <!--folder name="AnnotationTypes"-->
    2.89 +	<file name="CS-F10.shadow">
    2.90 +	    <attr name="originalFile" stringvalue="Actions/Tools/de-hunsicker-jalopy-plugin-netbeans-FormatAction.instance" />
    2.91 +	</file>
    2.92  
    2.93 -    <folder name="text">
    2.94 -      <folder name="x-java">
    2.95 -        <folder name="Popup">
    2.96 -          <!--attr name="org-openide-actions-PasteAction.instance/de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow" boolvalue="true" /-->
    2.97 -          <file name="de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow">
    2.98 -            <attr name="originalFile" stringvalue="Actions/Tools/de-hunsicker-jalopy-plugin-netbeans-FormatAction.instance" />
    2.99 -          </file>
   2.100 -        </folder>
   2.101 -      </folder>
   2.102 -    </folder>    <!--folder name="text"-->
   2.103 +    </folder>  <!--folder name="Shortcuts"-->
   2.104  
   2.105 -  </folder>  <!--folder name="Editors"-->
   2.106 +    <!-- ##################################################################### -->
   2.107  
   2.108 -  <!-- Loaders -->
   2.109 -  <folder name="Loaders">
   2.110 +    <folder name="Editors">
   2.111  
   2.112 -    <folder name="text">
   2.113 -      <folder name="x-java">
   2.114 -        <folder name="Actions">
   2.115 -          <!--attr name="org-openide-actions-PasteAction.instance/de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow" boolvalue="true" /-->
   2.116 -          <file name="de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow">
   2.117 -            <attr name="originalFile" stringvalue="Actions/Tools/de-hunsicker-jalopy-plugin-netbeans-FormatAction.instance" />
   2.118 -          </file>
   2.119 -        </folder>
   2.120 -      </folder>
   2.121 -    </folder>    <!--folder name="text"-->
   2.122 +	<folder name="AnnotationTypes">
   2.123 +	    <file name="de-hunsicker-jalopy-plugin-netbeans-error.xml" url="error-annotation.xml" />
   2.124 +	    <file name="de-hunsicker-jalopy-plugin-netbeans-warn.xml" url="warn-annotation.xml" />
   2.125 +	</folder>    <!--folder name="AnnotationTypes"-->
   2.126  
   2.127 -    <folder name="folder">
   2.128 -      <folder name="any">
   2.129 -        <folder name="Actions">
   2.130 -          <!--attr name="org-openide-actions-PasteAction.instance/de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow" boolvalue="true" /-->
   2.131 -          <file name="de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow">
   2.132 -            <attr name="originalFile" stringvalue="Actions/Tools/de-hunsicker-jalopy-plugin-netbeans-FormatAction.instance" />
   2.133 -          </file>
   2.134 -        </folder>
   2.135 -      </folder>
   2.136 -    </folder>    <!--folder name="folder"-->
   2.137 +	<folder name="text">
   2.138 +	    <folder name="x-java">
   2.139 +		<folder name="Popup">
   2.140 +		    <attr name="org-openide-actions-PasteAction.instance/de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow" boolvalue="true" />
   2.141 +		    <file name="de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow">
   2.142 +			<attr name="originalFile" stringvalue="Actions/Tools/de-hunsicker-jalopy-plugin-netbeans-FormatAction.instance" />
   2.143 +		    </file>
   2.144 +		</folder>
   2.145 +	    </folder>
   2.146 +	</folder>    <!--folder name="text"-->
   2.147  
   2.148 -  </folder>  <!--folder name="Loaders"-->
   2.149 +    </folder>  <!--folder name="Editors"-->
   2.150 +
   2.151 +    <!-- ##################################################################### -->
   2.152 +
   2.153 +    <folder name="Loaders">
   2.154 +
   2.155 +	<folder name="text">
   2.156 +	    <folder name="x-java">
   2.157 +		<folder name="Actions">
   2.158 +		    <attr name="org-openide-actions-PasteAction.instance/de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow" boolvalue="true" />
   2.159 +		    <file name="de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow">
   2.160 +			<attr name="originalFile" stringvalue="Actions/Tools/de-hunsicker-jalopy-plugin-netbeans-FormatAction.instance" />
   2.161 +		    </file>
   2.162 +		</folder>
   2.163 +	    </folder>
   2.164 +	</folder>    <!--folder name="text"-->
   2.165 +
   2.166 +	<folder name="folder">
   2.167 +	    <folder name="any">
   2.168 +		<folder name="Actions">
   2.169 +		    <attr name="org-openide-actions-PasteAction.instance/de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow" boolvalue="true" />
   2.170 +		    <file name="de-hunsicker-jalopy-plugin-netbeans-FormatAction.shadow">
   2.171 +			<attr name="originalFile" stringvalue="Actions/Tools/de-hunsicker-jalopy-plugin-netbeans-FormatAction.instance" />
   2.172 +		    </file>
   2.173 +		</folder>
   2.174 +	    </folder>
   2.175 +	</folder>    <!--folder name="folder"-->
   2.176 +
   2.177 +    </folder>  <!--folder name="Loaders"-->
   2.178  
   2.179  </filesystem>