myTreeExpander = new DefaultTreeExpander(myTree);
myBuilder = new SimpleTreeBuilder(myTree, (DefaultTreeModel)myTree.getModel(), structure, null);
myBuilder.initRoot();
final DumbService dumbService = DumbService.getInstance(facetEditorContext.getProject());
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(final TreeSelectionEvent e) {
final StrutsFileSet fileSet = getCurrentFileSet();
myEditButton.setEnabled(fileSet != null && !dumbService.isDumb());
myRemoveButton.setEnabled(fileSet != null);
}
});
final CommonActionsManager actionManager = CommonActionsManager.getInstance();
myTreePanel.add(
ToolbarDecorator.createDecorator(myTree)
.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
final StrutsFileSet fileSet =
new StrutsFileSet(StrutsFileSet.getUniqueId(myBuffer),
StrutsFileSet.getUniqueName(StrutsBundle.message("facet.fileset.my.fileset"), myBuffer),
originalConfiguration) {
public boolean isNew() {
return true;
}
};
final FileSetEditor editor = new FileSetEditor(myPanel,
fileSet,
facetEditorContext,
myConfigsSearcher);
editor.show();
if (editor.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
final StrutsFileSet editedFileSet = editor.getEditedFileSet();
Disposer.register(strutsFacetConfiguration, editedFileSet);
myBuffer.add(editedFileSet);
myModified = true;
myBuilder.updateFromRoot();
selectFileSet(fileSet);
}
myTree.requestFocus();
}
})
.setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
remove();
myModified = true;
myBuilder.updateFromRoot();
myTree.requestFocus();
}
})
.setEditAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
final StrutsFileSet fileSet = getCurrentFileSet();
if (fileSet != null) {
final FileSetEditor editor = new FileSetEditor(myPanel,
fileSet,
facetEditorContext,
myConfigsSearcher);
editor.show();
if (editor.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
myModified = true;
myBuffer.remove(fileSet);
final StrutsFileSet edited = editor.getEditedFileSet();
Disposer.register(strutsFacetConfiguration, edited);
myBuffer.add(edited);
edited.setAutodetected(false);
myBuilder.updateFromRoot();
selectFileSet(edited);
}
myTree.requestFocus();
}
}
})
.addExtraAction(AnActionButton.fromAction(actionManager.createExpandAllAction(myTreeExpander, myTree)))
.addExtraAction(AnActionButton.fromAction(actionManager.createCollapseAllAction(myTreeExpander, myTree)))
.addExtraAction(new AnActionButton("Open Struts 2 plugin documentation…", AllIcons.Actions.Help) {
@Override
public void actionPerformed(AnActionEvent e) {
BrowserUtil.browse("http://confluence.jetbrains.com/pages/viewpage.action?pageId=35367");
}
})
.disableUpDownActions()
.createPanel());
myEditButton = ToolbarDecorator.findEditButton(myTreePanel);
myRemoveButton = ToolbarDecorator.findRemoveButton(myTreePanel);
AnActionButton addButton = ToolbarDecorator.findAddButton(myTreePanel);
assert addButton != null;
dumbService.makeDumbAware(addButton.getContextComponent(), this);
dumbService.makeDumbAware(myEditButton.getContextComponent(), this);
}