From a591891ed0b2e3fb150ff05bd600c0f8dacd7d55 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Fri, 14 Dec 2012 17:18:27 +0400 Subject: [PATCH] [git] remove unused classes. --- .../git4idea/ui/GitRefspecAddRefsDialog.form | 77 --- .../git4idea/ui/GitRefspecAddRefsDialog.java | 340 --------- .../src/git4idea/ui/GitRefspecPanel.form | 125 ---- .../src/git4idea/ui/GitRefspecPanel.java | 652 ------------------ 4 files changed, 1194 deletions(-) delete mode 100644 plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.form delete mode 100644 plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.java delete mode 100644 plugins/git4idea/src/git4idea/ui/GitRefspecPanel.form delete mode 100644 plugins/git4idea/src/git4idea/ui/GitRefspecPanel.java diff --git a/plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.form b/plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.form deleted file mode 100644 index d198315c4e9e..000000000000 --- a/plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.form +++ /dev/null @@ -1,77 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.java b/plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.java deleted file mode 100644 index 5d1c3a77a341..000000000000 --- a/plugins/git4idea/src/git4idea/ui/GitRefspecAddRefsDialog.java +++ /dev/null @@ -1,340 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package git4idea.ui; - -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.CheckboxTree; -import com.intellij.ui.CheckedTreeNode; -import com.intellij.ui.ColoredTreeCellRenderer; -import com.intellij.ui.SimpleTextAttributes; -import com.intellij.ui.treeStructure.Tree; -import com.intellij.util.PlatformIcons; -import com.intellij.util.ui.tree.TreeUtil; -import git4idea.GitBranch; -import git4idea.GitTag; -import git4idea.commands.GitCommand; -import git4idea.commands.GitHandlerUtil; -import git4idea.commands.GitSimpleHandler; -import git4idea.i18n.GitBundle; -import git4idea.util.StringScanner; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.HashSet; -import java.util.SortedSet; -import java.util.TreeSet; - -/** - * This dialog allows adding selected tag and branches are references. - */ -public class GitRefspecAddRefsDialog extends DialogWrapper { - /** - * Get references button - */ - private JButton myGetRefsButton; - /** - * If selected, the branches are fetched by {@link #myGetRefsButton} - */ - private JCheckBox myIncludeBranchesCheckBox; - /** - * If selected, the tags are fetched by {@link #myGetRefsButton} - */ - private JCheckBox myIncludeTagsCheckBox; - /** - * The selector for tags and branches - */ - private CheckboxTree myReferenceChooser; - /** - * The root panel of the dialog - */ - private JPanel myPanel; - /** - * The context project - */ - private final Project myProject; - /** - * Root of the tree - */ - private CheckedTreeNode myTreeRoot; - /** - * The git root of the repository - */ - private final VirtualFile myRoot; - /** - * The name of the remote - */ - private final String myRemote; - /** - * The set of tags - */ - private final SortedSet myTags; - /** - * The set of branches - */ - private final SortedSet myBranches; - /** - * The logger for the class - */ - private static final Logger log = Logger.getInstance(GitRefspecAddRefsDialog.class.getName()); - - /** - * A constructor - * - * @param project the project - * @param root the git repository root - * @param remote the remote name or url of remote repository - * @param tags the set of tags (might be modified if update button is pressed) - * @param branches the set of branches (might be modified if update button is pressed) - */ - protected GitRefspecAddRefsDialog(@NotNull Project project, - @NotNull VirtualFile root, - @NotNull String remote, - @NotNull SortedSet tags, - @NotNull SortedSet branches) { - super(project, true); - setTitle(GitBundle.getString("addrefspec.title")); - setOKButtonText(GitBundle.getString("addrefspec.button")); - myProject = project; - myRoot = root; - myRemote = remote; - myTags = tags; - myBranches = branches; - updateTree(); - setupGetReferences(); - init(); - setOKActionEnabled(false); - } - - - /** - * Set up action listener for {@link #myGetRefsButton} - */ - private void setupGetReferences() { - // setup enabled state - final ActionListener enabledListener = new ActionListener() { - public void actionPerformed(final ActionEvent e) { - myGetRefsButton.setEnabled(myIncludeBranchesCheckBox.isSelected() || myIncludeTagsCheckBox.isSelected()); - } - }; - myIncludeBranchesCheckBox.addActionListener(enabledListener); - myIncludeTagsCheckBox.addActionListener(enabledListener); - // perform update - myGetRefsButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - GitSimpleHandler handler = new GitSimpleHandler(myProject, myRoot, GitCommand.LS_REMOTE); - if (myIncludeBranchesCheckBox.isSelected()) { - handler.addParameters("--heads"); - myBranches.clear(); - } - if (myIncludeTagsCheckBox.isSelected()) { - handler.addParameters("--tags"); - myTags.clear(); - } - handler.addParameters(myRemote); - String result = GitHandlerUtil - .doSynchronously(handler, GitBundle.message("addrefspec.getting.references.title", myRemote), handler.printableCommandLine()); - if (result != null) { - StringScanner s = new StringScanner(result); - while (s.hasMoreData()) { - s.tabToken(); // skip last commit hash - String ref = s.line(); - if (ref.startsWith(GitBranch.REFS_HEADS_PREFIX)) { - myBranches.add(ref); - } - else if (ref.startsWith(GitTag.REFS_TAGS_PREFIX)) { - myTags.add(ref); - } - else { - log.warn("Unknwon reference type from ls-remote \"" + myRemote + "\" :" + ref); - } - } - } - updateTree(); - } - }); - } - - /** - * Update checkbox tree basing on the current state of the tag and branches set. The checkbox state is preserved. New items are created - * in unselected state. - */ - private void updateTree() { - // save the previous selection - HashSet oldTags = new HashSet(); - HashSet oldBranches = new HashSet(); - for (Reference ref : myReferenceChooser.getCheckedNodes(Reference.class, null)) { - (ref.isTag ? oldTags : oldBranches).add(ref.name); - } - // clear the tree - myTreeRoot.removeAllChildren(); - // fill tags and branches - addReferences(false, oldBranches, myBranches, GitBundle.getString("addrefspec.node.branches")); - addReferences(true, oldTags, myTags, GitBundle.getString("addrefspec.node.tags")); - TreeUtil.expandAll(myReferenceChooser); - myReferenceChooser.treeDidChange(); - } - - /** - * Add references to the tree along with category node - * - * @param isTag if true tag nodes are added - * @param old the set of old elements (used to select - * @param current the current set of elements (after update) - * @param name the name of the set - */ - private void addReferences(final boolean isTag, final HashSet old, final SortedSet current, @Nls final String name) { - if (!current.isEmpty()) { - final CheckedTreeNode tagsRoot = new CheckedTreeNode(name); - for (String t : current) { - final CheckedTreeNode node = new CheckedTreeNode(new Reference(isTag, t)); - node.setChecked(old.contains(t)); - tagsRoot.add(node); - } - myTreeRoot.add(tagsRoot); - } - } - - /** - * {@inheritDoc} - */ - @Override - protected String getDimensionServiceKey() { - return GitRefspecAddRefsDialog.class.getName(); - } - - /** - * {@inheritDoc} - */ - protected JComponent createCenterPanel() { - return myPanel; - } - - /** - * Create UI components that require custom creation: {@link #myReferenceChooser} - */ - private void createUIComponents() { - myTreeRoot = new CheckedTreeNode(""); - myReferenceChooser = new CheckboxTree(new CheckboxTree.CheckboxTreeCellRenderer() { - - public void customizeRenderer(final JTree tree, - final Object value, - final boolean selected, - final boolean expanded, - final boolean leaf, - final int row, - final boolean hasFocus) { - if (!(value instanceof CheckedTreeNode)) return; - final CheckedTreeNode node = (CheckedTreeNode)value; - final Object userObject = node.getUserObject(); - String text; - SimpleTextAttributes attributes; - Icon icon; - if (userObject == null) { - // invisible root (do nothing) - //noinspection HardCodedStringLiteral - text = "INVISBLE ROOT"; - attributes = SimpleTextAttributes.ERROR_ATTRIBUTES; - icon = null; - } - else if (userObject instanceof String) { - // category node (render as bold) - text = (String)userObject; - attributes = SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES; - icon = PlatformIcons.DIRECTORY_CLOSED_ICON; - } - else { - // reference node - text = ((Reference)userObject).name; - attributes = node.isChecked() ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES; - icon = null; - } - final ColoredTreeCellRenderer textRenderer = getTextRenderer(); - if (icon != null) { - textRenderer.setIcon(icon); - } - if (text != null) { - textRenderer.append(text, attributes); - } - } - }, myTreeRoot) { - @Override - protected void onNodeStateChanged(final CheckedTreeNode node) { - boolean flag = node.isChecked() || myReferenceChooser.getCheckedNodes(Reference.class, null).length != 0; - setOKActionEnabled(flag); - super.onNodeStateChanged(node); - } - }; - } - - /** - * Get selected elements - * - * @param isTag if true tags are returned, heads otherwise - * @return a collection of selected reference of the specified type - */ - public SortedSet getSelected(final boolean isTag) { - TreeSet rc = new TreeSet(); - final Reference[] checked = myReferenceChooser.getCheckedNodes(Reference.class, new Tree.NodeFilter() { - public boolean accept(final Reference node) { - return node.isTag == isTag; - } - }); - for (Reference r : checked) { - rc.add(r.name); - } - return rc; - } - - /** - * {@inheritDoc} - */ - @Override - protected String getHelpId() { - return "reference.VersionControl.Git.Fetch.AddReference"; - } - - - /** - * A remote reference - */ - static final class Reference { - /** - * If true, the name represents a tag. if false, the name represents the branch name. - */ - final boolean isTag; - /** - * Name of the reference - */ - final String name; - - /** - * A constructor from fields - * - * @param tag the value for {@link #isTag} - * @param name the value for {@link #name} - */ - public Reference(final boolean tag, final String name) { - isTag = tag; - this.name = name; - } - } -} diff --git a/plugins/git4idea/src/git4idea/ui/GitRefspecPanel.form b/plugins/git4idea/src/git4idea/ui/GitRefspecPanel.form deleted file mode 100644 index 51c901871e04..000000000000 --- a/plugins/git4idea/src/git4idea/ui/GitRefspecPanel.form +++ /dev/null @@ -1,125 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/git4idea/src/git4idea/ui/GitRefspecPanel.java b/plugins/git4idea/src/git4idea/ui/GitRefspecPanel.java deleted file mode 100644 index 52b128b0b3c0..000000000000 --- a/plugins/git4idea/src/git4idea/ui/GitRefspecPanel.java +++ /dev/null @@ -1,652 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package git4idea.ui; - -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.DocumentAdapter; -import com.intellij.util.containers.HashMap; -import git4idea.GitBranch; -import git4idea.GitDeprecatedRemote; -import git4idea.GitTag; -import git4idea.util.GitUIUtil; -import git4idea.util.StringScanner; -import git4idea.i18n.GitBundle; -import git4idea.validators.GitBranchNameValidator; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import javax.swing.event.DocumentEvent; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.table.AbstractTableModel; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.SortedSet; -import java.util.TreeSet; - -/** - * The component that allows specifying a list of references - */ -public class GitRefspecPanel extends JPanel { - /** - * The logger for the class - */ - private static final Logger log = Logger.getInstance(Logger.class.getName()); - /** - * Named remotes associated with the current git root - */ - private final HashMap myRemotes = new HashMap(); - /** - * The project - */ - private Project myProject; - /** - * The git root for mapping - */ - private VirtualFile myGitRoot; - /** - * Remote heads (for Add... dialog) - */ - private final SortedSet myRemoteHeads = new TreeSet(); - /** - * Remote tags (for Add.. dialog) - */ - private final SortedSet myRemoteTags = new TreeSet(); - /** - * The button that adds all branches button - */ - private JButton myAddAllBranchesButton; - /** - * The button that adds selected references - */ - private JButton myAddButton; - /** - * The button that removes currently selected entries from the table - */ - private JButton myRemoveButton; - /** - * The text that contains remote name - */ - private JTextField myRemoteNameTextField; - /** - * The root panel of the form - */ - private JPanel myPanel; - /** - * The references table - */ - private JTable myReferences; - /** - * The button that adds entry that maps all tags - */ - private JButton myAddAllTagsButton; - /** - * Restore default mapping button - */ - private JButton myDefaultButton; - /** - * The name of the remote - */ - private String myRemote; - /** - * The source of default references - */ - private ReferenceSource myReferenceSource; - /** - * Mapping table model - */ - private final MyMappingTableModel myReferencesModel = new MyMappingTableModel(); - - /** - * A constructor - */ - public GitRefspecPanel() { - super(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - c.weightx = 1; - c.weighty = 1; - c.fill = GridBagConstraints.BOTH; - add(myPanel, c); - setupTable(); - setupButtons(); - } - - - /** - * Validates fields - * - * @return null if there is no error; empty string means that there is no error yet but OK should be disabled; otherwise error text should be used as the current error for dialog - */ - @Nullable - public String validateFields() { - final String remote = getRemoteName(); - if (remote.length() == 0) { - if (myReferencesModel.isRemoteNameUsed()) { - return GitBundle.getString("refspec.validation.remote.is.blank"); - } - } - else { - if (!GitBranchNameValidator.INSTANCE.checkInput(remote)) { - return GitBundle.getString("refspec.validation.remote.invalid"); - } - } - return null; - } - - /** - * Set project for panel - * - * @param project the context project - */ - public void setProject(Project project) { - myProject = project; - } - - /** - * Setup add/remove buttons - */ - private void setupButtons() { - // disable ok button if nothing is selected - myReferences.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - public void valueChanged(final ListSelectionEvent e) { - myRemoveButton.setEnabled(myReferences.getSelectedRowCount() != 0); - } - }); - // remove selected mappings - myRemoveButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - myReferencesModel.removeSelectedMapping(); - } - }); - // add all tags (mapped to tags directory) - myAddAllTagsButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - myReferencesModel.addMapping(false, tagName("*"), tagName("*")); - } - }); - // all heads (mapped to remotes directory) - myAddAllBranchesButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - addAllBranches(); - } - }); - // map selected tags and heads - myAddButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - if (myGitRoot == null) { - throw new IllegalStateException("Git root must be already set at this point."); - } - GitRefspecAddRefsDialog d = new GitRefspecAddRefsDialog(myProject, myGitRoot, myRemote, myRemoteTags, myRemoteHeads); - d.show(); - if (!d.isOK()) { - return; - } - for (String tag : d.getSelected(true)) { - myReferencesModel.addMapping(false, tag, tag); - } - for (String head : d.getSelected(false)) { - myReferencesModel.addMapping(true, head, remoteName(head.substring(GitBranch.REFS_HEADS_PREFIX.length()))); - } - } - }); - myDefaultButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - String remote = myRemote; - setRemote(null); - setRemote(remote); - } - }); - } - - /** - * Add mapping for all branches - */ - private void addAllBranches() { - myReferencesModel.addMapping(false, headName("*"), remoteName("*")); - } - - - /** - * Generate tag with remote name - * - * @param remoteName the name of remote in the local system - * @param tagName the name of the tag - * @return the full path to the head - */ - private static String tagRemoteName(final String remoteName, final String tagName) { - return GitTag.REFS_TAGS_PREFIX + remoteName + "/" + tagName; - } - - /** - * Simple tag name - * - * @param tagName the short name of tag - * @return the fully qualified tag reference name - */ - private static String tagName(final String tagName) { - return GitTag.REFS_TAGS_PREFIX + tagName; - } - - /** - * Generate remote head name in local file system, note that as name of remote {@link #getRemoteName()} is used. - * - * @param headName the name head of remote in the local system - * @return the full path to the head - */ - private String remoteName(final String headName) { - return remoteName(getRemoteName(), headName); - } - - /** - * Generate remote name in local file system - * - * @param remote a remote name, if blank a local branch is returned. - * @param headName the name head of remote in the local system - * @return the full path to the head - */ - private static String remoteName(final String remote, final String headName) { - return remote.length() != 0 ? GitBranch.REFS_REMOTES_PREFIX + remote + "/" + headName : headName(headName); - } - - /** - * Generate head name - * - * @param head the head name - * @return the full path to the head - */ - private static String headName(final String head) { - return GitBranch.REFS_HEADS_PREFIX + head; - } - - /** - * @return the current name of the remote - */ - public String getRemoteName() { - return myRemoteNameTextField.getText(); - } - - /** - * Setup table header and table model - */ - private void setupTable() { - // setup model - myReferences.setModel(myReferencesModel); - myReferences.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - myReferences.getColumnModel().getColumn(MyMappingTableModel.FORCE_COLUMN).sizeWidthToFit(); - myRemoteNameTextField.getDocument().addDocumentListener(new DocumentAdapter() { - protected void textChanged(final DocumentEvent e) { - myReferencesModel.remoteUpdated(); - } - }); - } - - /** - * Set git root for reference mapping - * - * @param gitRoot a git root - */ - public void setGitRoot(final VirtualFile gitRoot) { - if (Comparing.equal(gitRoot, myGitRoot)) { - return; - } - myGitRoot = gitRoot; - myRemotes.clear(); - if (myGitRoot != null) { - try { - for (GitDeprecatedRemote r : GitDeprecatedRemote.list(myProject, myGitRoot)) { - myRemotes.put(r.name(), r); - } - } - catch (VcsException e) { - GitUIUtil.showOperationError(myProject, e, "listing remotes"); - } - } - } - - /** - * Set remote or url - * - * @param name a name of remote or URL - */ - public void setRemote(String name) { - if (name != null && name.length() == 0) { - name = null; - } - if (myRemote == null && name == null || myRemote != null && myRemote.equals(name)) { - return; - } - myRemote = name; - myAddButton.setEnabled(myRemote != null && myRemote.length() != 0); - final GitDeprecatedRemote remote = myRemotes.get(name); - if (remote != null) { - myRemoteNameTextField.setText(name); - myRemoteNameTextField.setEditable(false); - myDefaultButton.setEnabled(true); - } - else { - myRemoteNameTextField.setText(""); - myRemoteNameTextField.setEditable(true); - myDefaultButton.setEnabled(false); - } - myRemoteHeads.clear(); - myRemoteTags.clear(); - setDefaultMapping(); - } - - /** - * Set default mapping - */ - private void setDefaultMapping() { - final GitDeprecatedRemote remote = myRemotes.get(myRemote); - myReferencesModel.clear(); - if (remote != null && myReferenceSource == ReferenceSource.FETCH) { - try { - for (String ref : GitDeprecatedRemote.getFetchSpecs(myProject, myGitRoot, remote.name())) { - StringScanner s = new StringScanner(ref); - boolean force = s.tryConsume('+'); - String remotePart = s.boundedToken(':'); - String localPart = s.line(); - myReferencesModel.addMapping(force, remotePart, localPart); - } - } - catch (VcsException e) { - log.error("Failed to get fetch references ", e); - } - } - else { - addAllBranches(); - } - } - - /** - * Add listener that is fired when validation is required - * - * @param l a listener to add - */ - public void addValidationRequiredListener(final ActionListener l) { - myRemoteNameTextField.getDocument().addDocumentListener(new DocumentAdapter() { - protected void textChanged(final DocumentEvent e) { - //noinspection HardCodedStringLiteral - l.actionPerformed(new ActionEvent(myRemoteNameTextField, ActionEvent.ACTION_PERFORMED, "validationRequired")); - } - }); - } - - /** - * Set default reference source for panel. - * - * @param referenceSource a reference source - */ - public void setReferenceSource(final ReferenceSource referenceSource) { - myReferenceSource = referenceSource; - } - - /** - * @return references added to the model - */ - public String[] getReferences() { - return myReferencesModel.getReferences(); - } - - /** - * Mapping table model - */ - private class MyMappingTableModel extends AbstractTableModel { - /** - * Force column in the table - */ - private static final int FORCE_COLUMN = 0; - /** - * Remote reference column in the table - */ - private static final int REMOTE_COLUMN = 1; - /** - * Local reference column in the table - */ - private static final int LOCAL_COLUMN = 2; - /** - * Remote name used for the table update - */ - private String mySavedRemoteName = null; - /** - * The currently constructed mapping - */ - private final ArrayList myMapping = new ArrayList(); - - /** - * {@inheritDoc} - */ - public int getRowCount() { - return myMapping.size(); - } - - /** - * Remove currently selected mappings - */ - public void removeSelectedMapping() { - final int[] rows = myReferences.getSelectedRows(); - Arrays.sort(rows); - for (int i = rows.length - 1; i >= 0; i--) { - myMapping.remove(rows[i]); - } - fireTableDataChanged(); - } - - /** - * {@inheritDoc} - */ - public int getColumnCount() { - return LOCAL_COLUMN + 1; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isCellEditable(final int rowIndex, final int columnIndex) { - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public void setValueAt(final Object aValue, final int rowIndex, final int columnIndex) { - RefMapping m = myMapping.get(rowIndex); - switch (columnIndex) { - case FORCE_COLUMN: - m.force = ((Boolean)aValue).booleanValue(); - break; - case LOCAL_COLUMN: - m.local = (String)aValue; - break; - case REMOTE_COLUMN: - m.remote = (String)aValue; - break; - default: - throw new IllegalStateException("Invalid column: " + columnIndex); - } - } - - /** - * {@inheritDoc} - */ - @Override - public String getColumnName(final int column) { - switch (column) { - case FORCE_COLUMN: - return GitBundle.getString("refspec.column.force"); - case LOCAL_COLUMN: - return GitBundle.getString("refspec.column.local"); - case REMOTE_COLUMN: - return GitBundle.getString("refspec.column.remote"); - default: - throw new IllegalStateException("Invalid column: " + column); - } - } - - /** - * {@inheritDoc} - */ - public Object getValueAt(final int rowIndex, final int columnIndex) { - RefMapping m = myMapping.get(rowIndex); - switch (columnIndex) { - case FORCE_COLUMN: - return m.force; - case LOCAL_COLUMN: - return m.local; - case REMOTE_COLUMN: - return m.remote; - default: - throw new IllegalStateException("Invalid column: " + columnIndex); - } - } - - /** - * Add mapping - * - * @param force a force flag - * @param remote a remote reference - * @param local a local reference - */ - public void addMapping(final boolean force, @NonNls final String remote, @NonNls final String local) { - final RefMapping m = new RefMapping(); - m.force = force; - m.remote = remote; - m.local = local; - int row = myMapping.size(); - myMapping.add(m); - fireTableRowsInserted(row, row); - if (mySavedRemoteName == null) { - remoteUpdated(); - } - } - - /** - * This method updates all local heads in the table with remote name - */ - private void remoteUpdated() { - String newText = myRemoteNameTextField.getText(); - if (mySavedRemoteName != null && !newText.equals(mySavedRemoteName)) { - @NonNls String oldTagsPrefix = tagRemoteName(mySavedRemoteName, ""); - @NonNls String newTagsPrefix = tagRemoteName(newText, ""); - @NonNls String oldHeadsPrefix = remoteName(mySavedRemoteName, ""); - @NonNls String newHeadsPrefix = remoteName(newText, ""); - for (RefMapping m : myMapping) { - if (m.local.startsWith(oldTagsPrefix)) { - m.local = newTagsPrefix + m.local.substring(oldTagsPrefix.length()); - } - else if (m.local.startsWith(oldHeadsPrefix)) { - m.local = newHeadsPrefix + m.local.substring(oldHeadsPrefix.length()); - } - } - fireTableDataChanged(); - } - mySavedRemoteName = newText; - } - - @Override - public Class getColumnClass(final int columnIndex) { - if (columnIndex == FORCE_COLUMN) { - return Boolean.class; - } - return super.getColumnClass(columnIndex); - } - - /** - * @return true if remote name is actually used in the entries - */ - boolean isRemoteNameUsed() { - String text = myRemoteNameTextField.getText(); - @NonNls String tagsPrefix = tagRemoteName(text, ""); - for (RefMapping m : myMapping) { - if (m.local.startsWith(tagsPrefix)) { - return true; - } - } - return false; - } - - /** - * Clear the mapping - */ - public void clear() { - myMapping.clear(); - fireTableDataChanged(); - } - - /** - * @return a list of references - */ - public String[] getReferences() { - final int n = myMapping.size(); - String[] rc = new String[n]; - for (int i = 0; i < n; i++) { - rc[i] = myMapping.get(i).toString(); - } - return rc; - } - - /** - * Reference mapping object used in the table model - */ - class RefMapping { - /** - * if true update is forced - */ - boolean force; - /** - * remote reference name - */ - String remote; - /** - * local reference name - */ - String local; - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return (force ? "+" : "") + remote + ":" + local; - } - } - } - - /** - * The source of default references - */ - public enum ReferenceSource { - /** - * The references are pulled from fetch specification - */ - FETCH, - /** - * The references are pulled from push specification - */ - PUSH, } -}