MultiView Element help

merlin dragonfire <[email protected]> Wed, 12 Jul 2017 21:18:46 -0700
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <CAAxe7Endi1Bn8V7thOvT0Ka5z_t0PqfLKeEzhrSsrNgTw-SGdA@mail.gmail.com>
I am trying to create my own custom "form" for Java Netbeans. Sort-of like
the swing GUI project templates that you can find in the Netbeans new file
window. I, so far, have been able to create and register a Java template to
the Netbeans new file prompt. Now I have ran into a problem. I cannot
figure out how to add a multi-view window to the template. I have been
trying to use the new file type to create it but it does not show up.

Sorry if this is confusing.
Here is an Example Representation of What I Have So-Far:

   1. MyExampleTemplate.java.template
   2. package-info.java
   3. MyExampleVisualElement.java

------------------------------

// Most of this is automatically generated by the Netbeans New File
Template. // I have Included These Files in the case they do not
generate the [email protected](...)@Messages(...)public
final class MyExampleVisualElement extends JPanel implements
MultiViewElement {
    private MyExampleDataObject obj;
    private JToolBar toolbar = new JToolBar();
    private transient MultiViewElementCallback callback;
    public MyExampleVisualElement(Lookup lkp) {//Is this good or do I
need to do somthing here to connect it?
        obj = lkp.lookup(MyExampleDataObject.class);
        assert obj != null;
        initComponents();
    }
    @Override public String getName() {return "MyExampleVisualElement";}
  //Warning as well as initComponents() Generated by Form.
    @Override public JComponent getVisualRepresentation() {return this;}
    @Override public JComponent getToolbarRepresentation() {return toolbar;}
    @Override public Action[] getActions() {return new Action[0];}
    @Override public Lookup getLookup() {return obj.getLookup();}
    //Overriden blank void methods excluded from example:
componentOpened, componentClosed, componentShowing, componentHidden,
componentActivated, componentDeactivated
    @Override public UndoRedo getUndoRedo() {return UndoRedo.NONE;}
    @Override public void
setMultiViewCallback(MultiViewElementCallback callback) {this.callback
= callback;}
    @Override public CloseOperationState canCloseElement() {return
CloseOperationState.STATE_OK;}}


   1. MyExampleDataObject.java

------------------------------

@Messages({ ... })@MIMEResolver.ExtensionRegistration( ...
)@DataObject.Registration( ... )@ActionReferences({ ... })public class
MyExampleDataObject extends MultiDataObject{
    public MyExampleDataObject(FileObject pf, MultiFileLoader loader)
throws DataObjectExistsException, IOException {
        super(pf, loader);
        registerEditor("application/my-meta-data+xml", true);
    }
    @Override protected int associateLookup() {return 1;}
    @MultiViewElement.Registration(...)
    @Messages(...)
    public static MultiViewEditorElement createEditor(Lookup lkp)
{return new MultiViewEditorElement(lkp);}}

After running I can create my object in Java however their is no
*'Visual'* button
on the bar. Only the *'Source'* and *'History'* Buttons show up.

Anyway I simply want to now the correct format required by Netbeans and its
OpenIDE as to how to utilize multi-windows. An example or a link to an
example would be fine.

I have tried looking at the Netbeans Documentation however I find it to be
confusing and unhelpful. I believe that the problem may be occurring do to
the fact that I am trying to add a template to an existing Netbeans
extension type(ex:.java, .xml, .exe). I have tried to look online howerever
I can only fine examples and tutorials for creating such items for new
unregistered extentions(ex: .mytag, .pasta, .fish, .abc).

Some sites I have looked at but did not help are, svn Multiview API Old
Tutorial
<https://svn.netbeans.org/svn/platform~platform-content/trunk/tutorials/67/nbm-multiview-api-old.html>,
and the Javadoc
<http://bits.netbeans.org/8.0/javadoc/org-netbeans-core-multiview/overview-summary.html>
.

To Duplicate:

   1. Create a Netbeans Module Project
      1. In the Netbeans IDE 8.2 go-to the New Project button → Select
*Netbeans
      Modules* → *Module* and then Click Next
      2. Should be a radio button Defaulted on 🔘*Standalone Module* → Next
      to the *Netbeans Platform* Label → *Development IDE* then enter in a
      name like 'NewFileExample' and Click Next
      3. Create a Code Name Base and Click Finish
   2. Insert a 16x16 picture ether in .gif or .png format into the file or
   somewhere accessible.
   3.

   Create a *'New File Type'*
   1. Make sure to be selected in your project's package where the Bundle
      object is located → Go to New File → Select *Module Development* →
      then *File Type* then Click Next
      2. type in a custom MIME Type such as *'text/x-mymime'*
      3. select the 🔘*by Filename Extension* radio button then → go to the
      text box next to the *Extension(s):* box.
      4. From here there are three different things i have overall tried.
      Choose one of the file extensions:
         - .java
         - .mycustomextention
         - .form
      5. Click Next
      6. Enter in a Class Prefix like *'ExampleFile'* then below select the
      image file that we got ready in Step 2. (Make sure that the ☑*Use
      Multiveiw* Checkbox is checked)
      7.

      check the generated files list below to match this:

      Created Files:
      - src/..*[file path]*../ [*MyClassPrefix*] DataObject.java
         - src/..*[file path]*../ [*MyClassPrefix*] Template.[*myextention*]
         - src/..*[file path]*../ [*MyClassPrefix*] VisualElement.form
         - src/..*[file path]*../ [*MyClassPrefix*] VisualElement.java
         - src/..*[file path]*../package-info.java *(unless already
         created)*
         - *[file path to image]*/ [*IconName*] .png

      Modified Files:
      - nbproject/project.xml
         - src/..*[file path]*../package-info.java *(unless not created
         yet)*
      8.

      Click Finish
      4.

   If you used the file Extention .java rename your template file extention
   to: .java.template and go into the package-info.java to change content =
   "MyClassPrefixTemplate.java" to content = "MyClassPrefixTemplate.java.
   template"
   5. Click run to run the code.

The Outcomes I got were:
- For .java a generated java file in the Others template with only
*'Source'* and *'History'*.
- For a custom extension like .mycustomextension a generated
mycustomextension file in the Others template with only *'Source'* and
*'History'*.
- For .form a generated .from file in the Others template with only
*'Source'* and *'History'* however if a generated form and javafile is
created the their will be other Bars that show up.

Sorry about if this is confusing.
thanks,
Merlin D.


__________________________________________________________________________________



also here is an added item to help clarify as an example :

I am trying to do something *like* this:

​[Note: this is just an example as well as the file still being .java with
some other extension (ex: .world ) that would function similarly to a .form]
goal.png (image/png, 75 KB) - not displayed