Example usage for org.eclipse.jface.viewers StructuredSelection StructuredSelection

List of usage examples for org.eclipse.jface.viewers StructuredSelection StructuredSelection

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection StructuredSelection.

Prototype

public StructuredSelection(List elements) 

Source Link

Document

Creates a structured selection from the given List.

Usage

From source file:com.bdaum.zoom.ui.internal.dialogs.TemplateEditDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite comp = (Composite) super.createDialogArea(parent);
    GridLayout layout = (GridLayout) comp.getLayout();
    layout.marginWidth = 10;/*from  w  ww. j a v a2s . c o m*/
    layout.marginHeight = 5;
    layout.verticalSpacing = 10;

    final Composite composite = new Composite(comp, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    final GridLayout gridLayout_1 = new GridLayout();
    gridLayout_1.numColumns = 2;
    composite.setLayout(gridLayout_1);
    new Label(composite, SWT.NONE).setText(Messages.TemplateEditDialog_name);
    nameField = new Text(composite, SWT.BORDER);
    nameField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    nameField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            updateButtons();
        }
    });

    new Label(composite, SWT.NONE).setText(Messages.TemplateEditDialog_template);
    templateField = new Text(composite, SWT.BORDER);
    templateField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    templateField.addVerifyListener(new VerifyListener() {
        public void verifyText(VerifyEvent e) {
            for (int i = 0; i < e.text.length(); i++)
                if (INVALIDCAHRS.indexOf(e.text.charAt(i)) >= 0) {
                    e.doit = false;
                    return;
                }
        }
    });
    templateField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            updateButtons();
            computeExample();
        }
    });
    new Label(composite, SWT.NONE).setText(Messages.TemplateEditDialog_example);
    exampleField = new Text(composite, SWT.READ_ONLY | SWT.BORDER);
    final GridData gd_exampleField = new GridData(SWT.FILL, SWT.CENTER, true, false);
    exampleField.setLayoutData(gd_exampleField);

    final Composite buttonComp = new Composite(comp, SWT.NONE);
    buttonComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    buttonComp.setLayout(gridLayout);
    final ISelectionChangedListener varListener = new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            templateField.insert(
                    selectedVar = (String) ((IStructuredSelection) event.getSelection()).getFirstElement());
            varViewer.getCombo().setVisible(false);
        }
    };
    addVariableButton = new Button(buttonComp, SWT.PUSH);
    addVariableButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    addVariableButton.setText(Messages.TemplateEditDialog_add_var);
    addVariableButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            varViewer.getCombo().setVisible(true);
            if (selectedVar != null) {
                varViewer.removeSelectionChangedListener(varListener);
                varViewer.setSelection(new StructuredSelection(selectedVar));
                varViewer.addSelectionChangedListener(varListener);
            }
        }
    });
    varViewer = new ComboViewer(buttonComp, SWT.NONE);
    Combo vcontrol = varViewer.getCombo();
    vcontrol.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    vcontrol.setVisibleItemCount(10);
    vcontrol.setVisible(false);
    varViewer.setContentProvider(ArrayContentProvider.getInstance());
    varViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof String) {
                String varName = ((String) element);
                if (varName.startsWith("{") && varName.endsWith("}")) //$NON-NLS-1$ //$NON-NLS-2$
                    return element + TemplateMessages
                            .getString(TemplateMessages.PREFIX + varName.substring(1, varName.length() - 1));
            }
            return super.getText(element);
        }
    });
    varViewer.addSelectionChangedListener(varListener);
    varViewer.setInput(variables);
    if (asset != null) {
        addMetadataButton = new Button(buttonComp, SWT.PUSH);
        addMetadataButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
        addMetadataButton.setText(Messages.TemplateEditDialog_add_metadata);
        addMetadataButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                TemplateFieldSelectionDialog dialog = new TemplateFieldSelectionDialog(getShell());
                if (dialog.open() != TemplateFieldSelectionDialog.OK)
                    return;
                FieldDescriptor fd = dialog.getResult();
                templateField.insert(Constants.TV_META + (fd.subfield == null ? fd.qfield.getId()
                        : fd.qfield.getId() + '&' + fd.subfield.getId()) + '}');
            }
        });
        new Label(buttonComp, SWT.NONE).setText(Messages.TemplateEditDialog_example_shows_metadata);
    }
    return comp;
}

From source file:com.bdaum.zoom.ui.internal.dialogs.WebGalleryEditDialog.java

License:Open Source License

private void setSelectedWebEngine(String engineId) {
    if (engineId != null && !engineId.isEmpty())
        for (IConfigurationElement generator : generators)
            if (engineId.equals(generator.getAttribute("id"))) { //$NON-NLS-1$
                engineViewer.setSelection(new StructuredSelection(generator));
                break;
            }/*  w ww .  j a v a 2  s .co m*/
}

