/** @return create dialog result object basing on the dialog state */ private Result createResult() { Result rc = new Result(); String name = myNameTextField.getText().trim(); if (myTarget == null) { rc.target = myConfig.createConfiguration(name); } else { rc.target = myTarget; rc.target.setName(name); } rc.changes = new ArrayList<Change>(myChangesTree.getIncludedChanges()); for (BranchDescriptor d : myBranches) { if (d.root != null) { if (!StringUtil.isEmpty(d.newBranchName)) { final String ref = d.referenceToCheckout.trim(); rc.referencesToUse.put(d.root, Pair.create(ref, d.referencesToSelect.contains(ref))); rc.target.setReference(d.root.getPath(), d.newBranchName.trim()); rc.checkoutNeeded.add(d.root); } else { String ref = d.referenceToCheckout.trim(); if (!d.referencesToSelect.contains(ref)) { ref = myConfig.detectTag(d.root, ref); } rc.target.setReference(d.root.getPath(), ref); if (!d.referenceToCheckout.equals(d.currentReference)) { rc.checkoutNeeded.add(d.root); } } } } return rc; }
/** * The constructor * * @param project the project * @param target the target configuration * @param allChanges the all changes * @param roots the collection of roots * @param remoteBranch the remote branch * @param config the configuration * @param isModify the modify flag * @throws VcsException if there is a problem with detecting the current state */ protected SwitchBranchesDialog( Project project, final BranchConfiguration target, final List<Change> allChanges, List<VirtualFile> roots, String remoteBranch, final BranchConfigurations config, boolean isModify) throws VcsException { super(project, true); setTitle(isModify ? "Modify Branch Configuration" : "Checkout Branch Configuration"); assert (remoteBranch == null) || (target == null) : "There should be no target for remote branch"; myTarget = target; myConfig = config; myModify = isModify; myProject = project; VirtualFile baseDir = project.getBaseDir(); myBaseFile = baseDir == null ? null : new File(baseDir.getPath()); myExistingConfigNames = myConfig.getConfigurationNames(); myChangesTree = new ChangesTreeList<Change>( myProject, Collections.<Change>emptyList(), !myModify, true, null, RemoteRevisionsCache.getInstance(project).getChangesNodeDecorator()) { protected DefaultTreeModel buildTreeModel( final List<Change> changes, ChangeNodeDecorator changeNodeDecorator) { TreeModelBuilder builder = new TreeModelBuilder(myProject, false); return builder.buildModel(changes, changeNodeDecorator); } protected List<Change> getSelectedObjects(final ChangesBrowserNode<Change> node) { return node.getAllChangesUnder(); } @Nullable protected Change getLeadSelectedObject(final ChangesBrowserNode node) { final Object o = node.getUserObject(); if (o instanceof Change) { return (Change) o; } return null; } }; if (remoteBranch != null) { myBranches = prepareBranchesForRemote(remoteBranch, roots); } else { myBranches = prepareBranchDescriptors(target, roots); } Collections.sort( myBranches, new Comparator<BranchDescriptor>() { @Override public int compare(BranchDescriptor o1, BranchDescriptor o2) { return o1.getRoot().compareTo(o2.getRoot()); } }); if (target == null) { myNameTextField.setText(generateNewConfigurationName()); } else { myNameTextField.setText(target.getName()); } myChangesTree.setChangesToDisplay(allChanges); myChangesTree.setIncludedChanges(Collections.<Change>emptyList()); myChangesPanel.add(myChangesTree, BorderLayout.CENTER); myChangesLabel.setLabelFor(myChangesTree); if (myModify) { myChangesLabel.setText("Changes in the current configuration"); } RootTableModel tableModel = new RootTableModel(); myBranchesTable.setModel(tableModel); myBranchesTable.setDefaultRenderer(Pair.class, new PairTableRenderer()); final TableColumnModel columns = myBranchesTable.getColumnModel(); final PairTableRenderer renderer = new PairTableRenderer(); for (Enumeration<TableColumn> cs = columns.getColumns(); cs.hasMoreElements(); ) { cs.nextElement().setCellRenderer(renderer); } TableColumn revisionColumn = columns.getColumn(RootTableModel.REVISION_COLUMN); revisionColumn.setCellEditor(new ReferenceEditor()); TableColumn branchColumn = columns.getColumn(RootTableModel.NEW_BRANCH_COLUMN); branchColumn.setCellEditor(new BranchNameEditor()); myNameTextField .getDocument() .addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { verify(); } }); tableModel.addTableModelListener( new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { verify(); } }); verify(); init(); }