error nodes support

This commit is contained in:
Konstantin Bulenkov
2011-05-03 19:25:52 +04:00
parent b1b64cdbc6
commit 2419db059d
8 changed files with 136 additions and 10 deletions
@@ -44,6 +44,7 @@ import java.util.concurrent.Callable;
*/
public abstract class DiffElement<T> implements Disposable {
public static final DiffElement[] EMPTY_ARRAY = new DiffElement[0];
public static final DiffElement ERROR_NODE = new DiffErrorElement("Can't load elements", "An error has been occurred while getting children");
private DiffPanel myDiffPanel;
private Editor myEditor;
private static final Logger LOG = Logger.getInstance(DiffElement.class.getName());
@@ -0,0 +1,97 @@
/*
* 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.
* 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 com.intellij.ide.diff;
import com.intellij.openapi.project.Project;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Icons;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.io.IOException;
/**
* @author Konstantin Bulenkov
*/
public class DiffErrorElement extends DiffElement {
private final String myMessage;
private final JTextArea myDescription;
public DiffErrorElement() {
this("Can't load children", "");
}
public DiffErrorElement(@NotNull String message, @NotNull String description) {
myMessage = message;
myDescription = new JTextArea(description);
//myDescription.setBackground(new Color(0,0,0,0));
myDescription.setEditable(false);
}
@Override
public String getPath() {
return "";
}
@NotNull
@Override
public String getName() {
return myMessage;
}
@Override
public long getSize() {
return -1;
}
@Override
public long getTimeStamp() {
return -1;
}
@Override
public boolean isContainer() {
return false;
}
@Override
public DiffElement[] getChildren() throws IOException {
return EMPTY_ARRAY;
}
@Override
public byte[] getContent() throws IOException {
return ArrayUtil.EMPTY_BYTE_ARRAY;
}
@Override
public Object getValue() {
return null;
}
@Override
public Icon getIcon() {
return Icons.ERROR_INTRODUCTION_ICON;
}
@Override
public JComponent getViewComponent(Project project, @Nullable DiffElement target) {
return myDescription;
}
}
@@ -16,6 +16,7 @@
package com.intellij.openapi.diff.impl.dir;
import com.intellij.ide.diff.DiffElement;
import com.intellij.ide.diff.DiffErrorElement;
import com.intellij.ide.diff.DirDiffSettings;
import com.intellij.util.containers.HashMap;
import com.intellij.util.containers.SortedList;
@@ -27,6 +28,8 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import static com.intellij.openapi.diff.impl.dir.DType.ERROR;
/**
* @author Konstantin Bulenkov
*/
@@ -143,7 +146,9 @@ public class DTree {
for (DTree tree : getChildren()) {
final DiffElement<?> src = tree.getSource();
final DiffElement<?> trg = tree.getTarget();
if (src == null && trg != null) {
if (src instanceof DiffErrorElement || trg instanceof DiffErrorElement) {
tree.setType(ERROR);
} else if (src == null && trg != null) {
tree.setType(DType.TARGET);
} else if (src != null && trg == null) {
tree.setType(DType.SOURCE);
@@ -172,6 +177,10 @@ public class DTree {
public void updateVisibility(DirDiffSettings settings) {
if (children.isEmpty()) {
if (type == ERROR) {
myVisible = true;
return;
}
if (type != DType.SEPARATOR && !"".equals(settings.getFilter())) {
if (!settings.getFilterPattern().matcher(getName()).matches()) {
myVisible = false;
@@ -189,6 +198,7 @@ public class DTree {
myVisible = settings.showNewOnTarget;
break;
case SEPARATOR:
case ERROR:
myVisible = true;
break;
case CHANGED:
@@ -18,4 +18,4 @@ package com.intellij.openapi.diff.impl.dir;
/**
* @author Konstantin Bulenkov
*/
public enum DType {SOURCE, TARGET, SEPARATOR, CHANGED, EQUAL}
public enum DType {SOURCE, TARGET, SEPARATOR, CHANGED, EQUAL, ERROR}
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import static com.intellij.openapi.diff.impl.dir.DirDiffOperation.*;
import static com.intellij.openapi.diff.impl.dir.DirDiffOperation.COPY_TO;
/**
* @author Konstantin Bulenkov
@@ -43,7 +43,10 @@ public class DirDiffElement {
myTarget = target;
myTargetLength = target == null || target.isContainer() ? -1 : target.getSize();
myName = name;
if (isSource()) {
if (type == DType.ERROR) {
myOperation = DirDiffOperation.NONE;
}
else if (isSource()) {
myOperation = COPY_TO;
}
else if (isTarget()) {
@@ -67,13 +70,18 @@ public class DirDiffElement {
}
private static String getLastModification(DiffElement file) {
return DateFormatUtil.formatDateTime(file.getTimeStamp());
final long timeStamp = file.getTimeStamp();
return timeStamp < 0 ? "" : DateFormatUtil.formatDateTime(timeStamp);
}
public static DirDiffElement createChange(@NotNull DiffElement source, @NotNull DiffElement target) {
return new DirDiffElement(source, target, DType.CHANGED, source.getName());
}
public static DirDiffElement createError(@Nullable DiffElement source, @Nullable DiffElement target) {
return new DirDiffElement(source, target, DType.ERROR, source == null ? target.getName() : source.getName());
}
public static DirDiffElement createSourceOnly(@NotNull DiffElement source) {
return new DirDiffElement(source, null, DType.SOURCE, null);
}
@@ -109,7 +117,7 @@ public class DirDiffElement {
@Nullable
public String getSourceName() {
return myType == DType.CHANGED || myType == DType.SOURCE || myType == DType.EQUAL
? mySource.getName() : null;
? mySource.getName() : mySource == null ? null : mySource.getName();
}
@Nullable
@@ -120,7 +128,7 @@ public class DirDiffElement {
@Nullable
public String getTargetName() {
return myType == DType.CHANGED || myType == DType.TARGET || myType == DType.EQUAL
? myTarget.getName() : null;
? myTarget.getName() : myTarget == null ? null : myTarget.getName();
}
@Nullable
@@ -26,7 +26,7 @@ import java.awt.*;
* @author Konstantin Bulenkov
*/
public enum DirDiffOperation {
COPY_TO, COPY_FROM, MERGE, EQUAL;
COPY_TO, COPY_FROM, MERGE, EQUAL, NONE;
public Icon getIcon() {
switch (this) {
@@ -34,6 +34,7 @@ public enum DirDiffOperation {
case COPY_FROM: return IconLoader.getIcon("/vcs/arrow_left.png");
case MERGE: return IconLoader.getIcon("/vcs/not_equal.png");
case EQUAL: return IconLoader.getIcon("/vcs/equal.png");
case NONE:
}
return EmptyIcon.create(16);
}
@@ -46,6 +47,7 @@ public enum DirDiffOperation {
case MERGE:
return FileStatus.COLOR_MODIFIED;
case EQUAL:
case NONE:
}
return Color.BLACK;
}
@@ -113,14 +113,20 @@ public class DirDiffPanel implements Disposable {
}
} else {
final DiffElement object = element.isSource() ? element.getSource() : element.getTarget();
final DiffElement object;
if (element.getType() == DType.ERROR) {
object = element.getSource() == null ? element.getTarget() : element.getSource();
} else {
object = element.isSource() ? element.getSource() : element.getTarget();
}
myViewComponent = object.getViewComponent(project, null);
if (myViewComponent != null) {
myCurrentElement = object;
myDiffPanel.add(myViewComponent, BorderLayout.CENTER);
DataManager.registerDataProvider(myDiffPanel, myCurrentElement.getDataProvider(project));
myViewComponent.revalidate();
myDiffPanel.revalidate();
myDiffPanel.repaint();
} else {
myDiffPanel.add(getErrorLabel(), BorderLayout.CENTER);
myDiffPanel.revalidate();
@@ -246,6 +246,8 @@ public class DirDiffTableModel extends AbstractTableModel implements Disposable
case EQUAL:
elements.add(DirDiffElement.createEqual(child.getSource(), child.getTarget()));
break;
case ERROR:
elements.add(DirDiffElement.createError(child.getSource(), child.getTarget()));
}
}
} else {