From source file:com.bdaum.zoom.ui.internal.NavigationHistory.java

License:Open Source License

public void resetHistory() {
    previousStack.clear();//  w w w  . j  a v a  2s.  c  om
    nextStack.clear();
    selectedAssets = AssetSelection.EMPTY;
    otherSelection = StructuredSelection.EMPTY;
    fireSelection(null, new StructuredSelection(ICollectionProcessor.EMPTYCOLLECTION));
}

From source file:com.bdaum.zoom.ui.internal.NavigationHistory.java

License:Open Source License

private void restoreState(HistoryItem current) {
    if (restoring)
        return;/*from  www.  j  a  v a2s  .c o m*/
    restoring = true;
    try {
        IDbManager dbManager = Core.getCore().getDbManager();
        this.filters = current.getFilters();
        this.customSort = current.getSort();
        IdentifiableObject collection = null;
        if (current.getQuery() instanceof String) {
            collection = dbManager.obtainById(IdentifiableObject.class, (String) current.query);
        } else if (current.getQuery() instanceof IdentifiableObject) {
            collection = (IdentifiableObject) current.getQuery();
        }
        if (collection != null) {
            IWorkbenchPage activePage = window.getActivePage();
            if (activePage != null) {
                String perspectiveId = current.getPerspectiveId();
                if (perspectiveId != null) {
                    IPerspectiveDescriptor perspective = PlatformUI.getWorkbench().getPerspectiveRegistry()
                            .findPerspectiveWithId(perspectiveId);
                    if (perspective != null)
                        activePage.setPerspective(perspective);
                }
                postSelection(new StructuredSelection(collection));
                String partId = current.getActivePart();
                IViewPart view = null;
                if (partId != null) {
                    try {
                        String secondaryId = current.getSecondaryId();
                        view = secondaryId != null
                                ? activePage.showView(partId, secondaryId, IWorkbenchPage.VIEW_ACTIVATE)
                                : activePage.showView(partId);
                    } catch (PartInitException e) {
                        // ignore
                    }
                }
                if (current.isPicked()) {
                    String[] selectedIds = current.getSelectedAssets();
                    List<Asset> assets = new ArrayList<Asset>(selectedIds.length);
                    for (String id : selectedIds) {
                        Asset a = dbManager.obtainAsset(id);
                        if (a != null)
                            assets.add(a);
                    }
                    postSelection(new AssetSelection(assets));
                } else if (view instanceof SelectionActionClusterProvider)
                    ((SelectionActionClusterProvider) view).selectAll();
            }
        }
    } finally {
        restoring = false;
    }
}

From source file:com.bdaum.zoom.ui.internal.preferences.AppearancePreferencePage.java

License:Open Source License

@Override
protected void doFillValues() {
    IPreferenceStore preferenceStore = getPreferenceStore();
    theme = preferenceStore.getString(PreferenceConstants.BACKGROUNDCOLOR);
    colorViewer.setSelection(new StructuredSelection(theme));
    distViewer//from w  w  w  . j a va  2s  .  c  o  m
            .setSelection(new StructuredSelection(preferenceStore.getString(PreferenceConstants.DISTANCEUNIT)));
    dimViewer.setSelection(new StructuredSelection(preferenceStore.getString(PreferenceConstants.DIMUNIT)));
    locationButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.SHOWLOCATION));
    doneButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.SHOWDONEMARK));
    regionField.setSelection(preferenceStore.getInt(PreferenceConstants.MAXREGIONS));
    String rating = preferenceStore.getString(PreferenceConstants.SHOWRATING);
    int r = 1;
    for (int i = 0; i < ratingOptions.length; i++)
        if (ratingOptions[i].equals(rating)) {
            r = i;
            break;
        }
    showRatingGroup.setSelection(r);
    rotateButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.SHOWROTATEBUTTONS));
    voiceNoteButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.SHOWVOICENOTE));
    expandButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.SHOWEXPANDCOLLAPSE));
    labelConfigGroup.setSelection(preferenceStore.getInt(PreferenceConstants.SHOWLABEL),
            preferenceStore.getString(PreferenceConstants.THUMBNAILTEMPLATE),
            preferenceStore.getInt(PreferenceConstants.LABELFONTSIZE));
    updateButtons();
}

From source file:com.bdaum.zoom.ui.internal.preferences.AutoPreferencePage.java

License:Open Source License

