Creating A New Split For An Existing Mode

Section 3.4.3 of the "New Window System API Changes" (dated "January 8, 2004"), is pretty interesting. It describes how you can split a mode (i.e., a position in an application based on the NetBeans Platform, such as the IDE itself). To show what I mean, here you see, in addition to a TopComponent in my new banner mode, that the editor area has been split in two:

By default, the editor area is not split. For this to happen, two things must happen. Firstly, the editor must be told that it will share the 'editor' area with another mode. Secondly, the second mode must be created and assigned to the 'editor' area.

The key to both these tasks is described in section 3.4.4 above. Concretely, my new mode is defined in a file called upperEditor.wsmode, with this content:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mode PUBLIC
          "-//NetBeans//DTD Mode Properties 2.0//EN"
          "http://www.netbeans.org/dtds/mode-properties2_0.dtd">

<mode version="2.0">
    <name unique="upperEditor" />
    <kind type="editor" />
    <state type="joined" />
    <constraints>
        <path orientation="vertical" number="0" weight="0.5" />
    </constraints>
    <empty-behavior permanent="true" />
</mode>

The important part is highlighted above. That's the split. So the split is vertical (i.e., my mode will be above or below another mode). The number attribute tells me that this is the first mode (i.e., the upper mode) in the split. The weight attribute tells me that the split will be 50/50, so each mode will take up an equal amount of space within the area. And how do I know which area we're dealing with? Look at the kind element, that's where the type is set. There are only two types: "editor" and "view". And there normally is only one mode in the editor area, which is why the editor's wsmode file is defined like this by default:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mode PUBLIC
          "-//NetBeans//DTD Mode Properties 2.0//EN"
          "http://www.netbeans.org/dtds/mode-properties2_0.dtd">

<mode version="2.0">
    <name unique="editor" />
    <kind type="editor" />
    <state type="joined" />
    <constraints>
    </constraints>
    <empty-behavior permanent="true" />
</mode>

As you can see in the highlighted part above, the editor has no constraints by default. It isn't sharing the "editor" area with any other mode. So we need to change that. In the Important Files node in the module that defines my new upperEditor mode, I expanded "XML Layer" node, and then, within "this layer in context", I expanded "Windows2/modes". There I added a new constraint to editor.wsmode, to tell the editor mode that it would be in a vertical split, that it would be second (i.e., the number attribute is 1), as well as the fact that it would take up half of the split:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mode PUBLIC
          "-//NetBeans//DTD Mode Properties 2.0//EN"
          "http://www.netbeans.org/dtds/mode-properties2_0.dtd">

<mode version="2.0">
    <name unique="editor" />
    <kind type="editor" />
    <state type="joined" />
    <constraints>
        <path orientation="vertical" number="1" weight="0.5" />
    </constraints>
    <empty-behavior permanent="true" />
</mode>

After making this change, the node for the editor.wsmode became highlighted and I found a copy of this file in my main package. That means that I had overridden the default definition of this file. I also found that my XML Layer had been changed, referencing the changed version of the editor.wsmode file. After I added entries for my new upperEditor.wsmode file, I ended up with this section in my XML Layer:

<folder name="Windows2">
    <folder name="Components">
        <file name="TestTopComponent.settings" url="TestTopComponentSettings.xml"/>
    </folder>
    <folder name="Modes">
        <file name="upperEditor.wsmode" url="modes/upperEditor.wsmode"/>
        <folder name="upperEditor">
            <file name="TestTopComponent.wstcref" url="TestTopComponentWstcref.xml"/>
        </folder>
        <file name="editor.wsmode" url="editorWsmode.xml"/>
    </folder>
</folder>

As a result of all this, I ended up with the split editor area that you can see in the screenshot at the start of this blog entry. Note that this is a pretty simple split, things can become a lot more complicated. I highly recommend Section 3.4.3 of the document mentioned earlier, because it gives a very clear outline of how to split modes. One tip when you're experimenting with modes and splits—you should close down the IDE often (if the modes and splits relate to the IDE, rather than some other application on the NetBeans Platform), when things get confusing, and delete the application's (or IDE's, if you're dealing with the IDE's window layout) user directory's config/Windows2Local folder. Then restart the IDE and you will have everything back at the default values + the values you specified in the XML Layer. That way things are refreshed and you know where you are and can continue building your window layout from there.

In other news. Hurray, I have a module on http://www.nbextras.org. That's kind of a coming of age of my own module development work! It's the HTML Palette Extension module that I blogged about a week or so ago. Go to the entry on nbextras here for some further details.

Comments:

Hi Geertjan, I have been checking your blog regularly while investigating whether to use Eclipse RCP or Netbeans as the platform for a large application for my company. Right now I am trying to investigate a custom layout requirement to programmatically layout numerous components in the editor area in multiple modes (as though the user opened several editors and dragged each of them to their own mode). These layouts are saved and different ones are activated when the user clicks on a link (similar to changing perspectives in Eclipse). The key to this seems to be related to these mode files. Do you know of a way to get the same result of editing these mode/constraint files programmatically at runtime? Failing that, any ideas on saving the entire workspace state and restoring it while the application is running (save and restore to different complete workspace layouts).

Posted by jimbo on November 29, 2006 at 01:30 AM PST #

Hi jimbo, thanks for the comment. Please drop me an e-mail and we'll chat further (geertjan.wielenga@sun.com).

Posted by Geertjan on November 29, 2006 at 01:49 AM PST #

Hi,

When I tried this I got a strange resize behavior. I put two TopComponents arranged vertically and when I reduce the vertical size of the window. both TC are resized. But when I expand the window vertically they don't resize and I end up with a lot of empty space in the bottom.

I posted a question on netbeans forums about it (see [1], screenshot included). Maybe you can help me to find out why I get this behavior. Any ideas? Thanks in advance

[1] http://forums.netbeans.org/viewtopic.php?t=29039

Posted by Rubén Laguna on July 01, 2010 at 03:20 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today