cleanup, notnull

This commit is contained in:
Alexey Kudravtsev
2012-10-05 14:15:52 +04:00
parent c7c47b232c
commit d1e5ac7653
6 changed files with 38 additions and 18 deletions
@@ -33,7 +33,7 @@ public class FileGroup implements JDOMExternalizable {
public String myUpdateName;
public String myStatusName;
private final Map<String, String> myErrorsMap;
private final Map<String, String> myErrorsMap = new HashMap<String, String>();
private final Collection<UpdatedFile> myFiles = new ArrayList<UpdatedFile>();
public boolean mySupportsDeletion;
@@ -75,11 +75,9 @@ public class FileGroup implements JDOMExternalizable {
myCanBeAbsent = canBeAbsent;
myUpdateName = updateName;
myStatusName = statusName;
myErrorsMap = new HashMap<String, String>();
}
public FileGroup() {
myErrorsMap = new HashMap<String, String>();
}
public void addChild(FileGroup child) {
@@ -94,6 +92,7 @@ public class FileGroup implements JDOMExternalizable {
myErrorsMap.put(path, error);
}
@NotNull
public Map<String, String> getErrorsMap() {
return myErrorsMap;
}
@@ -19,6 +19,7 @@ import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.SimpleTextAttributes;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
@@ -26,7 +27,6 @@ import javax.swing.tree.DefaultTreeModel;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/**
* author: lesya
@@ -40,8 +40,8 @@ public abstract class AbstractTreeNode extends DefaultMutableTreeNode{
public void setTree(JTree tree) {
myTree = tree;
if (children == null) return;
for (Iterator each = children.iterator(); each.hasNext();) {
AbstractTreeNode node = (AbstractTreeNode) each.next();
for (Object aChildren : children) {
AbstractTreeNode node = (AbstractTreeNode)aChildren;
node.setTree(tree);
}
@@ -50,8 +50,8 @@ public abstract class AbstractTreeNode extends DefaultMutableTreeNode{
public void setTreeModel(DefaultTreeModel treeModel) {
myTreeModel = treeModel;
if (children == null) return;
for (Iterator each = children.iterator(); each.hasNext();) {
AbstractTreeNode node = (AbstractTreeNode) each.next();
for (Object aChildren : children) {
AbstractTreeNode node = (AbstractTreeNode)aChildren;
node.setTreeModel(treeModel);
}
}
@@ -76,7 +76,7 @@ public abstract class AbstractTreeNode extends DefaultMutableTreeNode{
}
public String getText(){
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
result.append(getName());
if(showStatistics()){
result.append(" (");
@@ -86,18 +86,22 @@ public abstract class AbstractTreeNode extends DefaultMutableTreeNode{
return result.toString();
}
private String getStatistics(int itemsCount){
private static String getStatistics(int itemsCount){
return VcsBundle.message("update.tree.node.size.statistics", itemsCount);
}
@NotNull
protected abstract String getName();
protected abstract int getItemsCount();
protected abstract boolean showStatistics();
@NonNls public abstract Icon getIcon(boolean expanded);
@NotNull
public abstract Collection<VirtualFile> getVirtualFiles();
@NotNull
public abstract Collection<File> getFiles();
@NotNull
public abstract SimpleTextAttributes getAttributes();
public abstract boolean getSupportsDeletion();
@@ -19,6 +19,7 @@ import com.intellij.icons.AllIcons;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.SimpleTextAttributes;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.io.File;
@@ -50,6 +51,7 @@ public class DirectoryTreeNode extends FileOrDirectoryTreeNode{
return AllIcons.Nodes.Folder;
}
@NotNull
public Collection<VirtualFile> getVirtualFiles() {
Collection<VirtualFile> result = new ArrayList<VirtualFile>();
for (int i = 0; i < getChildCount(); i++){
@@ -59,6 +61,7 @@ public class DirectoryTreeNode extends FileOrDirectoryTreeNode{
return result;
}
@NotNull
public Collection<File> getFiles() {
Collection<File> result = new ArrayList<File>();
for (int i = 0; i < getChildCount(); i++){
@@ -29,6 +29,7 @@ import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.io.File;
@@ -44,8 +45,10 @@ public abstract class FileOrDirectoryTreeNode extends AbstractTreeNode implement
protected final File myFile;
private final String myName;
protected FileOrDirectoryTreeNode(@NotNull String path, SimpleTextAttributes invalidAttributes,
Project project, String parentPath) {
protected FileOrDirectoryTreeNode(@NotNull String path,
@NotNull SimpleTextAttributes invalidAttributes,
@NotNull Project project,
@Nullable String parentPath) {
String preparedPath = path.replace(File.separatorChar, '/');
String url = VirtualFileManager.constructUrl(LocalFileSystem.getInstance().getProtocol(), preparedPath);
setUserObject(VirtualFilePointerManager.getInstance().create(url, this, this));
@@ -55,6 +58,7 @@ public abstract class FileOrDirectoryTreeNode extends AbstractTreeNode implement
myName = parentPath == null ? myFile.getAbsolutePath() : myFile.getName();
}
@NotNull
@Override
public String getName() {
return myName;
@@ -100,6 +104,7 @@ public abstract class FileOrDirectoryTreeNode extends AbstractTreeNode implement
return (VirtualFilePointer)getUserObject();
}
@NotNull
@Override
public SimpleTextAttributes getAttributes() {
if (!getFilePointer().isValid()) {
@@ -111,7 +116,8 @@ public abstract class FileOrDirectoryTreeNode extends AbstractTreeNode implement
return getAttributesFor(status);
}
private static SimpleTextAttributes getAttributesFor(FileStatus status) {
@NotNull
private static SimpleTextAttributes getAttributesFor(@NotNull FileStatus status) {
Color color = status.getColor();
if (color == null) color = Color.black;
@@ -35,11 +35,14 @@ public class FileTreeNode extends FileOrDirectoryTreeNode {
private static final Collection<VirtualFile> EMPTY_VIRTUAL_FILE_ARRAY = new ArrayList<VirtualFile>();
public FileTreeNode(@NotNull String path, SimpleTextAttributes invalidAttributes,
Project project, String parentPath) {
public FileTreeNode(@NotNull String path,
@NotNull SimpleTextAttributes invalidAttributes,
@NotNull Project project,
String parentPath) {
super(path, invalidAttributes, project, parentPath);
}
@Override
public Icon getIcon(boolean expanded) {
if (myFile.isDirectory()) {
return PlatformIcons.DIRECTORY_CLOSED_ICON;
@@ -47,25 +50,29 @@ public class FileTreeNode extends FileOrDirectoryTreeNode {
return FileTypeManager.getInstance().getFileTypeByFileName(myFile.getName()).getIcon();
}
@NotNull
@Override
public Collection<VirtualFile> getVirtualFiles() {
VirtualFile virtualFile = getFilePointer().getFile();
if (virtualFile == null) return EMPTY_VIRTUAL_FILE_ARRAY;
return Collections.singleton(virtualFile);
}
@NotNull
@Override
public Collection<File> getFiles() {
if (getFilePointer().getFile() == null) {
return Collections.singleton(myFile);
}
else {
return EMPTY_FILE_ARRAY;
}
return EMPTY_FILE_ARRAY;
}
@Override
protected int getItemsCount() {
return 1;
}
@Override
protected boolean showStatistics() {
return false;
}
@@ -58,6 +58,7 @@ public class UpdateRootNode extends GroupTreeNode {
return group;
}
@Override
public boolean getSupportsDeletion() {
return false;
}