@Override
protected void doFillValues() {
    IPreferenceStore preferenceStore = getPreferenceStore();
    ruleComponent.fillValues(preferenceStore.getString(PreferenceConstants.AUTORULES));
    autoButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.AUTODERIVE));
    xmpButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.APPLYXMPTODERIVATES));
    StringTokenizer st = new StringTokenizer(preferenceStore.getString(PreferenceConstants.RELATIONDETECTORS));
    while (st.hasMoreTokens()) {
        CheckboxButton button = detectorButtons.get(st.nextToken());
        if (button != null)
            button.setSelection(true);//from  ww w.j  a v a2 s .  co m
    }
    if (relviewer != null)
        relviewer.setSelection(
                new StructuredSelection(preferenceStore.getString(PreferenceConstants.DERIVERELATIONS)));
}

From source file:com.bdaum.zoom.ui.internal.preferences.ColorCodeGroup.java

License:Open Source License

@SuppressWarnings("unused")
public ColorCodeGroup(Composite autoGroup, int index, PreferencePage page) {
    this.page = page;
    new Label(autoGroup, SWT.BORDER).setImage(Icons.toSwtColors(index));
    new Label(autoGroup, SWT.NONE);
    critGroupCombo = new ComboViewer(autoGroup, SWT.READ_ONLY | SWT.BORDER);
    Combo comboControl = critGroupCombo.getCombo();
    comboControl.setVisibleItemCount(10);
    critGroupCombo.setContentProvider(ArrayContentProvider.getInstance());
    critGroupCombo.setFilters(new ViewerFilter[] { new GroupComboCatFilter() });
    critGroupCombo.setLabelProvider(new GroupComboLabelProvider());
    critGroupCombo.setInput(QueryField.getCategoriesAndSubgroups());
    critGroupCombo.setSelection(new StructuredSelection(QueryField.CATEGORY_ALL));
    comboControl.setLayoutData(new GridData(80, SWT.DEFAULT));
    critFieldCombo = new Combo(autoGroup, SWT.READ_ONLY | SWT.BORDER);
    critFieldCombo.setLayoutData(new GridData(200, SWT.DEFAULT));
    critFieldCombo.setVisibleItemCount(10);
    critRelationCombo = new Combo(autoGroup, SWT.READ_ONLY | SWT.BORDER);
    critRelationCombo.setLayoutData(new GridData(80, SWT.DEFAULT));
    valueComp = new Composite(autoGroup, SWT.NONE);
    valueComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    valueLayout = new StackLayout();
    valueComp.setLayout(valueLayout);/*w ww.j a  v  a 2s  .c  o  m*/
    enumGroup = createStackGroup(valueComp, 1);
    enumValueCombo = new Combo(enumGroup, SWT.READ_ONLY | SWT.BORDER);
    GridData data = new GridData(SWT.LEFT, SWT.CENTER, false, true);
    data.widthHint = 150;
    enumValueCombo.setLayoutData(data);
    textGroup = createStackGroup(valueComp, 1);
    textValueField = new Text(textGroup, SWT.SINGLE | SWT.BORDER);
    data = new GridData(SWT.LEFT, SWT.CENTER, false, true);
    data.widthHint = 320;
    textValueField.setLayoutData(data);
    codeGroup = createStackGroup(valueComp, 1);
    codeValueField = new CodeGroup(codeGroup, SWT.NONE, null);
    data = new GridData(SWT.LEFT, SWT.CENTER, false, true);
    data.widthHint = 150;
    codeValueField.setLayoutData(data);
    dateGroup = createStackGroup(valueComp, 1);
    dateValueField = new DateInput(dateGroup, SWT.DATE | SWT.TIME | SWT.DROP_DOWN | SWT.BORDER);
    dateValueField.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true));
    enumRangeGroup = createStackGroup(valueComp, 2);
    enumFromField = new Combo(enumRangeGroup, SWT.READ_ONLY | SWT.BORDER);
    data = new GridData(SWT.LEFT, SWT.CENTER, false, true);
    data.widthHint = 150;
    enumFromField.setLayoutData(data);
    enumToField = new Combo(enumRangeGroup, SWT.READ_ONLY | SWT.BORDER);
    data = new GridData(SWT.LEFT, SWT.CENTER, false, true);
    data.widthHint = 150;
    enumToField.setLayoutData(data);
    codeRangeGroup = createStackGroup(valueComp, 2);
    codeFromField = new CodeGroup(codeRangeGroup, SWT.NONE, null);
    data = new GridData(SWT.LEFT, SWT.CENTER, false, true);
    data.widthHint = 150;
    codeFromField.setLayoutData(data);
    codeToField = new CodeGroup(codeRangeGroup, SWT.NONE, null);
    data = new GridData(SWT.LEFT, SWT.CENTER, false, true);
    data.widthHint = 150;
    codeToField.setLayoutData(data);
    textRangeGroup = createStackGroup(valueComp, 2);
    textFromField = new Text(textRangeGroup, SWT.SINGLE | SWT.BORDER);
    textFromField.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true));
    textToField = new Text(textRangeGroup, SWT.SINGLE | SWT.BORDER);
    textToField.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true));
    dateRangeGroup = createStackGroup(valueComp, 2);
    dateFromField = new DateInput(dateRangeGroup, SWT.DATE | SWT.TIME | SWT.DROP_DOWN | SWT.BORDER);
    dateFromField.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true));
    dateToField = new DateInput(dateRangeGroup, SWT.DATE | SWT.TIME | SWT.DROP_DOWN | SWT.BORDER);
    dateToField.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true));
    undefinedGroup = createStackGroup(valueComp, 1);
    Button clearButton = new Button(autoGroup, SWT.PUSH);
    clearButton.setImage(Icons.delete.getImage());
    clearButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            crit = null;
            switchColor();
        }
    });
    critGroupCombo.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            fillFieldCombo();
            resetValues();
        }
    });
    critFieldCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            fillRelationCombo();
            resetValues();
            validate();
        }
    });
    critRelationCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            updateValueFields(crit);
            validate();
        }
    });
    fillFieldCombo();
}

