Java Code Examples for javax.swing.tree.DefaultTreeSelectionModel

The following examples show how to use javax.swing.tree.DefaultTreeSelectionModel. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: azure-devops-intellij   Source File: PullRequestsTreeModel.java    License: MIT License 6 votes vote down vote up
public PullRequestsTreeModel() {
    super(null);

    this.root = new PRTreeNode(TfPluginBundle.message(TfPluginBundle.KEY_VCS_PR_TITLE));
    setRoot(root);
    this.requestedByMeRoot = new PRTreeNode(TfPluginBundle.message(TfPluginBundle.KEY_VCS_PR_REQUESTED_BY_ME));
    root.insert(requestedByMeRoot, 0);
    this.assignedToMeRoot = new PRTreeNode(TfPluginBundle.message(TfPluginBundle.KEY_VCS_PR_ASSIGNED_TO_ME));
    root.insert(assignedToMeRoot, 1);

    allRequestedByMePullRequests = new ArrayList<GitPullRequest>();
    allAssignedToMePullRequests = new ArrayList<GitPullRequest>();

    selectionModel = new DefaultTreeSelectionModel();
    selectionModel.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
}
 
Example 2
Source Project: p4ic4idea   Source File: ActiveConnectionPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void setup() {
    root = new JPanel(new BorderLayout());
    JScrollPane scroll = new JBScrollPane();
    root.add(scroll, BorderLayout.CENTER);
    connectionTree = new Tree();
    scroll.setViewportView(connectionTree);

    connectionTree.getEmptyText().setText(P4Bundle.getString("connection.tree.initial"));
    connectionTree.setEditable(false);
    connectionTreeModel = new DefaultTreeModel(treeNode);
    connectionTree.setModel(connectionTreeModel);
    connectionTree.setCellRenderer(new ConnectionTreeCellRenderer());
    connectionTree.setRootVisible(false);
    DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
    selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    connectionTree.setSelectionModel(selectionModel);

    ActionGroup actionButtons = createActionGroup();
    ActionToolbar toolbar =
            ActionManager.getInstance().createActionToolbar("p4.active-connection",
                    actionButtons, false);
    root.add(toolbar.getComponent(), BorderLayout.WEST);

    // TODO add context menu support for each selected node type.
    // TODO add support for navigating to a file if a FilePath is selected.
}
 
Example 3
/**
 * Creates the JTree for the report configuration.
 *
 * @return the tree component.
 * @throws ConfigTreeModelException if the model could not be built.
 */
private JComponent createEntryTree( final boolean includeGlobals ) {
  treeModel = new ConfigTreeModel( packageManager, includeGlobals );

  final TreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
  selectionModel.setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );

  tree = new JTree( treeModel );
  tree.setSelectionModel( selectionModel );
  tree.setCellRenderer( new ConfigTreeRenderer() );
  tree.setRootVisible( false );
  tree.setShowsRootHandles( true );
  tree.addTreeSelectionListener( new ModuleTreeSelectionHandler() );

  return new JScrollPane
    ( tree, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
      ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER );
}
 
Example 4
protected void init() {
  setTitle( EditorExpressionsMessages.getString( "ExpressionChooserDialog.Title" ) );
  setModal( true );

  final DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
  selectionModel.setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
  selectionModel.addTreeSelectionListener( new ExpressionSelectionHandler() );

  expressionsTree = new JTree( ExpressionsTreeModel.getTreeModel() );
  expressionsTree.setRootVisible( false );
  expressionsTree.setSelectionModel( selectionModel );
  expressionsTree.addMouseListener( new DblClickHandler() );
  expressionsTree.setCellRenderer( new ExpressionTreeCellRenderer() );

  addAction = new AddAction();

  super.init();
}
 
Example 5
Source Project: binnavi   Source File: CTagsTree.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new tree object.
 *
 * @param parent Parent window used for dialogs.
 * @param graph Graph shown in the window.
 * @param manager Provides tag information.
 */
