1 package org.simantics.scl.ui.imports.internal;
3 import gnu.trove.procedure.TObjectProcedure;
5 import java.util.Comparator;
7 import org.eclipse.core.runtime.CoreException;
8 import org.eclipse.core.runtime.IProgressMonitor;
9 import org.eclipse.core.runtime.IStatus;
10 import org.eclipse.core.runtime.Status;
11 import org.eclipse.jface.dialogs.IDialogSettings;
12 import org.eclipse.swt.widgets.Composite;
13 import org.eclipse.swt.widgets.Control;
14 import org.eclipse.swt.widgets.Shell;
15 import org.eclipse.ui.dialogs.FilteredItemsSelectionDialog;
16 import org.eclipse.ui.dialogs.SearchPattern;
17 import org.simantics.scl.osgi.SCLOsgi;
18 import org.simantics.scl.ui.Activator;
20 public class SCLModuleSelectionDialog extends FilteredItemsSelectionDialog {
22 private static final String SCL_MODULE_SELECTION_DIALOG = "SCL_MODULE_SELECTION_DIALOG";
24 public SCLModuleSelectionDialog(Shell shell) {
29 protected Control createExtendedContentArea(Composite parent) {
34 protected IDialogSettings getDialogSettings() {
35 IDialogSettings settings = org.simantics.scl.ui.Activator.getInstance()
36 .getDialogSettings().getSection(SCL_MODULE_SELECTION_DIALOG);
38 settings = Activator.getInstance()
39 .getDialogSettings().addNewSection(SCL_MODULE_SELECTION_DIALOG);
44 protected IStatus validateItem(Object item) {
45 return Status.OK_STATUS;
49 protected ItemsFilter createFilter() {
50 return new ItemsFilter() {
52 String patternText = getPattern();
53 patternMatcher = new SearchPattern();
54 if(patternText != null && patternText.length() > 0)
55 patternMatcher.setPattern(patternText);
57 patternMatcher.setPattern("*");
61 public boolean matchItem(Object item) {
62 if(getPattern().indexOf('/') > 0)
63 return matches((String)item);
65 for(String part : ((String)item).split("/"))
73 public boolean isConsistentItem(Object item) {
80 Comparator<String> comparator = new Comparator<String>() {
82 public int compare(String o1, String o2) {
83 return o1.compareTo(o2);
87 @SuppressWarnings("rawtypes")
89 protected Comparator getItemsComparator() {
94 protected void fillContentProvider(final AbstractContentProvider contentProvider,
95 final ItemsFilter itemsFilter, IProgressMonitor progressMonitor)
96 throws CoreException {
97 SCLOsgi.SOURCE_REPOSITORY.forAllModules(new TObjectProcedure<String>() {
99 public boolean execute(String module) {
100 contentProvider.add(module, itemsFilter);
104 if(progressMonitor != null)
105 progressMonitor.done();
109 public String getElementName(Object item) {