use of javax.swing.tree.DefaultTreeModel in project intellij-community by JetBrains.
the class ShelvedChangesViewManager method buildChangesModel.
private TreeModel buildChangesModel() {
// not null for TreeState matching to work
myRoot = new DefaultMutableTreeNode(ROOT_NODE_VALUE);
DefaultTreeModel model = new DefaultTreeModel(myRoot);
final List<ShelvedChangeList> changeLists = new ArrayList<>(myShelveChangesManager.getShelvedChangeLists());
Collections.sort(changeLists, ChangelistComparator.getInstance());
if (myShelveChangesManager.isShowRecycled()) {
ArrayList<ShelvedChangeList> recycled = new ArrayList<>(myShelveChangesManager.getRecycledShelvedChangeLists());
changeLists.addAll(recycled);
Collections.sort(changeLists, ChangelistComparator.getInstance());
}
myMoveRenameInfo.clear();
for (ShelvedChangeList changeList : changeLists) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(changeList);
model.insertNodeInto(node, myRoot, myRoot.getChildCount());
final List<Object> shelvedFilesNodes = new ArrayList<>();
List<ShelvedChange> changes = changeList.getChanges(myProject);
for (ShelvedChange change : changes) {
putMovedMessage(change.getBeforePath(), change.getAfterPath());
shelvedFilesNodes.add(change);
}
List<ShelvedBinaryFile> binaryFiles = changeList.getBinaryFiles();
for (ShelvedBinaryFile file : binaryFiles) {
putMovedMessage(file.BEFORE_PATH, file.AFTER_PATH);
shelvedFilesNodes.add(file);
}
Collections.sort(shelvedFilesNodes, ShelvedFilePatchComparator.getInstance());
for (int i = 0; i < shelvedFilesNodes.size(); i++) {
final Object filesNode = shelvedFilesNodes.get(i);
final DefaultMutableTreeNode pathNode = new DefaultMutableTreeNode(filesNode);
model.insertNodeInto(pathNode, node, i);
}
}
return model;
}
use of javax.swing.tree.DefaultTreeModel in project intellij-community by JetBrains.
the class TodoCheckinHandler method showTodo.
private void showTodo(TodoCheckinHandlerWorker worker) {
String title = "For commit (" + DateFormatUtil.formatDateTime(System.currentTimeMillis()) + ")";
ServiceManager.getService(myProject, TodoView.class).addCustomTodoView(new TodoTreeBuilderFactory() {
@Override
public TodoTreeBuilder createTreeBuilder(JTree tree, DefaultTreeModel treeModel, Project project) {
return new CustomChangelistTodosTreeBuilder(tree, treeModel, myProject, title, worker.inOneList());
}
}, title, new TodoPanelSettings(myConfiguration.myTodoPanelSettings));
ApplicationManager.getApplication().invokeLater(() -> {
ToolWindowManager manager = ToolWindowManager.getInstance(myProject);
if (manager != null) {
ToolWindow window = manager.getToolWindow("TODO");
if (window != null) {
window.show(() -> {
ContentManager cm = window.getContentManager();
Content[] contents = cm.getContents();
if (contents.length > 0) {
cm.setSelectedContent(contents[contents.length - 1], true);
}
});
}
}
}, ModalityState.NON_MODAL, myProject.getDisposed());
}
use of javax.swing.tree.DefaultTreeModel in project intellij-community by JetBrains.
the class ChooseLibrariesDialogBase method createCenterPanel.
@Override
@Nullable
protected JComponent createCenterPanel() {
myBuilder = new SimpleTreeBuilder(myTree, new DefaultTreeModel(new DefaultMutableTreeNode()), new MyStructure(getProject()), WeightBasedComparator.FULL_INSTANCE);
myBuilder.initRootNode();
myTree.setDragEnabled(false);
myTree.setShowsRootHandles(true);
UIUtil.setLineStyleAngled(myTree);
myTree.setRootVisible(false);
myTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(final TreeSelectionEvent e) {
updateOKAction();
}
});
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
if (isOKActionEnabled()) {
doOKAction();
return true;
}
return false;
}
}.installOn(myTree);
myTree.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ENTER");
myTree.getActionMap().put("ENTER", getOKAction());
final JScrollPane pane = ScrollPaneFactory.createScrollPane(myTree);
pane.setPreferredSize(JBUI.size(500, 400));
return pane;
}
use of javax.swing.tree.DefaultTreeModel in project intellij-community by JetBrains.
the class PackageChooserDialog method createNewPackage.
private void createNewPackage() {
final PsiPackage selectedPackage = getTreeSelection();
if (selectedPackage == null)
return;
final String newPackageName = Messages.showInputDialog(myProject, IdeBundle.message("prompt.enter.a.new.package.name"), IdeBundle.message("title.new.package"), Messages.getQuestionIcon(), "", new InputValidator() {
public boolean checkInput(final String inputString) {
return inputString != null && inputString.length() > 0;
}
public boolean canClose(final String inputString) {
return checkInput(inputString);
}
});
if (newPackageName == null)
return;
CommandProcessor.getInstance().executeCommand(myProject, () -> {
final Runnable action = () -> {
try {
String newQualifiedName = selectedPackage.getQualifiedName();
if (!Comparing.strEqual(newQualifiedName, ""))
newQualifiedName += ".";
newQualifiedName += newPackageName;
final PsiDirectory dir = PackageUtil.findOrCreateDirectoryForPackage(myProject, newQualifiedName, null, false);
if (dir == null)
return;
final PsiPackage newPackage = JavaDirectoryService.getInstance().getPackage(dir);
DefaultMutableTreeNode node = (DefaultMutableTreeNode) myTree.getSelectionPath().getLastPathComponent();
final DefaultMutableTreeNode newChild = new DefaultMutableTreeNode();
newChild.setUserObject(newPackage);
node.add(newChild);
final DefaultTreeModel model = (DefaultTreeModel) myTree.getModel();
model.nodeStructureChanged(node);
final TreePath selectionPath = myTree.getSelectionPath();
TreePath path;
if (selectionPath == null) {
path = new TreePath(newChild.getPath());
} else {
path = selectionPath.pathByAddingChild(newChild);
}
myTree.setSelectionPath(path);
myTree.scrollPathToVisible(path);
myTree.expandPath(path);
} catch (IncorrectOperationException e) {
Messages.showMessageDialog(getContentPane(), StringUtil.getMessage(e), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
if (LOG.isDebugEnabled()) {
LOG.debug(e);
}
}
};
ApplicationManager.getApplication().runReadAction(action);
}, IdeBundle.message("command.create.new.package"), null);
}
use of javax.swing.tree.DefaultTreeModel in project intellij-community by JetBrains.
the class ToDoTreeStructureTest method testToDo.
//todo kirillk
public void testToDo() throws Exception {
AllTodosTreeBuilder all = new AllTodosTreeBuilder(new Tree(), new DefaultTreeModel(new DefaultMutableTreeNode()), myProject);
all.init();
AbstractTreeStructure structure = all.getTreeStructure();
ProjectViewTestUtil.assertStructureEqual(structure, "Root\n" + " Summary\n" + " toDo\n" + " xmlFile.xml\n" + " Item: (12,16)\n" + " package1 toDoFileCount=2,toDoItemCount=4\n" + " package2 toDoFileCount=1,toDoItemCount=2\n" + " JavaClass.java\n" + " Item: (62,78)\n" + " Item: (145,162)\n" + " JavaClass.java\n" + " Item: (52,68)\n" + " Item: (134,151)\n" + " package3 toDoFileCount=1,toDoItemCount=2\n" + " JavaClass.java\n" + " Item: (53,69)\n" + " Item: (136,153)\n", myPrintInfo);
checkOccurrences(all, new String[] { "Item: (12,16)", "Item: (62,78)", "Item: (145,162)", "Item: (52,68)", "Item: (134,151)", "Item: (53,69)", "Item: (136,153)" });
final DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
final JTree currentFileTree = new Tree(treeModel);
CurrentFileTodosTreeBuilder builder = new CurrentFileTodosTreeBuilder(currentFileTree, treeModel, myProject);
builder.init();
builder.setFile(getSrcDirectory().findSubdirectory("package1").findFile("JavaClass.java"));
builder.updateFromRoot();
ProjectViewTestUtil.assertStructureEqual(builder.getTreeStructure(), "JavaClass.java\n" + " JavaClass.java\n" + " Item: (52,68)\n" + " Item: (134,151)\n", myPrintInfo);
Disposer.dispose(builder);
Disposer.dispose(all);
}
Aggregations