public CTagsTree(final JFrame parent, final ZyGraph graph, final ITagManager manager) {
  m_parent = Preconditions.checkNotNull(parent, "IE02308: Perent argument can not be null");
  m_graph = Preconditions.checkNotNull(graph, "IE01776: Graph can not be null");
  m_tagManager = Preconditions.checkNotNull(manager, "IE01777: Manager argument can not be null");

  m_model = new CTagsTreeModel(this);
  setModel(m_model);
  getModel().addTreeModelListener(new InternalModelListener());
  addMouseListener(m_mouseListener);
  m_graph.addListener(m_graphSelectionListener);
  m_graph.addListener(m_graphVisibilityListener);

  setRootVisible(false);

  m_rootNode = new CRootTagTreeNode(parent, this, graph, m_tagManager);
  m_model.setRoot(m_rootNode);

  setCellRenderer(new CTagTreeCellRenderer()); // ATTENTION: UNDER NO CIRCUMSTANCES MOVE THIS LINE
                                               // ABOVE THE SETROOT LINE

  m_model.nodeStructureChanged(m_rootNode);

  final List<IDropHandler> handlers = new ArrayList<IDropHandler>();

  handlers.add(new CTagSortingHandler());

  new CDefaultTransferHandler(this, DnDConstants.ACTION_COPY_OR_MOVE, handlers);

  final DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
  selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  setSelectionModel(selectionModel);

  final InputMap windowImap = getInputMap(JComponent.WHEN_FOCUSED);

  windowImap.put(HotKeys.DELETE_HK.getKeyStroke(), "DELETE");
  getActionMap().put("DELETE", CActionProxy.proxy(new DeleteAction()));
}
 
Example 6
Source Project: binnavi   Source File: TypesTree.java    License: Apache License 2.0 5 votes vote down vote up
public TypesTree() {
  setRootVisible(false);
  setDragEnabled(true);
  setDropMode(DropMode.INSERT); // Dropped objects are inserted behind the drop location.
  setToggleClickCount(1); // Child nodes expand with a single click.
  final DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
  selectionModel.setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
  setSelectionModel(selectionModel);
  final IconNodeRenderer renderer = new IconNodeRenderer();
  renderer.setFont(GuiHelper.MONOSPACED_FONT);
  setCellRenderer(renderer);
}
 
Example 7
Source Project: binnavi   Source File: CSelectionHistoryChooser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Frees allocated resources.
 */
public void dispose() {
  m_selectionHistory.removeHistoryListener(m_selectionHistoryListener);

  m_graph.removeListener(m_graphSelectionListener);
  m_tree.removeMouseListener(m_treeMouseListener);
  m_tree.removeTreeSelectionListener(m_treeSelectionListener);

  m_tree.setSelectionModel(new DefaultTreeSelectionModel());
}
 
Example 8
Source Project: uima-uimaj   Source File: MainFrame.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Inits the.
 */
private void init() {
  // Set the title.
  this.setTitle("Type System Editor");
  JSplitPane contentPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
  this.setContentPane(contentPane);

  // Set up the type tree. Use simple DefaultTreeModel.
  DefaultMutableTreeNode root = new DefaultMutableTreeNode("<html><b>No CAS!</b></html>");
  DefaultTreeModel treeModel = new DefaultTreeModel(root);
  this.typeTree = new JTree(treeModel);
  this.typeTree.addTreeSelectionListener(new TypeTreeSelectionListener());
  TreeSelectionModel treeSelectionModel = new DefaultTreeSelectionModel();
  treeSelectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  this.typeTree.setSelectionModel(treeSelectionModel);
  JScrollPane treePane = new JScrollPane(this.typeTree);
  contentPane.setLeftComponent(treePane);
  DefaultTreeCellRenderer cellRenderer = new DefaultTreeCellRenderer();
  cellRenderer.setLeafIcon(null);
  // cellRenderer.setIcon(null);
  cellRenderer.setClosedIcon(null);
  cellRenderer.setOpenIcon(null);
  this.typeTree.setCellRenderer(cellRenderer);

  // Set up the feature table.
  this.featureTable = new JTable(new FeatureTableModel());
  JScrollPane featurePane = new JScrollPane(this.featureTable);
  featurePane.getViewport().setBackground(Color.WHITE);
  contentPane.setRightComponent(featurePane);

  this.setJMenuBar(createMenuBar());
}
 
Example 9
Source Project: netbeans   Source File: PathsCustomizer.java    License: Apache License 2.0 4 votes vote down vote up
public SelectionListener(DefaultTreeModel treeModel, JList list, DefaultListModel otherListModel, DefaultTreeSelectionModel otherTreeModel) {
    this.treeModel = treeModel;
    this.list = list;
    this.otherListModel = otherListModel;
    this.otherTreeSelectionModel = otherTreeModel;
}
 
Example 10
Source Project: netbeans   Source File: PathsCustomizer.java    License: Apache License 2.0 4 votes vote down vote up
public SelectionListener(DefaultTreeModel treeModel, JList list, DefaultListModel otherListModel, DefaultTreeSelectionModel otherTreeModel) {
    this.treeModel = treeModel;
    this.list = list;
    this.otherListModel = otherListModel;
    this.otherTreeSelectionModel = otherTreeModel;
}
 
Example 11
Source Project: binnavi   Source File: CCombinedRightPanel.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Frees allocated resources.
 */
public void dispose() {
  taggingPanel.getTree().dispose();
  taggingPanel.getTree().setSelectionModel(new DefaultTreeSelectionModel());
}