From source file:com.bdaum.zoom.ui.internal.preferences.ColorCodeGroup.java

License:Open Source License

private void switchColor() {
    resetValues();/*  ww  w .  j a  va  2 s .  c  o m*/
    if (crit == null)
        crit = new CriterionImpl();
    if (crit.getField() == null || crit.getField().isEmpty()) {
        fieldDescriptor = null;
        critGroupCombo.setSelection(new StructuredSelection(QueryField.CATEGORY_ALL));
    } else {
        fieldDescriptor = new FieldDescriptor(crit);
        critGroupCombo.setSelection(new StructuredSelection(fieldDescriptor.qfield.getCategory()));
    }
    fillFieldCombo();
}

From source file:com.bdaum.zoom.ui.internal.preferences.ColorCodePage.java

License:Open Source License

@Override
public void fillValues() {
    IPreferenceStore preferenceStore = getPreferenceStore();
    colorCodeViewer.setSelection(//from w w w  . j  a va  2s .  c om
            new StructuredSelection(preferenceStore.getString(PreferenceConstants.SHOWCOLORCODE)));
    updateAutoGroup();
    String[] tokens = new String[colorCodeGroups.length];
    String s = preferenceStore.getString(PreferenceConstants.AUTOCOLORCODECRIT);
    if (s != null) {
        int i = 0;
        int off = 0;
        while (i < colorCodeGroups.length) {
            int p = s.indexOf('\n', off);
            if (p < 0)
                break;
            tokens[i++] = s.substring(off, p);
            off = p + 1;
        }
    }
    for (int i = 0; i < colorCodeGroups.length; i++)
        colorCodeGroups[i].fillValues(tokens[i]);
}

From source file:com.bdaum.zoom.ui.internal.preferences.GeneralPreferencePage.java

License:Open Source License

@Override
protected void doFillValues() {
    IPreferenceStore preferenceStore = getPreferenceStore();
    undoField.setSelection(preferenceStore.getInt(PreferenceConstants.UNDOLEVELS));
    backupField.setSelection(preferenceStore.getInt(PreferenceConstants.BACKUPINTERVAL));
    backupGenerationsField.setSelection(
            new StructuredSelection(preferenceStore.getString(PreferenceConstants.BACKUPGENERATIONS)));
    iccViewer/*from  w w  w.jav a  2 s .c  o  m*/
            .setSelection(new StructuredSelection(preferenceStore.getString(PreferenceConstants.COLORPROFILE)));
    customFile = preferenceStore.getString(PreferenceConstants.CUSTOMPROFILE);
    advancedButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.ADVANCEDGRAPHICS));
    previewButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.PREVIEW));
    noiseButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.ADDNOISE));
    enlargeButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.ENLARGESMALL));
    if (displayGroup != null) {
        String s = preferenceStore.getString(PreferenceConstants.SECONDARYMONITOR);
        displayGroup.setSelection(
                PreferenceConstants.MON_ALTERNATE.equals(s) ? 2 : Boolean.parseBoolean(s) ? 1 : 0);
    }
    inactivityField.setSelection(preferenceStore.getInt(PreferenceConstants.INACTIVITYINTERVAL));
    updateViewer
            .setSelection(new StructuredSelection(preferenceStore.getString(PreferenceConstants.UPDATEPOLICY)));
    noProgressButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.NOPROGRESS));
}