use of javax.swing.tree.DefaultTreeModel in project intellij-community by JetBrains.
the class ConfigureTasksActivationDialog method moveSelectedRows.
private static void moveSelectedRows(@NotNull final SimpleTree tree, final int direction) {
final TreePath[] selectionPaths = tree.getSelectionPaths();
if (selectionPaths == null)
return;
ContainerUtil.sort(selectionPaths, new Comparator<TreePath>() {
@Override
public int compare(TreePath o1, TreePath o2) {
return -direction * compare(tree.getRowForPath(o1), tree.getRowForPath(o2));
}
private int compare(int x, int y) {
return (x < y) ? -1 : ((x == y) ? 0 : 1);
}
});
for (TreePath selectionPath : selectionPaths) {
final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) treeNode.getParent();
final int idx = parent.getIndex(treeNode);
((DefaultTreeModel) tree.getModel()).removeNodeFromParent(treeNode);
((DefaultTreeModel) tree.getModel()).insertNodeInto(treeNode, parent, idx + direction);
}
tree.addSelectionPaths(selectionPaths);
}
use of javax.swing.tree.DefaultTreeModel in project intellij-community by JetBrains.
the class ScopeTreeViewPanel method refreshScope.
public void refreshScope(@Nullable NamedScope scope) {
FileTreeModelBuilder.clearCaches(myProject);
if (scope == null) {
//was deleted
scope = CustomScopesProviderEx.getAllScope();
}
final NamedScopesHolder holder = NamedScopesHolder.getHolder(myProject, scope.getName(), myDependencyValidationManager);
final PackageSet packageSet = scope.getValue() != null ? scope.getValue() : new InvalidPackageSet("");
final DependenciesPanel.DependencyPanelSettings settings = new DependenciesPanel.DependencyPanelSettings();
settings.UI_FILTER_LEGALS = true;
settings.UI_GROUP_BY_SCOPE_TYPE = false;
settings.UI_SHOW_FILES = true;
final ProjectView projectView = ProjectView.getInstance(myProject);
settings.UI_FLATTEN_PACKAGES = projectView.isFlattenPackages(ScopeViewPane.ID);
settings.UI_COMPACT_EMPTY_MIDDLE_PACKAGES = projectView.isHideEmptyMiddlePackages(ScopeViewPane.ID);
settings.UI_SHOW_MODULES = projectView.isShowModules(ScopeViewPane.ID);
settings.UI_SHOW_MODULE_GROUPS = projectView.isShowModules(ScopeViewPane.ID);
myBuilder = new FileTreeModelBuilder(myProject, new Marker() {
@Override
public boolean isMarked(VirtualFile file) {
return packageSet != null && (packageSet instanceof PackageSetBase ? ((PackageSetBase) packageSet).contains(file, myProject, holder) : packageSet.contains(PackageSetBase.getPsiFile(file, myProject), holder));
}
}, settings);
myTree.setPaintBusy(true);
myBuilder.setTree(myTree);
myTree.getEmptyText().setText("Loading...");
myActionCallback = new ActionCallback();
myTree.putClientProperty(TreeState.CALLBACK, new WeakReference<>(myActionCallback));
myTree.setModel(myBuilder.build(myProject, true, () -> {
myTree.setPaintBusy(false);
myTree.getEmptyText().setText(UIBundle.message("message.nothingToShow"));
myActionCallback.setDone();
}));
((PackageDependenciesNode) myTree.getModel().getRoot()).sortChildren();
((DefaultTreeModel) myTree.getModel()).reload();
FileTreeModelBuilder.clearCaches(myProject);
}
use of javax.swing.tree.DefaultTreeModel in project intellij-community by JetBrains.
the class ModulesDependenciesPanel method updateRightTree.
private void updateRightTree(Module module) {
DefaultMutableTreeNode root = (DefaultMutableTreeNode) myRightTree.getModel().getRoot();
root.removeAllChildren();
Set<List<Module>> cycles = GraphAlgorithms.getInstance().findCycles(myModuleGraph, module);
int index = 1;
for (List<Module> modules : cycles) {
DefaultMutableTreeNode cycle = new DefaultMutableTreeNode(AnalysisScopeBundle.message("module.dependencies.cycle.node.text", index++));
root.add(cycle);
cycle.add(new DefaultMutableTreeNode(new MyUserObject(false, module)));
for (Module moduleInCycle : modules) {
cycle.add(new DefaultMutableTreeNode(new MyUserObject(false, moduleInCycle)));
}
}
((DefaultTreeModel) myRightTree.getModel()).reload();
TreeUtil.expandAll(myRightTree);
}
use of javax.swing.tree.DefaultTreeModel in project jadx by skylot.
the class MainWindow method initUI.
private void initUI() {
mainPanel = new JPanel(new BorderLayout());
JSplitPane splitPane = new JSplitPane();
splitPane.setResizeWeight(SPLIT_PANE_RESIZE_WEIGHT);
mainPanel.add(splitPane);
DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode(NLS.str("msg.open_file"));
treeModel = new DefaultTreeModel(treeRoot);
tree = new JTree(treeModel);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
treeClickAction();
}
});
tree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
treeClickAction();
}
}
});
tree.setCellRenderer(new DefaultTreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean isLeaf, int row, boolean focused) {
Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
if (value instanceof JNode) {
setIcon(((JNode) value).getIcon());
}
return c;
}
});
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
TreePath path = event.getPath();
Object node = path.getLastPathComponent();
if (node instanceof JClass) {
JClass cls = (JClass) node;
cls.getRootClass().load();
}
}
@Override
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
}
});
progressPane = new ProgressPanel(this, true);
JPanel leftPane = new JPanel(new BorderLayout());
leftPane.add(new JScrollPane(tree), BorderLayout.CENTER);
leftPane.add(progressPane, BorderLayout.PAGE_END);
splitPane.setLeftComponent(leftPane);
tabbedPane = new TabbedPane(this);
splitPane.setRightComponent(tabbedPane);
dropTarget = new DropTarget(this, DnDConstants.ACTION_COPY, new MainDropTarget(this));
setContentPane(mainPanel);
setTitle(DEFAULT_TITLE);
}
use of javax.swing.tree.DefaultTreeModel in project intellij-plugins by JetBrains.
the class BundleSelector method createModel.
private static TreeModel createModel(Project project, FrameworkInstanceDefinition instance, Collection<SelectedBundle> selectedList) {
Set<SelectedBundle> selected = ContainerUtil.newHashSet(selectedList);
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
// all the modules
DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(OsmorcBundle.message("bundle.selector.group.modules"));
Module[] modules = ModuleManager.getInstance(project).getModules();
for (Module module : modules) {
if (OsmorcFacet.hasOsmorcFacet(module)) {
SelectedBundle bundle = new SelectedBundle(SelectedBundle.BundleType.Module, module.getName(), null);
if (!selected.contains(bundle)) {
moduleNode.add(new DefaultMutableTreeNode(bundle));
}
}
}
if (moduleNode.getChildCount() > 0)
root.add(moduleNode);
// all the framework bundles (if there are any)
if (instance != null) {
FrameworkIntegrator integrator = FrameworkIntegratorRegistry.getInstance().findIntegratorByInstanceDefinition(instance);
if (integrator != null) {
DefaultMutableTreeNode frameworkNode = new DefaultMutableTreeNode(OsmorcBundle.message("bundle.selector.group.framework"));
for (SelectedBundle bundle : integrator.getFrameworkInstanceManager().getFrameworkBundles(instance, FrameworkBundleType.OTHER)) {
if (!selected.contains(bundle)) {
frameworkNode.add(new DefaultMutableTreeNode(bundle));
}
}
if (frameworkNode.getChildCount() > 0)
root.add(frameworkNode);
}
}
// all the libraries that are bundles already (doesn't make much sense to start bundlified libs as they have no activator).
DefaultMutableTreeNode libraryNode = new DefaultMutableTreeNode(OsmorcBundle.message("bundle.selector.group.libraries"));
List<String> paths = OrderEnumerator.orderEntries(project).librariesOnly().productionOnly().runtimeOnly().classes().getPathsList().getPathList();
for (String path : paths) {
String displayName = CachingBundleInfoProvider.getBundleSymbolicName(path);
if (displayName != null) {
SelectedBundle bundle = new SelectedBundle(SelectedBundle.BundleType.StartLibrary, displayName, path);
if (!selected.contains(bundle)) {
libraryNode.add(new DefaultMutableTreeNode(bundle));
}
}
}
if (libraryNode.getChildCount() > 0)
root.add(libraryNode);
return new DefaultTreeModel(root);
}
Aggregations