|
@@ -26,6 +26,8 @@ import org.eclipse.jface.viewers.ISelectionChangedListener;
|
|
|
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
|
|
import org.eclipse.jface.viewers.StructuredSelection;
|
|
|
import org.eclipse.jface.viewers.TreeViewer;
|
|
|
+import org.eclipse.jface.viewers.Viewer;
|
|
|
+import org.eclipse.jface.viewers.ViewerFilter;
|
|
|
import org.eclipse.jface.wizard.WizardPage;
|
|
|
import org.eclipse.swt.SWT;
|
|
|
import org.eclipse.swt.browser.Browser;
|
|
@@ -47,6 +49,8 @@ import org.yakindu.sct.examples.wizard.service.ExampleData;
|
|
|
import org.yakindu.sct.examples.wizard.service.ExampleWizardConstants;
|
|
|
import org.yakindu.sct.examples.wizard.service.IExampleService;
|
|
|
|
|
|
+import com.google.common.base.Predicate;
|
|
|
+import com.google.common.collect.Iterables;
|
|
|
import com.google.inject.Inject;
|
|
|
|
|
|
/**
|
|
@@ -57,7 +61,11 @@ import com.google.inject.Inject;
|
|
|
*/
|
|
|
|
|
|
public class SelectExamplePage extends WizardPage
|
|
|
- implements ExampleWizardConstants, ISelectionChangedListener, SelectionListener, IPropertyChangeListener {
|
|
|
+ implements
|
|
|
+ ExampleWizardConstants,
|
|
|
+ ISelectionChangedListener,
|
|
|
+ SelectionListener,
|
|
|
+ IPropertyChangeListener {
|
|
|
|
|
|
@Inject
|
|
|
private IExampleService exampleService;
|
|
@@ -66,6 +74,9 @@ public class SelectExamplePage extends WizardPage
|
|
|
private Browser browser;
|
|
|
private MessageArea messageArea;
|
|
|
|
|
|
+ /** ID of example to be installed */
|
|
|
+ private String exampleIdToInstall;
|
|
|
+
|
|
|
public SelectExamplePage() {
|
|
|
super(SELECT_PAGE_TITLE);
|
|
|
setTitle(SELECT_PAGE_TITLE);
|
|
@@ -91,7 +102,7 @@ public class SelectExamplePage extends WizardPage
|
|
|
container.setLayout(layout);
|
|
|
createTreeViewer(container);
|
|
|
createDetailsPane(container);
|
|
|
- container.setWeights(new int[] { 1, 2 });
|
|
|
+ container.setWeights(new int[]{1, 2});
|
|
|
setControl(container);
|
|
|
}
|
|
|
|
|
@@ -135,6 +146,10 @@ public class SelectExamplePage extends WizardPage
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private boolean revealExamplesAutomatically() {
|
|
|
+ return (exampleIdToInstall != null) && (!exampleService.exists() || !exampleService.isUpToDate(null));
|
|
|
+ }
|
|
|
+
|
|
|
private void initAsync() {
|
|
|
try {
|
|
|
getWizard().getContainer().run(true, false, new IRunnableWithProgress() {
|
|
@@ -143,6 +158,16 @@ public class SelectExamplePage extends WizardPage
|
|
|
init(monitor);
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ if (revealExamplesAutomatically()) {
|
|
|
+ Display.getCurrent().asyncExec(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ messageArea.button.setEnabled(false);
|
|
|
+ revealExamples();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
} catch (InvocationTargetException | InterruptedException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -178,12 +203,46 @@ public class SelectExamplePage extends WizardPage
|
|
|
|
|
|
protected void setInput(final IProgressMonitor monitor) {
|
|
|
final List<ExampleData> input = exampleService.getExamples(new NullProgressMonitor());
|
|
|
-
|
|
|
+
|
|
|
messageArea.hide();
|
|
|
viewer.setInput(input);
|
|
|
viewer.expandAll();
|
|
|
// explicit layouting required for Unix systems
|
|
|
viewer.getControl().getParent().getParent().layout(true);
|
|
|
+
|
|
|
+ filterAndSelectExampleToInstall(viewer, input);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void filterAndSelectExampleToInstall(TreeViewer viewer, List<ExampleData> input) {
|
|
|
+ final ExampleData exampleToInstall = Iterables.find(input, new Predicate<ExampleData>() {
|
|
|
+ @Override
|
|
|
+ public boolean apply(ExampleData input) {
|
|
|
+ if (exampleIdToInstall != null) {
|
|
|
+ return exampleIdToInstall.equals(input.getId());
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ if (exampleToInstall != null) {
|
|
|
+ viewer.addFilter(new ViewerFilter() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
|
|
|
+ if (exampleIdToInstall == null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (element instanceof ExampleData) {
|
|
|
+ return exampleIdToInstall.equals(((ExampleData) element).getId());
|
|
|
+ }
|
|
|
+ if (element instanceof ExampleContentProvider.Category) {
|
|
|
+ return ((ExampleContentProvider.Category)element).getChildren().contains(exampleToInstall);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ viewer.setSelection(new StructuredSelection(exampleToInstall), true);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
protected void createTreeViewer(Composite container) {
|
|
@@ -227,6 +286,10 @@ public class SelectExamplePage extends WizardPage
|
|
|
|
|
|
@Override
|
|
|
public void widgetSelected(SelectionEvent e) {
|
|
|
+ revealExamples();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void revealExamples() {
|
|
|
try {
|
|
|
getWizard().getContainer().run(true, true, new IRunnableWithProgress() {
|
|
|
@Override
|
|
@@ -248,13 +311,11 @@ public class SelectExamplePage extends WizardPage
|
|
|
} catch (InvocationTargetException | InterruptedException e1) {
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void widgetDefaultSelected(SelectionEvent e) {
|
|
|
widgetSelected(e);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -264,4 +325,8 @@ public class SelectExamplePage extends WizardPage
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void setInstallExampleId(String exampleId) {
|
|
|
+ this.exampleIdToInstall = exampleId;
|
|
|
+ }
|
|
|
+
|
|
|
}
|