Setting up:
- Get and install Mercurial
- Clone http://hg.netbeans.org/main
- Get Ant (1.9.3 worked for me)
- Make sure you have Java 7 (8 doesn't work)
- Open a shell in your working copy directory to do a first build that's needed for creating Ant tasks that are used by the NetBeans projectsset PATH=%PATH%;C:\softs\apache-ant-1.9.3\bin
set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_51
set ANT_OPTS=-Xmx512m -XX:MaxPermSize=512m
ant
With the first build done it is time to have a look at the working copy. Looking at the long list of modules, the first one that seems to talk about project and ui is projectui. A quick drill down shows that it also talks about groups, so lets open it in NetBeans.
org.netbeans.modules.project.ui.groups has a ManageGroupsPanel that correspond to our dialog (panel).
It doesn't include the bottom buttons though. Searching the nearby classes the buttons are defined in GroupsMenu, in manageGroups() on line 196:
dd.setOptions(new Object[] {select, newGroup, cancel});Lets remove newGroup from that line, then run the project then in the new NetBeans instance open the dialog, the button is gone.
Now coming back to the main dialog, the first thing that distracted me was the height of the buttons - 29 -, a quick look at other another dialog with a button shows a height of 23, so adjust the height of the buttons to 23 via the designer.
Run again, it looks nicer.
Next readding the New button. Drop a button above the Properties one... The panel is using a GrigBagLayout (long time no see), so adjust the Grid X/Y properties of the buttons to reallign (2,1 for New, 2,2 for Properties,...)
Next set the text of the New button, to do it click on the "..." by the text property then fill as:
Switch to the code tab of the properties, name the variable newButton.
Switch to Events, add a handler for actionPerformed (newButtonActionPerformed).
Now we need to add the action. The simplest is to move over the code from GroupsMenu.newGroup() along with the HELPCTX constant, adjust the messages prefix to ManageGroupsPanel instead of GroupsMenu, then call from the handler.
Run again, click new, click Create Group the new group is created and selected but not to the list...
To do that, first make the newGroup method non static, then in the
RP.post(new Runnable() {block add after
Group.setActiveGroup(g, true);the following
String selectedValue = null;Run again, now the list is updated.
DefaultListModel model = (DefaultListModel)groupList.getModel();
model.removeAllElements();
for (final Group grp : Group.allGroups()) {
model.addElement(grp.getName());
if(grp.equals(Group.getActiveGroup())) {
selectedValue = grp.getName();
}
}
model.addElement(NONE_GROUP);
groupList.setSelectedValue(selectedValue, true);
The old dialog was closing both the New Group and the Manage Groups dialogs.
To give that option lets add a new button "Create and Select".
First add a new message:
"ManageGroupsPanel.new_create_and_select=Create and Select",between create and cancel.
Then after the cancel button creation:
final JButton createAndSwitch = new JButton(ManageGroupsPanel_new_create_and_select());Then change the line that follows to:
dd.setOptions(new Object[] {create, createAndSwitch, cancel});
Then allow the if(result...) condition to also handle createAndSwitch:
if (result.equals(create) || result.equals(createAndSwitch)) {Back up a little and mark result as final
Then after groupList.setSelectedValue(..) add:
if (result.equals(createAndSwitch))Run again, does the trick.
{
final Window w = SwingUtilities.getWindowAncestor(ManageGroupsPanel.this);
if (w != null) {
w.setVisible(false);
w.dispose();
}
}
}
});
One last thing, the selected group also change when we just click on Select, so let not change the active group in that case:
if (result.equals(createAndSwitch))The full method:
{
Group.setActiveGroup(g, true);
}
@Messages({
"ManageGroupsPanel.new_title=Create New Group",
"ManageGroupsPanel.new_create=Create Group",
"ManageGroupsPanel.new_create_and_select=Create and Select",
"ManageGroupsPanel.new_cancel=Cancel"
})
private void newGroup() {
final NewGroupPanel panel = new NewGroupPanel();
DialogDescriptor dd = new DialogDescriptor(panel, ManageGroupsPanel_new_title());
panel.setNotificationLineSupport(dd.createNotificationLineSupport());
dd.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION);
dd.setModal(true);
dd.setHelpCtx(new HelpCtx(HELPCTX));
final JButton create = new JButton(ManageGroupsPanel_new_create());
create.setDefaultCapable(true);
create.setEnabled(panel.isReady());
panel.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (NewGroupPanel.PROP_READY.equals(evt.getPropertyName())) {
create.setEnabled(panel.isReady());
}
}
});
JButton cancel = new JButton(ManageGroupsPanel_new_cancel());
final JButton createAndSwitch = new JButton(ManageGroupsPanel_new_create_and_select());
dd.setOptions(new Object[] {create, createAndSwitch, cancel});
final Object result = DialogDisplayer.getDefault().notify(dd);
if (result.equals(create) || result.equals(createAndSwitch)) {
assert panel.isReady();
final NewGroupPanel.Type type = panel.getSelectedType();
final boolean autoSync = panel.isAutoSyncField();
final boolean useOpen = panel.isUseOpenedField();
final String name = panel.getNameField();
final String masterProject = panel.getMasterProjectField();
final String directory = panel.getDirectoryField();
RP.post(new Runnable() {
@Override
public void run() {
Group g = NewGroupPanel.create(type, name, autoSync, useOpen, masterProject, directory);
if (result.equals(createAndSwitch))
{
Group.setActiveGroup(g, true);
}
String selectedValue = null;
DefaultListModel model = (DefaultListModel)groupList.getModel();
model.removeAllElements();
for (final Group grp : Group.allGroups()) {
model.addElement(grp.getName());
if(grp.equals(Group.getActiveGroup())) {
selectedValue = grp.getName();
}
}
model.addElement(NONE_GROUP);
groupList.setSelectedValue(selectedValue, true);
if (result.equals(createAndSwitch))
{
final Window w = SwingUtilities.getWindowAncestor(ManageGroupsPanel.this);
if (w != null) {
w.setVisible(false);
w.dispose();
}
}
}
});
}
}
Voila.
No comments:
Post a Comment