Generify, fix spelling

This commit is contained in:
Bas Leijdekkers
2011-08-19 10:48:54 +02:00
parent 981f8c85af
commit 653c18cf45
7 changed files with 58 additions and 93 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -21,12 +21,10 @@ import com.intellij.cvsSupport2.actions.cvsContext.CvsLightweightFile;
import com.intellij.cvsSupport2.application.CvsEntriesManager;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
@@ -37,13 +35,12 @@ public class CvsActionVisibility {
private boolean myCanBePerformedOnFile = true;
private boolean myCanBePerformedOnDirectory = true;
private boolean myCanBePerformedOnSeveralFiles = false;
private final boolean myExpectedCvsAsActiveVcs = true;
private final List myConditions = new ArrayList();
private final List<Condition> myConditions = new ArrayList();
private boolean myCanBePerformedOnLocallyDeletedFile = false;
private boolean myCanBePerformedOnCvsLightweightFile = false;
public static interface Condition{
public interface Condition{
boolean isPerformedOn(CvsContext context);
}
@@ -51,18 +48,11 @@ public class CvsActionVisibility {
myConditions.add(condition);
}
public boolean isVisible(CvsContext context){
if (!myExpectedCvsAsActiveVcs) return true;
return context.cvsIsActive();
}
public boolean isEnabled(CvsContext context){
boolean result = (context.cvsIsActive() || !myExpectedCvsAsActiveVcs)
&& hasSuitableType(context);
private boolean isEnabled(CvsContext context){
boolean result = context.cvsIsActive() && hasSuitableType(context);
if (!result) return false;
for (Iterator each = myConditions.iterator(); each.hasNext();) {
Condition condition = (Condition) each.next();
for (Condition condition : myConditions) {
if (!condition.isPerformedOn(context)) return false;
}
return true;
@@ -107,40 +97,35 @@ public class CvsActionVisibility {
}
private boolean containsFileFromUnsupportedFileSystem(VirtualFile[] selectedFiles) {
for (int i = 0; i < selectedFiles.length; i++) {
VirtualFile selectedFile = selectedFiles[i];
for (VirtualFile selectedFile : selectedFiles) {
if (!selectedFile.isInLocalFileSystem()) return true;
}
return false;
}
private boolean containsFile(VirtualFile[] selectedFiles) {
for (int i = 0; i < selectedFiles.length; i++) {
VirtualFile selectedFile = selectedFiles[i];
for (VirtualFile selectedFile : selectedFiles) {
if (!selectedFile.isDirectory()) return true;
}
return false;
}
private boolean containsDirectory(VirtualFile[] selectedFiles) {
for (int i = 0; i < selectedFiles.length; i++) {
VirtualFile selectedFile = selectedFiles[i];
for (VirtualFile selectedFile : selectedFiles) {
if (selectedFile.isDirectory()) return true;
}
return false;
}
private boolean containsDirectory(File[] selectedFiles) {
for (int i = 0; i < selectedFiles.length; i++) {
File selectedFile = selectedFiles[i];
for (File selectedFile : selectedFiles) {
if (selectedFile.isDirectory()) return true;
}
return false;
}
private boolean containsFile(File[] selectedFiles) {
for (int i = 0; i < selectedFiles.length; i++) {
File selectedFile = selectedFiles[i];
for (File selectedFile : selectedFiles) {
if (selectedFile.isFile()) return true;
}
return false;
@@ -160,12 +145,10 @@ public class CvsActionVisibility {
CvsContext cvsContext = CvsContextWrapper.createInstance(e);
Presentation presentation = e.getPresentation();
presentation.setEnabled(isEnabled(cvsContext));
presentation.setVisible(isVisible(cvsContext));
presentation.setVisible(cvsContext.cvsIsActive());
}
public void canBePerformedOnCvsLightweightFile() {
myCanBePerformedOnCvsLightweightFile = true;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -20,7 +20,6 @@ import com.intellij.openapi.components.ServiceManager;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
/**
* author: lesya
@@ -48,8 +47,7 @@ public class ImportConfiguration extends AbstractConfiguration {
return result;
String[] wrappers = KEYWORD_SUBSTITUTION_WRAPPERS.split(";");
for (int i = 0; i < wrappers.length; i++) {
String wrapper = wrappers[i];
for (String wrapper : wrappers) {
String[] extAndSubstitution = wrapper.split(" ");
if (extAndSubstitution.length != 2) continue;
result.add(new FileExtension(extAndSubstitution[0], extAndSubstitution[1]));
@@ -57,10 +55,9 @@ public class ImportConfiguration extends AbstractConfiguration {
return result;
}
public void setExtensions(List items) {
StringBuffer buffer = new StringBuffer();
for (Iterator iterator = items.iterator(); iterator.hasNext();) {
FileExtension extension = (FileExtension)iterator.next();
public void setExtensions(List<FileExtension> items) {
StringBuilder buffer = new StringBuilder();
for (FileExtension extension : items) {
buffer.append(extension.getExtension());
buffer.append(" ");
buffer.append(extension.getKeywordSubstitution().getSubstitution().toString());
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -15,8 +15,8 @@
*/
package com.intellij.cvsSupport2.config.ui;
import com.intellij.CvsBundle;
import com.intellij.cvsSupport2.config.CvsRootConfiguration;
import com.intellij.cvsSupport2.config.ui.SelectCvsConfgurationPanel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
@@ -28,11 +28,11 @@ import java.util.Observer;
* author: lesya
*/
public class SelectCvsConfigurationDialog extends DialogWrapper {
private final SelectCvsConfgurationPanel myPanel;
private final SelectCvsConfigurationPanel myPanel;
public SelectCvsConfigurationDialog(Project project) {
super(true);
myPanel = new SelectCvsConfgurationPanel(project);
myPanel = new SelectCvsConfigurationPanel(project);
setOKActionEnabled(myPanel.getSelectedConfiguration() != null);
myPanel.getObservable().addObserver(new Observer() {
@@ -40,7 +40,7 @@ public class SelectCvsConfigurationDialog extends DialogWrapper {
setOKActionEnabled(myPanel.getSelectedConfiguration() != null);
}
});
setTitle(com.intellij.CvsBundle.message("dialog.title.select.cvs.root.configuration"));
setTitle(CvsBundle.message("dialog.title.select.cvs.root.configuration"));
init();
}
@@ -56,6 +56,4 @@ public class SelectCvsConfigurationDialog extends DialogWrapper {
public CvsRootConfiguration getSelectedConfiguration() {
return myPanel.getSelectedConfiguration();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -15,6 +15,7 @@
*/
package com.intellij.cvsSupport2.config.ui;
import com.intellij.CvsBundle;
import com.intellij.cvsSupport2.config.CvsApplicationLevelConfiguration;
import com.intellij.cvsSupport2.config.CvsRootConfiguration;
import com.intellij.openapi.project.Project;
@@ -28,20 +29,20 @@ import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Observable;
/**
* author: lesya
*/
public class SelectCvsConfgurationPanel extends JPanel {
public class SelectCvsConfigurationPanel extends JPanel {
private final DefaultListModel myModel = new DefaultListModel();
private final JList myList = new JBList(myModel);
private CvsRootConfiguration mySelection;
private final Project myProject;
private final MyObservable myObservable;
public SelectCvsConfgurationPanel(Project project) {
public SelectCvsConfigurationPanel(Project project) {
super(new BorderLayout(2, 4));
myProject = project;
add(createListPanel(), BorderLayout.CENTER);
@@ -58,13 +59,11 @@ public class SelectCvsConfgurationPanel extends JPanel {
myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
fillModel(null);
}
private Component createButtonPanel() {
JPanel result = new JPanel(new BorderLayout());
JButton jButton = new JButton(com.intellij.CvsBundle.message("button.text.configure.cvs.roots"));
JButton jButton = new JButton(CvsBundle.message("button.text.configure.cvs.roots"));
jButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editConfigurations();
@@ -83,44 +82,35 @@ public class SelectCvsConfgurationPanel extends JPanel {
}
public void editConfigurations() {
final CvsApplicationLevelConfiguration configuration = CvsApplicationLevelConfiguration.getInstance();
CvsConfigurationsListEditor cvsConfigurationsListEditor =
new CvsConfigurationsListEditor(new ArrayList<CvsRootConfiguration>(getConfigurationList()), myProject);
new CvsConfigurationsListEditor(new ArrayList<CvsRootConfiguration>(configuration.CONFIGURATIONS), myProject);
CvsRootConfiguration selectedConfiguration = getSelectedConfiguration();
if (selectedConfiguration != null) {
cvsConfigurationsListEditor.selectConfiguration(selectedConfiguration);
}
cvsConfigurationsListEditor.show();
if (cvsConfigurationsListEditor.isOK()) {
getConfiguration().CONFIGURATIONS =
new ArrayList<CvsRootConfiguration>(cvsConfigurationsListEditor.getConfigurations());
configuration.CONFIGURATIONS =
new ArrayList<CvsRootConfiguration>(cvsConfigurationsListEditor.getConfigurations());
fillModel(cvsConfigurationsListEditor.getSelectedConfiguration());
}
}
private void fillModel(Object selectedConfiguration) {
Object oldSelection = selectedConfiguration == null ? myList.getSelectedValue() : selectedConfiguration;
Object selection = selectedConfiguration == null ? myList.getSelectedValue() : selectedConfiguration;
myModel.removeAllElements();
java.util.List configurations = getConfigurationList();
for (Iterator each = configurations.iterator(); each.hasNext();) {
CvsRootConfiguration configuration = (CvsRootConfiguration)each.next();
List<CvsRootConfiguration> configurations = CvsApplicationLevelConfiguration.getInstance().CONFIGURATIONS;
for (CvsRootConfiguration configuration : configurations) {
myModel.addElement(configuration);
}
myList.setSelectedValue(oldSelection, true);
myList.setSelectedValue(selection, true);
if (myList.getSelectedIndex() < 0 && myList.getModel().getSize() > 0) {
myList.setSelectedIndex(0);
}
}
private java.util.List<CvsRootConfiguration> getConfigurationList() {
return getConfiguration().CONFIGURATIONS;
}
private CvsApplicationLevelConfiguration getConfiguration() {
return CvsApplicationLevelConfiguration.getInstance();
}
public CvsRootConfiguration getSelectedConfiguration() {
return mySelection;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -15,11 +15,8 @@
*/
package com.intellij.cvsSupport2.cvsoperations.cvsErrors;
import com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesAdapter;
import com.intellij.cvsSupport2.errorHandling.CvsException;
import com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesAdapter;
import com.intellij.cvsSupport2.cvsoperations.cvsErrors.ErrorProcessor;
import com.intellij.cvsSupport2.cvsoperations.cvsErrors.ErrorProcessor;
import com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesAdapter;
import com.intellij.cvsSupport2.util.CvsVfsUtil;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFile;
@@ -32,7 +29,6 @@ public class ErrorMessagesProcessor extends CvsMessagesAdapter implements ErrorP
private final List<VcsException> myErrors;
private final List<VcsException> myWarnings;
public ErrorMessagesProcessor(List<VcsException> errors) {
myErrors = errors;
myWarnings = new ArrayList<VcsException>();
@@ -43,7 +39,6 @@ public class ErrorMessagesProcessor extends CvsMessagesAdapter implements ErrorP
}
public void addError(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot) {
addErrorOnCurrentMessage(relativeFilePath, message, cvsFileSystem, myErrors, cvsRoot);
}
@@ -51,17 +46,18 @@ public class ErrorMessagesProcessor extends CvsMessagesAdapter implements ErrorP
addErrorOnCurrentMessage(relativeFilePath, message, cvsFileSystem, myWarnings, cvsRoot);
}
private void addErrorOnCurrentMessage(String relativeFileName,
String message,
ICvsFileSystem cvsFileSystem,
List collection, String cvsRoot) {
private static void addErrorOnCurrentMessage(String relativeFileName,
String message,
ICvsFileSystem cvsFileSystem,
List<VcsException> collection,
String cvsRoot) {
VirtualFile vFile = getVirtualFile(cvsFileSystem, relativeFileName);
VcsException vcsException = new CvsException(message, cvsRoot);
if (vFile != null) vcsException.setVirtualFile(vFile);
collection.add(vcsException);
}
private VirtualFile getVirtualFile(ICvsFileSystem cvsFileSystem, String relativeFileName) {
private static VirtualFile getVirtualFile(ICvsFileSystem cvsFileSystem, String relativeFileName) {
if (cvsFileSystem == null) return null;
if (relativeFileName == null) return null;
return CvsVfsUtil.findFileByIoFile(cvsFileSystem.getLocalFileSystem().getFile(relativeFileName));
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -26,5 +26,5 @@ public interface ErrorProcessor {
void addError(VcsException ex);
void addWarning(VcsException ex);
List getErrors();
List<VcsException> getErrors();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -15,8 +15,9 @@
*/
package com.intellij.cvsSupport2.ui.experts;
import com.intellij.CvsBundle;
import com.intellij.cvsSupport2.config.CvsRootConfiguration;
import com.intellij.cvsSupport2.config.ui.SelectCvsConfgurationPanel;
import com.intellij.cvsSupport2.config.ui.SelectCvsConfigurationPanel;
import com.intellij.openapi.project.Project;
import javax.swing.*;
@@ -28,28 +29,28 @@ import java.util.Observer;
* author: lesya
*/
public class SelectCVSConfigurationStep extends WizardStep{
private final SelectCvsConfgurationPanel mySelectCvsConfgurationPanel;
private final SelectCvsConfigurationPanel mySelectCvsConfigurationPanel;
private final Observer myObserver;
public SelectCVSConfigurationStep(Project project, CvsWizard wizard) {
super(com.intellij.CvsBundle.message("dialog.title.select.cvs.configuration"), wizard);
mySelectCvsConfgurationPanel = new SelectCvsConfgurationPanel(project);
super(CvsBundle.message("dialog.title.select.cvs.configuration"), wizard);
mySelectCvsConfigurationPanel = new SelectCvsConfigurationPanel(project);
myObserver = new Observer() {
public void update(Observable o, Object arg) {
getWizard().updateStep();
}
};
mySelectCvsConfgurationPanel.getObservable().addObserver(myObserver);
mySelectCvsConfigurationPanel.getObservable().addObserver(myObserver);
init();
}
protected void dispose() {
mySelectCvsConfgurationPanel.getObservable().deleteObserver(myObserver);
mySelectCvsConfigurationPanel.getObservable().deleteObserver(myObserver);
}
public boolean nextIsEnabled() {
return mySelectCvsConfgurationPanel.getSelectedConfiguration() != null;
return mySelectCvsConfigurationPanel.getSelectedConfiguration() != null;
}
public boolean setActive() {
@@ -58,17 +59,17 @@ public class SelectCVSConfigurationStep extends WizardStep{
protected JComponent createComponent() {
JPanel result = new JPanel(new BorderLayout());
result.add(mySelectCvsConfgurationPanel, BorderLayout.CENTER);
result.add(mySelectCvsConfigurationPanel, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new BorderLayout());
result.add(buttonPanel, BorderLayout.SOUTH);
return result;
}
public CvsRootConfiguration getSelectedConfiguration() {
return mySelectCvsConfgurationPanel.getSelectedConfiguration();
return mySelectCvsConfigurationPanel.getSelectedConfiguration();
}
public Component getPreferredFocusedComponent() {
return mySelectCvsConfgurationPanel.getJList();
return mySelectCvsConfigurationPanel.getJList();
}
}