summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-07-22 17:25:30 (EDT)
committerSteffen Pingel2011-07-22 17:25:30 (EDT)
commit3e2527656eb7b6d90d7aa708eff7c3cfab4a1ff1 (patch)
tree6052db35eda5d17a9bc1ef0923681a61ef82a385
parentd369857e0835a0a3d5bf6d7d99d5cfef09975de7 (diff)
downloadorg.eclipse.mylyn.builds-3e2527656eb7b6d90d7aa708eff7c3cfab4a1ff1.zip
org.eclipse.mylyn.builds-3e2527656eb7b6d90d7aa708eff7c3cfab4a1ff1.tar.gz
org.eclipse.mylyn.builds-3e2527656eb7b6d90d7aa708eff7c3cfab4a1ff1.tar.bz2
NEW - bug 352916: [patch] Show artifact hierarchy in build editor
https://bugs.eclipse.org/bugs/show_bug.cgi?id=352916
-rw-r--r--org.eclipse.mylyn.builds.ui/src/org/eclipse/mylyn/internal/builds/ui/editor/ArtifactsPart.java87
1 files changed, 80 insertions, 7 deletions
diff --git a/org.eclipse.mylyn.builds.ui/src/org/eclipse/mylyn/internal/builds/ui/editor/ArtifactsPart.java b/org.eclipse.mylyn.builds.ui/src/org/eclipse/mylyn/internal/builds/ui/editor/ArtifactsPart.java
index 31547a1..a3c6d8a 100644
--- a/org.eclipse.mylyn.builds.ui/src/org/eclipse/mylyn/internal/builds/ui/editor/ArtifactsPart.java
+++ b/org.eclipse.mylyn.builds.ui/src/org/eclipse/mylyn/internal/builds/ui/editor/ArtifactsPart.java
@@ -7,15 +7,22 @@
*
* Contributors:
* Tasktop Technologies - initial API and implementation
+ * GitHub - fixes for bug 352916
*******************************************************************************/
package org.eclipse.mylyn.internal.builds.ui.editor;
+import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider;
import org.eclipse.jface.viewers.IOpenListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -25,8 +32,10 @@ import org.eclipse.jface.viewers.OpenEvent;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.mylyn.builds.core.IArtifact;
import org.eclipse.mylyn.builds.core.IBuild;
+import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
import org.eclipse.mylyn.internal.provisional.commons.ui.WorkbenchUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
@@ -38,16 +47,17 @@ import org.eclipse.ui.forms.widgets.FormToolkit;
/**
* @author Steffen Pingel
+ * @author Kevin Sawicki
*/
public class ArtifactsPart extends AbstractBuildEditorPart {
static class ArtifactFolder {
- List<IArtifact> artifacts = new ArrayList<IArtifact>();
+ final Map<String, ArtifactFolder> folders = new HashMap<String, ArtifactFolder>();
- List<ArtifactFolder> folders = new ArrayList<ArtifactsPart.ArtifactFolder>();
+ final List<IArtifact> artifacts = new ArrayList<IArtifact>();
- String name;
+ final String name;
public ArtifactFolder(String name) {
this.name = name;
@@ -56,7 +66,7 @@ public class ArtifactsPart extends AbstractBuildEditorPart {
protected Object[] getChildren() {
List<Object> all = new ArrayList<Object>(artifacts.size() + folders.size());
all.addAll(artifacts);
- all.addAll(folders);
+ all.addAll(folders.values());
return all.toArray();
}
@@ -65,10 +75,33 @@ public class ArtifactsPart extends AbstractBuildEditorPart {
}
public String getName() {
- // ignore
- return null;
+ return name;
+ }
+
+ ArtifactFolder add(String path, IArtifact artifact) {
+ int slash = path.indexOf('/');
+ if (slash > 0 && slash + 1 < path.length()) {
+ String name = path.substring(0, slash);
+ ArtifactFolder folder = folders.get(name);
+ if (folder == null) {
+ folder = new ArtifactFolder(name);
+ folders.put(name, folder);
+ }
+ path = path.substring(slash + 1);
+ folder.add(path, artifact);
+ } else {
+ artifacts.add(artifact);
+ }
+ return this;
}
+ public ArtifactFolder add(IArtifact artifact) {
+ return add(artifact.getRelativePath(), artifact);
+ }
+
+ public String toString() {
+ return name;
+ }
}
static class ArtifactsContentProvider implements ITreeContentProvider {
@@ -136,6 +169,7 @@ public class ArtifactsPart extends AbstractBuildEditorPart {
composite.setLayout(new GridLayout(1, false));
viewer = new TreeViewer(toolkit.createTree(composite, SWT.NONE));
+ viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
GridDataFactory.fillDefaults().hint(300, 100).grab(true, true).applyTo(viewer.getControl());
viewer.setContentProvider(new ArtifactsContentProvider());
viewer.setLabelProvider(new DecoratingStyledCellLabelProvider(new ArtifactsLabelProvider(), null, null));
@@ -155,6 +189,29 @@ public class ArtifactsPart extends AbstractBuildEditorPart {
}
}
});
+ viewer.setSorter(new ViewerSorter() {
+
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ String name1 = null;
+ String name2 = null;
+ if (e1 instanceof IArtifact) {
+ name1 = ((IArtifact) e1).getName();
+ } else if (e1 instanceof ArtifactFolder) {
+ name1 = ((ArtifactFolder) e1).getName();
+ }
+ if (e2 instanceof IArtifact) {
+ name2 = ((IArtifact) e2).getName();
+ } else if (e1 instanceof ArtifactFolder) {
+ name2 = ((ArtifactFolder) e2).getName();
+ }
+ if (name1 != null && name2 != null) {
+ return name1.compareToIgnoreCase(name2);
+ }
+ return super.compare(viewer, e1, e2);
+ }
+
+ });
menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
@@ -169,14 +226,30 @@ public class ArtifactsPart extends AbstractBuildEditorPart {
viewer.setInput("No artifacts.");
}
+ final int numArtifacts = getInput(IBuild.class).getArtifacts().size();
+ getSection().setText(MessageFormat.format("Artifacts ({0})", numArtifacts));
+
toolkit.paintBordersFor(composite);
return composite;
}
private ArtifactFolder getRootFolder() {
ArtifactFolder root = new ArtifactFolder("Root");
- root.artifacts.addAll(getInput(IBuild.class).getArtifacts());
+ for (IArtifact artifact : getInput(IBuild.class).getArtifacts()) {
+ root.add(artifact);
+ }
return root;
}
+ @Override
+ protected void fillToolBar(ToolBarManager toolBarManager) {
+ super.fillToolBar(toolBarManager);
+
+ toolBarManager.add(new Action("Collapse All", CommonImages.COLLAPSE_ALL) {
+
+ public void run() {
+ viewer.collapseAll();
+ }
+ });
+ }
}