Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SelectionDialog's "Name" text box autocompletes based on the selection;s

scope (e.g., with method names for METHOD_SCOPE).
  • Loading branch information...
commit 2a07c89797cbf15dc1131200dece933a67bc5d34 1 parent 59aad03
Coen De Roover authored
4 ExapusRAP/src/exapus/gui/editors/forest/tree/ForestTreeContentProvider.java
View
@@ -62,11 +62,11 @@ private void addListenerTo(Observable newInput) {
//TODO: getChildren() should be implemented on ForestElement, preferably in a thread-safe manner
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof PackageTree)
- return Iterables.toArray(((PackageTree) parentElement).getLayers(), PackageLayer.class);
+ return Iterables.toArray(((PackageTree) parentElement).getPackageLayers(), PackageLayer.class);
if (parentElement instanceof PackageLayer) {
PackageLayer layer = (PackageLayer) parentElement;
Iterable<Member> members = layer.getMembers();
- Iterable<PackageLayer> layers = layer.getLayers();
+ Iterable<PackageLayer> layers = layer.getPackageLayers();
return Iterables.toArray(Iterables.concat(members, layers), MemberContainer.class);
}
if (parentElement instanceof Member) {
4 ExapusRAP/src/exapus/gui/editors/forest/tree/ForestTreeGroupedPackagesContentProvider.java
View
@@ -15,7 +15,7 @@
List<MemberContainer> packages = new ArrayList<MemberContainer>();
for (PackageTree packageTree : ((FactForest) inputElement).getPackageTrees()) {
- for (PackageLayer packageLayer : packageTree.getLayers()) {
+ for (PackageLayer packageLayer : packageTree.getPackageLayers()) {
addToResult(packages, packageLayer);
}
}
@@ -30,7 +30,7 @@ private void addToResult(List<MemberContainer> packages, PackageLayer layer) {
packages.add(layer);
}
- for (PackageLayer nextLayer : layer.getLayers()) {
+ for (PackageLayer nextLayer : layer.getPackageLayers()) {
addToResult(packages, nextLayer);
}
}
119 ExapusRAP/src/exapus/gui/editors/view/definition/SelectionDialog.java
View
@@ -1,7 +1,13 @@
package exapus.gui.editors.view.definition;
+import java.util.Collections;
+
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.fieldassist.ContentProposalAdapter;
+import org.eclipse.jface.fieldassist.IContentProposalProvider;
+import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
+import org.eclipse.jface.fieldassist.TextContentAdapter;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -20,7 +26,17 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+import exapus.model.forest.ExapusModel;
+import exapus.model.forest.FactForest;
+import exapus.model.forest.ForestElement;
+import exapus.model.forest.Member;
import exapus.model.forest.QName;
+import exapus.model.store.Store;
+import exapus.model.view.View;
import exapus.model.view.Perspective;
import exapus.model.view.Scope;
import exapus.model.view.ScopedSelection;
@@ -37,14 +53,18 @@
private Selection selection;
private Text scopedSelectionTagText;
+
+ private String sourceViewName;
public Selection getSelection() {
return selection;
}
- public SelectionDialog(Shell parentShell, Perspective perspective) {
+ public SelectionDialog(Shell parentShell, Perspective perspective, String sourceViewName) {
super(parentShell);
this.perspective = perspective;
+ this.sourceViewName = sourceViewName;
+
}
//adapted from RAP controls demo
@@ -121,6 +141,18 @@ public void selectionChanged(SelectionChangedEvent event) {
scopedSelectionNameText = new Text(scopedSelectionComposite, SWT.BORDER);
scopedSelectionNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,1,1));
+ final SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(getProposalStrings());
+ ContentProposalAdapter adapter = new ContentProposalAdapter(scopedSelectionNameText, new TextContentAdapter(), proposalProvider, null, null);
+ adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
+
+ scopedSelectionScopeComboVW.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ proposalProvider.setProposals(getProposalStrings());
+
+ }
+ });
+
Label tagLabel = new Label(scopedSelectionComposite, SWT.NONE);
tagLabel.setText("Tag:");
tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
@@ -129,6 +161,52 @@ public void selectionChanged(SelectionChangedEvent event) {
return composite;
}
+
+ private FactForest getProposalFactForest() {
+ if(sourceViewName != null && Store.getCurrent().hasRegisteredView(sourceViewName)) {
+ View sourceView = Store.getCurrent().getView(sourceViewName);
+ if(sourceView.getPerspective().equals(perspective))
+ return sourceView.evaluate();
+ }
+ ExapusModel workspaceModel = Store.getCurrent().getWorkspaceModel();
+ return perspective.equals(Perspective.API_CENTRIC) ? workspaceModel.getAPICentricForest() : workspaceModel.getProjectCentricForest();
+ }
+
+ private Iterable<? extends ForestElement> getProposalForestElements() {
+ Scope selectedScope = getSelectedScope();
+ if(selectedScope == null)
+ return Collections.emptyList();
+ FactForest forest = getProposalFactForest();
+ if(selectedScope.equals(Scope.ROOT_SCOPE))
+ return forest.getPackageTrees();
+ if(selectedScope.equals(Scope.PACKAGE_SCOPE))
+ return forest.getAllPackageLayers();
+ if(selectedScope.equals(Scope.TYPE_SCOPE))
+ return Iterables.filter(forest.getAllMembers(),new Predicate<Member>() {
+ @Override
+ public boolean apply(Member m) {
+ return m.getElement().declaresType();
+ }
+ });
+ if(selectedScope.equals(Scope.METHOD_SCOPE))
+ return Iterables.filter(forest.getAllMembers(),new Predicate<Member>() {
+ @Override
+ public boolean apply(Member m) {
+ return m.getElement().isMethod();
+ }
+ });
+ if(selectedScope.equals(Scope.PREFIX_SCOPE))
+ return forest.getAllPackageLayers();
+ return Collections.emptyList();
+ }
+
+ private String[] getProposalStrings() {
+ return Iterables.toArray(Iterables.transform(getProposalForestElements(), new Function<ForestElement, String>() {
+ public String apply(ForestElement e) {
+ return e.getQName().toString();
+ }
+ }),String.class);
+ }
protected void createButtonsForButtonBar(final Composite parent) {
createButton(parent, IDialogConstants.CANCEL_ID, "Cancel", false);
@@ -146,31 +224,50 @@ protected void buttonPressed(final int buttonId) {
super.buttonPressed(buttonId);
}
- private void updateSelection() {
- selection = null;
+ @SuppressWarnings("unchecked")
+ private Class<Selection> getSelectedType() {
IStructuredSelection selType = (IStructuredSelection) selectionTypeComboVW.getSelection();
if(selType.isEmpty())
+ return null;
+ return (Class<Selection>) selType.getFirstElement();
+ }
+
+
+ @SuppressWarnings("unused")
+ private Scope getSelectedScope() {
+ Class<Selection> selectedType = getSelectedType();
+ if(selectedType == null || UniversalSelection.class.equals(selectedType))
+ return null;
+ IStructuredSelection selScope = (IStructuredSelection) scopedSelectionScopeComboVW.getSelection();
+ if(selScope.isEmpty())
+ return null;
+ return (Scope) selScope.getFirstElement();
+ }
+
+
+ private void updateSelection() {
+ selection = null;
+ Class<Selection> selectedType = getSelectedType();
+ if(selectedType == null)
return;
- Object selectedType = selType.getFirstElement();
if(selectedType.equals(UniversalSelection.class)) {
selection = UniversalSelection.getCurrent();
return;
}
-
if(selectedType.equals(ScopedSelection.class)) {
- QName name = new QName(scopedSelectionNameText.getText());
- IStructuredSelection selScope = (IStructuredSelection) scopedSelectionScopeComboVW.getSelection();
- if(selScope.isEmpty())
+ Scope selectedScope = getSelectedScope();
+ if(selectedScope == null)
return;
- selection = new ScopedSelection(name, (Scope) selScope.getFirstElement());
+ QName name = new QName(scopedSelectionNameText.getText());
+ selection = new ScopedSelection(name, selectedScope);
+
String scopedSelectionTag = scopedSelectionTagText.getText().trim();
if(!scopedSelectionTag.isEmpty())
((ScopedSelection) selection).setTag(scopedSelectionTag);
return;
}
-
-
}
+
}
25 ExapusRAP/src/exapus/gui/editors/view/definition/ViewDefinitionEditor.java
View
@@ -191,16 +191,17 @@ public void selectionChanged(SelectionChangedEvent event) {
lblRenderable.setLayoutData(gd_lblRenderable);
checkRenderable = new Button(parent, SWT.CHECK);
+ checkRenderable.setSelection(getView().getRenderable());
+
GridData gd_checkRenderable = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
checkRenderable.setLayoutData(gd_checkRenderable);
checkRenderable.setText("Render as graph.");
-
+
checkRenderable.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
getView().setRenderable(checkRenderable.getSelection());
- comboMetrics.setInput(MetricType.supportedMetrics(checkRenderable.getSelection()));
- comboMetrics.setSelection(new StructuredSelection(MetricType.defaultValue(checkRenderable.getSelection())));
+ updateComboMetrics();
}
@Override
@@ -208,9 +209,11 @@ public void widgetDefaultSelected(SelectionEvent e) {
}
});
+
comboVWPerspective.setInput(Perspective.supportedPerspectives());
comboGraphDetails.setInput(GraphDetails.supportedDetails());
- comboMetrics.setInput(MetricType.supportedMetrics(checkRenderable.getSelection()));
+ //TODO: jka
+ //comboMetrics.setInput(MetricType.supportedMetrics(checkRenderable.getSelection()));
}
@@ -302,7 +305,7 @@ public void selectionChanged(SelectionChangedEvent event) {
}
protected void showSelectionDialog(Perspective perspective) {
- SelectionDialog selectionDialog = new SelectionDialog(getSite().getShell(), perspective);
+ SelectionDialog selectionDialog = new SelectionDialog(getSite().getShell(), perspective, getView().getSourceViewName());
int returnCode = selectionDialog.open();
if(returnCode == IDialogConstants.OK_ID) {
Selection newSelection = selectionDialog.getSelection();
@@ -328,13 +331,13 @@ public void setFocus() {
public void updateControls() {
View view = getView();
+ checkRenderable.setSelection(view.getRenderable());
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));
- comboMetrics.setSelection(new StructuredSelection(view.getMetricType()));
- comboGraphDetails.setSelection(new StructuredSelection(view.getGraphDetails()));
+ updateComboMetrics();
+ comboGraphDetails.setSelection(new StructuredSelection(view.getGraphDetails()));
enableControls(!getView().sealed());
}
@@ -372,6 +375,12 @@ private void updateComboVWSource() {
String sourceViewName = getView().getSourceViewName();
comboVWSource.setSelection(new StructuredSelection(sourceViewName == null ? getWorkspaceSourceName() : sourceViewName));
}
+
+ private void updateComboMetrics() {
+ comboMetrics.setInput(MetricType.supportedMetrics(getView().getRenderable()));
+ //TODO: Kate, is is the case that a View's (previously set) metric type is always among the combo's elements?
+ comboMetrics.setSelection(new StructuredSelection(getView().getMetricType()));
+ }
public void setViewEditor(ViewEditor viewEditor) {
this.viewEditor = viewEditor;
Please sign in to comment.
Something went wrong with that request. Please try again.