use of javax.swing.event.TreeSelectionEvent in project felix by apache.
the class OBRPlugin method createEventListeners.
private void createEventListeners() {
// Create action listeners.
m_addRepoButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
synchronized (OBRPlugin.this) {
if (m_repoAdmin == null) {
return;
}
String s = JOptionPane.showInputDialog(OBRPlugin.this, "Enter repository URL:");
if (s != null) {
try {
m_repoAdmin.addRepository(new URL(s));
} catch (Exception ex) {
ex.printStackTrace();
}
}
// Update the table.
initializeRootNode();
}
}
});
m_removeRepoButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
synchronized (OBRPlugin.this) {
if (m_repoAdmin == null) {
return;
}
TreePath[] paths = m_bundleTree.getSelectionPaths();
for (int i = 0; i < paths.length; i++) {
SimpleTreeNode node = (SimpleTreeNode) paths[i].getLastPathComponent();
if (node.getObject() instanceof Repository) {
m_repoAdmin.removeRepository(((Repository) ((SimpleTreeNode) paths[i].getLastPathComponent()).getObject()).getURL());
}
}
// Update the table.
initializeRootNode();
}
}
});
m_refreshRepoButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
synchronized (OBRPlugin.this) {
if (m_repoAdmin == null) {
return;
}
TreePath[] paths = m_bundleTree.getSelectionPaths();
for (int i = 0; i < paths.length; i++) {
SimpleTreeNode node = (SimpleTreeNode) paths[i].getLastPathComponent();
if (node.getObject() instanceof Repository) {
try {
// Adding the repository again causes it to be reparsed.
m_repoAdmin.addRepository(((Repository) node.getObject()).getURL());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
// Update the table.
initializeRootNode();
}
}
});
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent event) {
boolean start = event.getActionCommand().equals(START_BUTTON);
synchronized (OBRPlugin.this) {
if (m_repoAdmin == null) {
return;
}
Resolver resolver = m_repoAdmin.resolver();
TreePath[] paths = m_bundleTree.getSelectionPaths();
for (int i = 0; i < paths.length; i++) {
SimpleTreeNode node = (SimpleTreeNode) paths[i].getLastPathComponent();
if (node.getObject() instanceof Resource) {
resolver.add((Resource) node.getObject());
}
}
if ((resolver.getAddedResources() != null) && (resolver.getAddedResources().length > 0)) {
if (resolver.resolve()) {
m_out.println("Target resource(s):");
printUnderline(m_out, 19);
Resource[] resources = resolver.getAddedResources();
for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
m_out.println(" " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
}
resources = resolver.getRequiredResources();
if ((resources != null) && (resources.length > 0)) {
m_out.println("\nRequired resource(s):");
printUnderline(m_out, 21);
for (int resIdx = 0; resIdx < resources.length; resIdx++) {
m_out.println(" " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
}
}
resources = resolver.getOptionalResources();
if ((resources != null) && (resources.length > 0)) {
m_out.println("\nOptional resource(s):");
printUnderline(m_out, 21);
for (int resIdx = 0; resIdx < resources.length; resIdx++) {
m_out.println(" " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
}
}
try {
m_out.print("\nDeploying...");
resolver.deploy(start);
m_out.println("done.");
} catch (IllegalStateException ex) {
m_out.println(ex);
}
} else {
Requirement[] reqs = resolver.getUnsatisfiedRequirements();
if ((reqs != null) && (reqs.length > 0)) {
m_out.println("Unsatisfied requirement(s):");
printUnderline(m_out, 27);
for (int reqIdx = 0; reqIdx < reqs.length; reqIdx++) {
m_out.println(" " + reqs[reqIdx].getFilter());
Resource[] resources = resolver.getResources(reqs[reqIdx]);
for (int resIdx = 0; resIdx < resources.length; resIdx++) {
m_out.println(" " + resources[resIdx].getPresentationName());
}
}
} else {
m_out.println("Could not resolve targets.");
}
}
m_out.println("");
}
}
}
};
m_deployButton.addActionListener(al);
m_startButton.addActionListener(al);
m_infoButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
synchronized (OBRPlugin.this) {
if (m_repoAdmin == null) {
return;
}
TreePath[] paths = m_bundleTree.getSelectionPaths();
for (int i = 0; i < paths.length; i++) {
if (i != 0) {
m_out.println("");
}
printInfo(m_out, ((SimpleTreeNode) paths[i].getLastPathComponent()).getObject());
}
m_out.println("");
}
}
});
m_clearButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
synchronized (OBRPlugin.this) {
m_soa.setText("");
}
}
});
m_bundleTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
if (m_repoAdmin == null) {
return;
}
TreePath[] paths = m_bundleTree.getSelectionPaths();
boolean repoOnly = true;
if (paths != null) {
for (int i = 0; repoOnly && (i < paths.length); i++) {
SimpleTreeNode node = (SimpleTreeNode) paths[i].getLastPathComponent();
if (!(node.getObject() instanceof Repository)) {
repoOnly = false;
}
}
}
m_removeRepoButton.setEnabled((paths != null) && repoOnly);
m_refreshRepoButton.setEnabled((paths != null) && repoOnly);
m_infoButton.setEnabled((paths != null) && (paths.length > 0));
}
});
}
use of javax.swing.event.TreeSelectionEvent in project JMRI by JMRI.
the class TreePaneDemo method testWithSelect.
@Test
public void testWithSelect() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
frame.setTitle("listener test");
pane.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
JTree tree = (JTree) e.getSource();
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
if (node == null) {
return;
}
System.out.print("Test prints selected treenode " + node);
if (node.getUserObject() instanceof NodeTreeRep.SelectionKey) {
System.out.println(" and invokes");
((NodeTreeRep.SelectionKey) node.getUserObject()).select(node);
} else {
System.out.println();
}
}
});
Message msg;
msg = new ProducerIdentifiedMessage(nid2, eventA, EventState.Unknown);
store.put(msg, null);
store.put(pipmsg, null);
msg = new SimpleNodeIdentInfoReplyMessage(nid2, nid2, new byte[] { 0x01, 0x31, 0x32, 0x33, 0x41, 0x42, (byte) 0xC2, (byte) 0xA2, 0x44, 0x00 });
store.put(msg, null);
}
use of javax.swing.event.TreeSelectionEvent in project JMRI by JMRI.
the class CatalogPanel method init.
protected void init(boolean treeDnD) {
_model = new DefaultTreeModel(new CatalogTreeNode("mainRoot"));
if (treeDnD) {
// index editor (right pane)
_dTree = new DropJTree(_model);
_noDrag = true;
} else {
// Catalog (left pane index editor or all icon editors)
_dTree = new JTree(_model);
_noDrag = false;
}
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setLeafIcon(renderer.getClosedIcon());
_dTree.setCellRenderer(renderer);
_dTree.setRootVisible(false);
_dTree.setShowsRootHandles(true);
_dTree.setScrollsOnExpand(true);
//_dTree.setDropMode(DropMode.ON);
_dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
_dTree.addTreeSelectionListener((TreeSelectionEvent e) -> {
updatePanel();
});
_dTree.setExpandsSelectedPaths(true);
_treePane.setViewportView(_dTree);
// setupPanel();
}
use of javax.swing.event.TreeSelectionEvent in project JMRI by JMRI.
the class NetworkTreePane method initComponents.
@Override
public void initComponents(CanSystemConnectionMemo memo) {
this.memo = memo;
memo.getTrafficController().addCanListener(this);
// add GUI components
setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
treePane = new TreePane();
treePane.setPreferredSize(new Dimension(300, 300));
treePane.initComponents((MimicNodeStore) memo.get(MimicNodeStore.class), (Connection) memo.get(Connection.class), (NodeID) memo.get(NodeID.class), new ActionLoader(memo.get(OlcbInterface.class)));
add(treePane);
treePane.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
JTree tree = (JTree) e.getSource();
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
if (node == null) {
return;
}
if (node.getUserObject() instanceof NodeTreeRep.SelectionKey) {
((NodeTreeRep.SelectionKey) node.getUserObject()).select(node);
}
}
});
}
use of javax.swing.event.TreeSelectionEvent in project intellij-plugins by JetBrains.
the class ChooseBuildConfigurationDialog method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
List<Module> modules = new ArrayList<>(myTreeItems.keySet());
Collections.sort(modules, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
for (Module module : modules) {
DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(module, true);
root.add(moduleNode);
List<FlexBCConfigurable> bcs = myTreeItems.get(module);
Collections.sort(bcs, (o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName()));
for (FlexBCConfigurable bc : bcs) {
DefaultMutableTreeNode bcNode = new DefaultMutableTreeNode(bc, false);
moduleNode.add(bcNode);
}
}
myTree.setModel(new DefaultTreeModel(root));
myTree.setRootVisible(false);
new TreeSpeedSearch(myTree, o -> {
Object lastPathComponent = o.getLastPathComponent();
return getText((DefaultMutableTreeNode) lastPathComponent);
}, true).setComparator(new SpeedSearchComparator(false));
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
updateOnSelectionChange();
}
});
myTree.setCellRenderer(new ColoredTreeCellRenderer() {
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
Object object = treeNode.getUserObject();
if (object instanceof Module) {
Module module = (Module) object;
setIcon(ModuleType.get(module).getIcon());
append(module.getName());
} else if (object instanceof FlexBCConfigurable) {
FlexBCConfigurable configurable = (FlexBCConfigurable) object;
setIcon(configurable.getIcon());
BCUtils.renderBuildConfiguration(configurable.getEditableObject(), null).appendToComponent(this);
}
}
});
TreeUtil.expandAll(myTree);
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
if (mySelection != null) {
doOKAction();
return true;
}
return false;
}
}.installOn(myTree);
myTree.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
doOKAction();
}
}
});
updateOnSelectionChange();
return myContentPane;
}
Aggregations