use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.
the class TodoPanel method initUI.
private void initUI() {
UIUtil.setLineStyleAngled(myTree);
myTree.setShowsRootHandles(true);
myTree.setRootVisible(false);
myTree.setCellRenderer(new TodoCompositeRenderer());
EditSourceOnDoubleClickHandler.install(myTree);
new TreeSpeedSearch(myTree);
DefaultActionGroup group = new DefaultActionGroup();
group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE));
group.addSeparator();
group.add(ActionManager.getInstance().getAction(IdeActions.GROUP_VERSION_CONTROLS));
PopupHandler.installPopupHandler(myTree, group, ActionPlaces.TODO_VIEW_POPUP, ActionManager.getInstance());
myTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (!e.isConsumed() && KeyEvent.VK_ENTER == e.getKeyCode()) {
TreePath path = myTree.getSelectionPath();
if (path == null) {
return;
}
final Object userObject = ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject();
if (!((userObject instanceof NodeDescriptor ? (NodeDescriptor) userObject : null) instanceof TodoItemNode)) {
return;
}
OpenSourceUtil.openSourcesFrom(DataManager.getInstance().getDataContext(TodoPanel.this), false);
}
}
});
myUsagePreviewPanel = new UsagePreviewPanel(myProject, FindInProjectUtil.setupViewPresentation(false, new FindModel()));
Disposer.register(this, myUsagePreviewPanel);
myUsagePreviewPanel.setVisible(mySettings.showPreview);
setContent(createCenterComponent());
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(final TreeSelectionEvent e) {
ApplicationManager.getApplication().invokeLater(() -> {
if (myUsagePreviewPanel.isVisible()) {
updatePreviewPanel();
}
}, ModalityState.NON_MODAL, myProject.getDisposed());
}
});
// Create tool bars and register custom shortcuts
JPanel toolBarPanel = new JPanel(new GridLayout());
DefaultActionGroup leftGroup = new DefaultActionGroup();
leftGroup.add(new PreviousOccurenceToolbarAction(myOccurenceNavigator));
leftGroup.add(new NextOccurenceToolbarAction(myOccurenceNavigator));
leftGroup.add(new ContextHelpAction("find.todoList"));
toolBarPanel.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.TODO_VIEW_TOOLBAR, leftGroup, false).getComponent());
DefaultActionGroup rightGroup = new DefaultActionGroup();
AnAction expandAllAction = CommonActionsManager.getInstance().createExpandAllAction(myTreeExpander, this);
rightGroup.add(expandAllAction);
AnAction collapseAllAction = CommonActionsManager.getInstance().createCollapseAllAction(myTreeExpander, this);
rightGroup.add(collapseAllAction);
if (!myCurrentFileMode) {
MyShowModulesAction showModulesAction = new MyShowModulesAction();
showModulesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_M, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)), myTree);
rightGroup.add(showModulesAction);
MyShowPackagesAction showPackagesAction = new MyShowPackagesAction();
showPackagesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_P, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)), myTree);
rightGroup.add(showPackagesAction);
MyFlattenPackagesAction flattenPackagesAction = new MyFlattenPackagesAction();
flattenPackagesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)), myTree);
rightGroup.add(flattenPackagesAction);
}
MyAutoScrollToSourceHandler autoScrollToSourceHandler = new MyAutoScrollToSourceHandler();
autoScrollToSourceHandler.install(myTree);
rightGroup.add(autoScrollToSourceHandler.createToggleAction());
SetTodoFilterAction setTodoFilterAction = new SetTodoFilterAction(myProject, mySettings, todoFilter -> setTodoFilter(todoFilter));
rightGroup.add(setTodoFilterAction);
rightGroup.add(new MyPreviewAction());
toolBarPanel.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.TODO_VIEW_TOOLBAR, rightGroup, false).getComponent());
setToolbar(toolBarPanel);
}
use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.
the class CertificateConfigurable method initializeUI.
private void initializeUI() {
myTree = new Tree();
myTreeBuilder = new CertificateTreeBuilder(myTree);
myTrustManager = CertificateManager.getInstance().getCustomTrustManager();
// show newly added certificates
myTrustManager.addListener(this);
myTree.getEmptyText().setText("No certificates");
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
myTree.setRootVisible(false);
//myTree.setShowsRootHandles(false);
ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTree).disableUpDownActions();
decorator.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
// show choose file dialog, add certificate
FileChooser.chooseFile(CERTIFICATE_DESCRIPTOR, null, null, file -> {
String path = file.getPath();
X509Certificate certificate = CertificateUtil.loadX509Certificate(path);
if (certificate == null) {
Messages.showErrorDialog(myRootPanel, "Malformed X509 server certificate", "Not Imported");
} else if (myCertificates.contains(certificate)) {
Messages.showWarningDialog(myRootPanel, "Certificate already exists", "Not Imported");
} else {
myCertificates.add(certificate);
myTreeBuilder.addCertificate(certificate);
addCertificatePanel(certificate);
myTreeBuilder.selectCertificate(certificate);
}
});
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
// allow to delete several certificates at once
for (X509Certificate certificate : myTreeBuilder.getSelectedCertificates(true)) {
myCertificates.remove(certificate);
myTreeBuilder.removeCertificate(certificate);
}
if (myCertificates.isEmpty()) {
showCard(EMPTY_PANEL);
} else {
myTreeBuilder.selectFirstCertificate();
}
}
});
myTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
X509Certificate certificate = myTreeBuilder.getFirstSelectedCertificate(true);
if (certificate != null) {
showCard(getCardName(certificate));
}
}
});
myCertificatesListPanel.add(decorator.createPanel(), BorderLayout.CENTER);
}
use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.
the class ConfigureClientPropertiesDialog method createCenterPanel.
@Nullable
protected JComponent createCenterPanel() {
myClassTree = new Tree();
myClassTree.setRootVisible(false);
myClassTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
final TreePath leadSelectionPath = e.getNewLeadSelectionPath();
if (leadSelectionPath == null)
return;
final DefaultMutableTreeNode node = (DefaultMutableTreeNode) leadSelectionPath.getLastPathComponent();
mySelectedClass = (Class) node.getUserObject();
updateSelectedProperties();
}
});
myClassTree.setCellRenderer(new ColoredTreeCellRenderer() {
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
if (node.getUserObject() instanceof Class) {
Class cls = (Class) node.getUserObject();
if (cls != null) {
append(cls.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
}
}
});
fillClassTree();
myPropertiesTable = new JBTable();
myPropertiesTable.setModel(myTableModel);
mySplitter = new JBSplitter("ConfigureClientPropertiesDialog.splitterProportion", 0.5f);
mySplitter.setFirstComponent(ToolbarDecorator.createDecorator(myClassTree).setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
ClassNameInputDialog dlg = new ClassNameInputDialog(myProject, mySplitter);
dlg.show();
if (dlg.getExitCode() == OK_EXIT_CODE) {
String className = dlg.getClassName();
if (className.length() == 0)
return;
final Class aClass;
try {
aClass = Class.forName(className);
} catch (ClassNotFoundException ex) {
Messages.showErrorDialog(mySplitter, UIDesignerBundle.message("client.properties.class.not.found", className), UIDesignerBundle.message("client.properties.title"));
return;
}
if (!JComponent.class.isAssignableFrom(aClass)) {
Messages.showErrorDialog(mySplitter, UIDesignerBundle.message("client.properties.class.not.component", className), UIDesignerBundle.message("client.properties.title"));
return;
}
myManager.addClientPropertyClass(className);
fillClassTree();
}
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
if (mySelectedClass != null) {
myManager.removeClientPropertyClass(mySelectedClass);
fillClassTree();
}
}
}).setToolbarPosition(SystemInfo.isMac ? ActionToolbarPosition.BOTTOM : ActionToolbarPosition.RIGHT).createPanel());
mySplitter.setSecondComponent(ToolbarDecorator.createDecorator(myPropertiesTable).disableUpDownActions().setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
AddClientPropertyDialog dlg = new AddClientPropertyDialog(myProject);
dlg.show();
if (dlg.getExitCode() == OK_EXIT_CODE) {
ClientPropertiesManager.ClientProperty[] props = myManager.getClientProperties(mySelectedClass);
for (ClientPropertiesManager.ClientProperty prop : props) {
if (prop.getName().equalsIgnoreCase(dlg.getEnteredProperty().getName())) {
Messages.showErrorDialog(mySplitter, UIDesignerBundle.message("client.properties.already.defined", prop.getName()), UIDesignerBundle.message("client.properties.title"));
return;
}
}
myManager.addConfiguredProperty(mySelectedClass, dlg.getEnteredProperty());
updateSelectedProperties();
}
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
int row = myPropertiesTable.getSelectedRow();
if (row >= 0 && row < mySelectedProperties.length) {
myManager.removeConfiguredProperty(mySelectedClass, mySelectedProperties[row].getName());
updateSelectedProperties();
if (mySelectedProperties.length > 0) {
if (row >= mySelectedProperties.length)
row--;
myPropertiesTable.getSelectionModel().setSelectionInterval(row, row);
}
}
}
}).createPanel());
return mySplitter;
}
use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.
the class TemplateListPanel method createTable.
private JPanel createTable() {
myTreeRoot = new CheckedTreeNode(null);
myTree = new LiveTemplateTree(new CheckboxTree.CheckboxTreeCellRenderer() {
@Override
public void customizeRenderer(final JTree tree, Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
if (!(value instanceof DefaultMutableTreeNode))
return;
value = ((DefaultMutableTreeNode) value).getUserObject();
if (value instanceof TemplateImpl) {
TemplateImpl template = (TemplateImpl) value;
TemplateImpl defaultTemplate = TemplateSettings.getInstance().getDefaultTemplate(template);
Color fgColor = defaultTemplate != null && templatesDiffer(template, defaultTemplate) ? JBColor.BLUE : null;
getTextRenderer().append(template.getKey(), new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, fgColor));
String description = template.getDescription();
if (StringUtil.isNotEmpty(description)) {
getTextRenderer().append(" (" + description + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
}
} else if (value instanceof TemplateGroup) {
getTextRenderer().append(((TemplateGroup) value).getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
}
}
}, myTreeRoot, this);
myTree.setRootVisible(false);
myTree.setShowsRootHandles(true);
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(@NotNull final TreeSelectionEvent e) {
TemplateSettings templateSettings = TemplateSettings.getInstance();
TemplateImpl template = getTemplate(getSingleSelectedIndex());
if (template != null) {
templateSettings.setLastSelectedTemplate(template.getGroupName(), template.getKey());
} else {
templateSettings.setLastSelectedTemplate(null, null);
showEmptyCard();
}
if (myUpdateNeeded) {
myAlarm.cancelAllRequests();
myAlarm.addRequest(() -> updateTemplateDetails(false, false), 100);
}
}
});
myTree.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(@Nullable ActionEvent event) {
myCurrentTemplateEditor.focusKey();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED);
installPopup();
DnDSupport.createBuilder(myTree).setBeanProvider((NullableFunction<DnDActionInfo, DnDDragStartBean>) dnDActionInfo -> {
Point point = dnDActionInfo.getPoint();
if (myTree.getPathForLocation(point.x, point.y) == null)
return null;
Map<TemplateImpl, DefaultMutableTreeNode> templates = getSelectedTemplates();
return !templates.isEmpty() ? new DnDDragStartBean(templates) : null;
}).setDisposableParent(this).setTargetChecker(new DnDTargetChecker() {
@Override
public boolean update(DnDEvent event) {
@SuppressWarnings("unchecked") Set<String> oldGroupNames = getAllGroups((Map<TemplateImpl, DefaultMutableTreeNode>) event.getAttachedObject());
TemplateGroup group = getDropGroup(event);
boolean differentGroup = group != null && !oldGroupNames.contains(group.getName());
event.setDropPossible(differentGroup, "");
return true;
}
}).setDropHandler(new DnDDropHandler() {
@Override
public void drop(DnDEvent event) {
//noinspection unchecked
moveTemplates((Map<TemplateImpl, DefaultMutableTreeNode>) event.getAttachedObject(), ObjectUtils.assertNotNull(getDropGroup(event)).getName());
}
}).setImageProvider((NullableFunction<DnDActionInfo, DnDImage>) dnDActionInfo -> {
Point point = dnDActionInfo.getPoint();
TreePath path = myTree.getPathForLocation(point.x, point.y);
return path == null ? null : new DnDImage(DnDAwareTree.getDragImage(myTree, path, point).first);
}).install();
if (myTemplateGroups.size() > 0) {
myTree.setSelectionInterval(0, 0);
}
return initToolbar().createPanel();
}
use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.
the class PackageChooserDialog method createCenterPanel.
protected JComponent createCenterPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
myModel = new DefaultTreeModel(new DefaultMutableTreeNode());
createTreeModel();
myTree = new Tree(myModel);
UIUtil.setLineStyleAngled(myTree);
myTree.setCellRenderer(new DefaultTreeCellRenderer() {
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
setIcon(PlatformIcons.PACKAGE_ICON);
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
Object object = node.getUserObject();
if (object instanceof PsiPackage) {
String name = ((PsiPackage) object).getName();
if (name != null && name.length() > 0) {
setText(name);
} else {
setText(IdeBundle.message("node.default"));
}
}
}
return this;
}
});
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
scrollPane.setPreferredSize(JBUI.size(500, 300));
new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
public String convert(TreePath path) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
Object object = node.getUserObject();
if (object instanceof PsiPackage)
return ((PsiPackage) object).getName();
else
return "";
}
});
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
PsiPackage selection = getTreeSelection();
if (selection != null) {
String name = selection.getQualifiedName();
setTitle(myTitle + " - " + ("".equals(name) ? IdeBundle.message("node.default.package") : name));
} else {
setTitle(myTitle);
}
updatePathFromTree();
}
});
panel.add(scrollPane, BorderLayout.CENTER);
DefaultActionGroup group = createActionGroup(myTree);
final JPanel northPanel = new JPanel(new BorderLayout());
panel.add(northPanel, BorderLayout.NORTH);
ActionToolbar toolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
northPanel.add(toolBar.getComponent(), BorderLayout.WEST);
setupPathComponent(northPanel);
return panel;
}
Aggregations