DevFaqActionAddFileMime

(Difference between revisions)
(How do I add an action to a file of a given mime-type?)
 
Line 6: Line 6:
# On the second tab, check '''File Type Context Menu Item''' and choose the MIME type and position.
# On the second tab, check '''File Type Context Menu Item''' and choose the MIME type and position.
-
You can also declare your action in your layer manually:
+
You can use <tt>text/html</tt>, <tt>text/x-java</tt>, <tt>text/x-ant+xml</tt>, <tt>text/x-jsp</tt>, <tt>image/png</tt>, etc.
-
 
+
-
<source lang="xml">
+
-
<folder name="Loaders">
+
-
  <folder name="text">
+
-
    <folder name="html">
+
-
      <folder name="Actions">
+
-
        <file name="org-mymodule-MyAction.instance"/>
+
-
      </folder>
+
-
    </folder>
+
-
  </folder>
+
-
</folder>
+
-
</source>
+
-
 
+
-
You can replace <tt>text/html</tt> with <tt>text/x-java</tt>, <tt>text/x-ant+xml</tt>, <tt>text/x-jsp</tt>, <tt>image/png</tt>, etc.
+
-
 
+
-
However, this still may not work depending on how the data loader for
+
-
the type works. The <tt>DataLoader</tt> implementation has to override <tt>actionsContext()</tt> and
+
-
return this path if it wants to load the <tt>Action</tt> instances from there.
+
-
If the data loader you are interested in does ''not'' yet do this, please first file a bug report
+
-
to make sure this is fixed in a future release; as an inferior workaround, you can use e.g.
+
-
 
+
-
<source lang="java">
+
-
DataLoader loader = DataLoaderPool.getDefault().firstProducerOf(SomeDataObject.class);
+
-
if (loader != null) {
+
-
    SystemAction[] actions = loader.getActions();
+
-
    SystemAction[[ | ]] newactions = new SystemAction[Actions.length+2];
+
-
    System.arraycopy(actions, 0, newactions, 0, actions.length);
+
-
    // More realistically: take care that it is not a duplicate,
+
-
    // place into a specific position, etc.:
+
-
    newactions[Actions.length] = null;
+
-
    newactions[Actions.length+1] = SystemAction.get(SomeAction.class);
+
-
    loader.setActions(newactions);
+
-
}
+
-
</source>
+
-
 
+
-
You need to know the implementation class of the foreign data object to implement this workaround. You should avoid doing this unless it is really critical to usability, and replace it with layer-based declarative actions as soon as that is available (you did file that bug report, right?).
+
===See also:===
===See also:===

Current revision as of 00:10, 14 December 2011

How do I add an action to a file of a given mime-type?

The simplest way is to run File > New... > Module Development > Action which creates an action for you and registers it in your layer.xml.

  1. On the first tab, choose Conditionally Enabled action and select DataObject as the cookie class.
  2. On the second tab, check File Type Context Menu Item and choose the MIME type and position.

You can use text/html, text/x-java, text/x-ant+xml, text/x-jsp, image/png, etc.

See also:

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo