use of javax.swing.event.TreeSelectionListener in project intellij-community by JetBrains.
the class AutoScrollToSourceHandler method install.
public void install(final JTree tree) {
myAutoScrollAlarm = new Alarm();
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent e, int clickCount) {
if (clickCount > 1)
return false;
TreePath location = tree.getPathForLocation(e.getPoint().x, e.getPoint().y);
if (location != null) {
onMouseClicked(tree);
return isAutoScrollMode();
}
return false;
}
}.installOn(tree);
tree.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(final MouseEvent e) {
onSelectionChanged(tree);
}
});
tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
onSelectionChanged(tree);
}
});
}
use of javax.swing.event.TreeSelectionListener in project intellij-community by JetBrains.
the class ChangesTreeList method addSelectionListener.
public void addSelectionListener(final Runnable runnable) {
myGenericSelectionListener = runnable;
addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
myGenericSelectionListener.run();
}
});
}
use of javax.swing.event.TreeSelectionListener 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.TreeSelectionListener 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.TreeSelectionListener 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;
}
Aggregations