Permalink
Browse files

Selection of packages/projects by their tag:

- select a source view that produces tags (e.g., Tagged APIs) 
- add desired tags as RootScope selections
Illustrated by new "API tag selection test" View.
  • Loading branch information...
1 parent a747f9f commit 8dcd7935ecb4ec21100e3c7342f4dfdd6aa55c04 @cderoove committed Jan 24, 2013
@@ -1,5 +1,8 @@
package exapus.gui.editors.view.definition;
+import java.util.ArrayList;
+import java.util.LinkedList;
+
import exapus.model.details.GraphDetails;
import exapus.model.metrics.MetricType;
import exapus.model.view.*;
@@ -27,10 +30,13 @@
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
+import com.google.common.base.Function;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
import exapus.gui.editors.view.IViewEditorPage;
import exapus.gui.editors.view.ViewEditor;
+import exapus.gui.views.store.StoreListContentProvider;
import exapus.model.store.Store;
//todo: implement view change listener, also in other editor parts
@@ -43,6 +49,7 @@
private ViewEditor viewEditor;
private ComboViewer comboMetrics;
private ComboViewer comboGraphDetails;
+ private ComboViewer comboVWSource;
@Override
public void doSave(IProgressMonitor monitor) {
@@ -91,10 +98,37 @@ public void selectionChanged(SelectionChangedEvent event) {
Object selected = selection.getFirstElement();
if(selected instanceof Perspective) {
getView().setPerspective((Perspective)selected);
+ updateComboVWSource();
}
}
});
+ //Source view
+ Label lblSource = new Label(parent, SWT.NONE);
+ lblSource.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblSource.setText("Source:");
+
+ comboVWSource = new ComboViewer(parent, SWT.READ_ONLY);
+ comboVWSource.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+ comboVWSource.setContentProvider(ArrayContentProvider.getInstance());
+
+ comboVWSource.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ Object selected = selection.getFirstElement();
+ if(selected instanceof String) {
+ String selectedSourceName = (String) selected;
+ if(selectedSourceName.equals(getWorkspaceSourceName()))
+ getView().setSourceViewName(null);
+ else
+ getView().setSourceViewName(selectedSourceName);
+ }
+ }
+ });
+
+
+
//Renderable
Label lblRenderable = new Label(parent, SWT.NONE);
@@ -292,6 +326,7 @@ public void setFocus() {
public void updateControls() {
View view = getView();
comboVWPerspective.setSelection(new StructuredSelection(view.getPerspective()));
+ updateComboVWSource();
checkRenderable.setSelection(view.getRenderable());
tableVWAPI.setInput(Iterables.toArray(view.getAPISelections(),Object.class));
tableVWProjects.setInput(Iterables.toArray(view.getProjectSelections(),Object.class));
@@ -300,6 +335,29 @@ public void updateControls() {
}
+ private String getWorkspaceSourceName() {
+ return getView().isAPICentric() ? "Workspace Packages" : "Workspace Projects";
+ }
+
+ private ArrayList<String> viewSourceNames() {
+ ArrayList<String> elements = new ArrayList<String>();
+ View thisView = getView();
+ Perspective thisPerspective = thisView.getPerspective();
+ for(View v : Store.getCurrent().getRegisteredViews()) {
+ if(v.getPerspective().equals(thisPerspective)
+ && !v.equals(thisView))
+ elements.add(v.getName());
+ }
+ elements.add(getWorkspaceSourceName());
+ return elements;
+ }
+
+ private void updateComboVWSource() {
+ comboVWSource.setInput(viewSourceNames());
+ String sourceViewName = getView().getSourceViewName();
+ comboVWSource.setSelection(new StructuredSelection(sourceViewName == null ? getWorkspaceSourceName() : sourceViewName));
+ }
+
public void setViewEditor(ViewEditor viewEditor) {
this.viewEditor = viewEditor;
}
@@ -111,6 +111,7 @@ private void registerDebugViews() {
registerView(ViewFactory.getCurrent().testAPICentricSelectionView());
registerView(ViewFactory.getCurrent().testAPICentricSelectionView2());
registerView(ViewFactory.getCurrent().testProjectCentricSelectionView());
+ registerView(ViewFactory.getCurrent().testAPITagSelectionView());
}
private void registerCSVTagView() {
@@ -5,9 +5,12 @@
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.jface.viewers.StructuredSelection;
+
import exapus.model.details.GraphDetails;
import exapus.model.forest.FactForest;
import exapus.model.metrics.MetricType;
+import exapus.model.store.Store;
import exapus.model.view.evaluator.Evaluator;
import exapus.model.view.graphbuilder.ForestGraph;
import exapus.model.view.graphbuilder.GraphBuilder;
@@ -24,11 +27,11 @@ public View(String n, Perspective p) {
metricType = MetricType.defaultValue(getRenderable());
graphDetails = GraphDetails.defaultValue();
}
-
+
private FactForest forest = null;
private File graph = null;
-
+ private String sourceViewName = null;
private boolean renderable;
@@ -44,6 +47,16 @@ public View(String n, Perspective p) {
private String name;
+
+ public String getSourceViewName() {
+ return sourceViewName;
+ }
+
+ public void setSourceViewName(String n) {
+ sourceViewName = n;
+ makeDirty();
+ }
+
public Perspective getPerspective() {
return perspective;
}
@@ -179,6 +192,7 @@ public static View fromView(View original) {
for(Selection sel : original.getProjectSelections())
duplicate.addProjectSelection(Selection.fromSelection(sel));
duplicate.setMetricType(original.getMetricType());
+ duplicate.setSourceViewName(original.getSourceViewName());
return duplicate;
}
@@ -84,6 +84,17 @@ public View testProjectCentricSelectionView() {
view.setRenderable(false);
return view;
}
+
+
+ private static String TAGGED_API_VIEW_NAME = "Tagged APIs";
+
+ public View testAPITagSelectionView() {
+ View view = new View("API tag selection test", Perspective.API_CENTRIC);
+ view.addProjectSelection(UniversalSelection.getCurrent());
+ view.addAPISelection(new ScopedSelection(new QName("ant"), Scope.ROOT_SCOPE));
+ view.setSourceViewName(TAGGED_API_VIEW_NAME);
+ return view;
+ }
public View viewFromCSVTags(File file) throws IOException {
@@ -120,7 +131,7 @@ else if(subsincluded == 1)
}
});
- View view = new View("Tagged APIs", Perspective.API_CENTRIC);
+ View view = new View(TAGGED_API_VIEW_NAME, Perspective.API_CENTRIC);
for(Selection selection : selections) {
view.addAPISelection(selection);
}
@@ -26,11 +26,8 @@ protected APICentricEvaluator(View v) {
super(v);
}
- @Override
- public FactForest getResult() {
- return modelResult.getAPICentricForest();
- }
+ @Override
protected ICopyingForestVisitor newVisitor() {
if(Iterables.any(getView().getAPISelections(), new Predicate<Selection>() {
@Override
@@ -42,14 +39,16 @@ public boolean apply(Selection selection) {
else
return new APICentricSelectionVisitor(getView().getAPISelections(), getView().getProjectSelections());
}
-
+
+ @Override
+ protected FactForest getCompleteForest() {
+ return Store.getCurrent().getWorkspaceModel().getAPICentricForest();
+ }
+
+
@Override
- public void evaluate() {
- ICopyingForestVisitor v = newVisitor();
- InboundFactForest workspaceForest = Store.getCurrent().getWorkspaceModel().getAPICentricForest();
- FactForest forest = v.copy(workspaceForest);
- calculateMetrics(forest);
- modelResult.setAPICentricForest((InboundFactForest) forest);
+ protected void cleanResult() {
+ result = new InboundFactForest(null);
}
}
@@ -2,19 +2,25 @@
import exapus.model.forest.ExapusModel;
import exapus.model.forest.FactForest;
+import exapus.model.forest.OutboundFactForest;
import exapus.model.metrics.MetricType;
import exapus.model.stats.StatsCollectionVisitor;
+import exapus.model.store.Store;
import exapus.model.view.View;
+import exapus.model.visitors.ICopyingForestVisitor;
public abstract class Evaluator {
private View view;
- protected ExapusModel modelResult;
+
+ protected FactForest result;
- protected ExapusModel getModelResult() {
- return modelResult;
+ protected abstract void cleanResult();
+
+ public FactForest getResult() {
+ return result;
}
-
+
public static Evaluator forView(View v) {
if(v.isAPICentric())
return new APICentricEvaluator(v);
@@ -31,17 +37,33 @@ public static FactForest evaluate(View v) {
protected Evaluator(View v) {
view = v;
- modelResult = new ExapusModel();
+ cleanResult();
}
public View getView() {
return view;
}
- public abstract FactForest getResult();
+ public void evaluate() {
+ ICopyingForestVisitor v = newVisitor();
+ FactForest sourceForest = getSourceForest();
+ FactForest forest = v.copy(sourceForest);
+ calculateMetrics(forest);
+ result = forest;
+ }
- public abstract void evaluate();
+ protected abstract ICopyingForestVisitor newVisitor();
+ protected abstract FactForest getCompleteForest();
+
+ protected FactForest getSourceForest() {
+ String sourceViewName = getView().getSourceViewName();
+ if(sourceViewName == null)
+ return getCompleteForest();
+ else
+ return Store.getCurrent().getView(sourceViewName).evaluate();
+ }
+
protected void calculateMetrics(FactForest forest) {
if (getView().getMetricType() != null) {
long startTime = System.currentTimeMillis();
@@ -1,10 +1,12 @@
package exapus.model.view.evaluator;
import exapus.model.forest.FactForest;
+import exapus.model.forest.InboundFactForest;
import exapus.model.forest.OutboundFactForest;
import exapus.model.store.Store;
import exapus.model.view.View;
import exapus.model.visitors.ICopyingForestVisitor;
+import exapus.model.visitors.IForestVisitor;
import exapus.model.visitors.SelectiveTopDownCopyingForestVisitor;
public class ProjectCentricEvaluator extends Evaluator {
@@ -14,21 +16,19 @@ protected ProjectCentricEvaluator(View v) {
}
@Override
- public FactForest getResult() {
- return getModelResult().getProjectCentricForest();
- }
-
protected ICopyingForestVisitor newVisitor() {
return new ProjectCentricSelectionVisitor(getView().getProjectSelections(), getView().getAPISelections());
}
+
+
+ @Override
+ protected FactForest getCompleteForest() {
+ return Store.getCurrent().getWorkspaceModel().getProjectCentricForest();
+ }
@Override
- public void evaluate() {
- ICopyingForestVisitor v = newVisitor();
- OutboundFactForest workspaceForest = Store.getCurrent().getWorkspaceModel().getProjectCentricForest();
- FactForest forest = v.copy(workspaceForest);
- calculateMetrics(forest);
- modelResult.setProjectCentricForest((OutboundFactForest) forest);
+ protected void cleanResult() {
+ result = new OutboundFactForest(null);
}
}

0 comments on commit 8dcd793

Please sign in to comment.