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.MediaDialog.java

License:Open Source License

private void fillValues() {
    viewer.setInput(mediaList);// ww  w  .  j a  va2  s  .  c  o m
    if (key != null)
        for (LastDeviceImport lastDeviceImport : mediaList)
            if (key.equals(lastDeviceImport.getVolume())) {
                viewer.setSelection(new StructuredSelection(lastDeviceImport));
                break;
            }
}

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

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite area = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(area, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    composite.setLayout(new GridLayout(1, false));
    CGroup fileGroup = new CGroup(composite, SWT.NONE);
    fileGroup.setText(Messages.MigrateDialog_save_as);
    fileGroup.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, true));
    fileGroup.setLayout(new GridLayout());
    String filename = catFile.getName();
    String migrated = "migrated_" + filename; //$NON-NLS-1$
    String parentFile = catFile.getParent();
    File migratedFile = new File(parentFile, migrated);
    fileEditor = new FileEditor(fileGroup, SWT.SAVE, "", false, //$NON-NLS-1$
            new String[] { "*" + BatchConstants.CATEXTENSION }, //$NON-NLS-1$
            new String[] { "ZoRaPD Catalog (*" //$NON-NLS-1$
                    + BatchConstants.CATEXTENSION + ")" }, //$NON-NLS-1$
            parentFile, migratedFile.getPath(), false, getDialogSettings(UiActivator.getDefault(), SETTINGSID));
    CGroup tableGroup = new CGroup(composite, SWT.NONE);
    tableGroup.setText(Messages.MigrateDialog_transformation);
    tableGroup.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, true));
    tableGroup.setLayout(new GridLayout());
    new Label(tableGroup, SWT.NONE).setText(Messages.MigrateDialog_file_separator_policy);
    fileSeparatorCombo = new Combo(tableGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    fileSeparatorCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    fileSeparatorCombo.setItems(new String[] { Messages.MigrateDialog_do_nothing,
            Messages.MigrateDialog_toSlash, Messages.MigrateDialog_toBackslash });
    fileSeparatorCombo.select(fileSepearatorPolicy);
    new Label(tableGroup, SWT.NONE).setText(Messages.MigrateDialog_rules);
    new Label(tableGroup, SWT.NONE).setText(Messages.MigrateDialog_rules_explanation);
    Composite tableComp = new Composite(tableGroup, SWT.NONE);
    tableComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    GridLayout layout = new GridLayout(2, false);
    layout.horizontalSpacing = layout.verticalSpacing = 0;
    tableComp.setLayout(layout);//from www  . java 2s  .  co m
    viewer = new TableViewer(tableComp, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.FULL_SELECTION);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
    layoutData.heightHint = 300;
    viewer.getTable().setLayoutData(layoutData);
    final TableViewerColumn col1 = new TableViewerColumn(viewer, SWT.NONE);
    col1.getColumn().setWidth(350);
    col1.getColumn().setText(Messages.MigrateDialog_source_pattern);
    col1.setLabelProvider(new ZColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof MigrationRule)
                return ((MigrationRule) element).getSourcePattern();
            return element.toString();
        }
    });
    final TableViewerColumn col2 = new TableViewerColumn(viewer, SWT.NONE);
    col2.getColumn().setWidth(220);
    col2.getColumn().setText(Messages.MigrateDialog_target_pattern);
    col2.setLabelProvider(new ZColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof MigrationRule)
                return ((MigrationRule) element).getTargetPattern();
            return super.getText(element);
        }
    });
    final TableViewerColumn col3 = new TableViewerColumn(viewer, SWT.NONE);
    col3.getColumn().setWidth(100);
    col3.getColumn().setText(Messages.MigrateDialog_target_volume);
    col3.setLabelProvider(new ZColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof MigrationRule)
                return ((MigrationRule) element).getTargetVolume();
            return element.toString();
        }
    });
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateButtons();
        }
    });
    Composite buttonComp = new Composite(tableComp, SWT.NONE);
    buttonComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    buttonComp.setLayout(new GridLayout(1, false));
    Button addPatternButton = new Button(buttonComp, SWT.PUSH);
    addPatternButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    addPatternButton.setText(Messages.MigrateDialog_add_pattern);
    addPatternButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            RegExDialog dialog = new RegExDialog(getShell(), null, null, false,
                    fileSeparatorCombo.getSelectionIndex(), -1);
            if (dialog.open() == RegExDialog.OK) {
                MigrationRule result = dialog.getResult();
                rules.add(result);
                viewer.add(result);
                viewer.setSelection(new StructuredSelection(result));
                updateButtons();
                dirty = true;
            }
        }
    });
    Button addFolderButton = new Button(buttonComp, SWT.PUSH);
    addFolderButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dirDialog = new DirectoryDialog(getShell());
            dirDialog.setText(Messages.MigrateDialog_select_folder);
            String dir = dirDialog.open();
            if (dir != null) {
                if (!dir.endsWith(File.separator))
                    dir += File.separator;
                if (Constants.WIN32) {
                    int i = dir.indexOf(':');
                    if (i == 1) {
                        String volume = Core.getCore().getVolumeManager().getVolumeForFile(new File(dir));
                        if (volume != null)
                            dir = volume + dir.substring(1);
                    }
                }
                char filesep;
                fileSepearatorPolicy = fileSeparatorCombo.getSelectionIndex();
                switch (fileSepearatorPolicy) {
                case 1:
                    filesep = '/';
                    break;
                case 2:
                    filesep = '\\';
                    break;
                default:
                    filesep = File.separatorChar;
                    break;
                }
                String sourcePattern = dir + "(.*)"; //$NON-NLS-1$
                MigrationRule rule = new MigrationRuleImpl(sourcePattern.replaceAll("\\\\", "\\\\\\\\"), //$NON-NLS-1$ //$NON-NLS-2$
                        Messages.MigrateDialog_target_folder + filesep + "$1", null); //$NON-NLS-1$
                RegExDialog regexDialog = new RegExDialog(getShell(), rule, dir, true, fileSepearatorPolicy,
                        Messages.MigrateDialog_target_folder.length());
                if (regexDialog.open() == RegExDialog.OK) {
                    MigrationRule result = regexDialog.getResult();
                    rules.add(result);
                    viewer.add(result);
                    viewer.setSelection(new StructuredSelection(result));
                    updateButtons();
                    dirty = true;
                }
            }
        }
    });
    addFolderButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    addFolderButton.setText(Messages.MigrateDialog_add_folder);
    editPatternButton = new Button(buttonComp, SWT.PUSH);
    editPatternButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    editPatternButton.setText(Messages.MigrateDialog_edit_pattern);
    editPatternButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            MigrationRule policy = (MigrationRule) viewer.getStructuredSelection().getFirstElement();
            RegExDialog regexDialog = new RegExDialog(getShell(), policy, null, false,
                    fileSeparatorCombo.getSelectionIndex(), -1);
            if (regexDialog.open() == RegExDialog.OK) {
                MigrationRule result = regexDialog.getResult();
                policy.setSourcePattern(result.getSourcePattern());
                policy.setTargetPattern(result.getTargetPattern());
                viewer.update(policy, null);
                updateButtons();
                dirty = true;
            }
        }
    });
    removePatternButton = new Button(buttonComp, SWT.PUSH);
    removePatternButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    removePatternButton.setText(Messages.MigrateDialog_remove_pattern);
    removePatternButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Object policy = viewer.getStructuredSelection().getFirstElement();
            rules.remove(policy);
            viewer.remove(policy);
            updateButtons();
            dirty = true;
        }
    });
    Label sep = new Label(buttonComp, SWT.SEPARATOR | SWT.HORIZONTAL);
    sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    upButton = new Button(buttonComp, SWT.PUSH);
    upButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    upButton.setText(Messages.MigrateDialog_up);
    upButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            MigrationRule policy = (MigrationRule) viewer.getStructuredSelection().getFirstElement();
            int i = rules.indexOf(policy);
            if (i > 0) {
                rules.remove(i);
                rules.add(i - 1, policy);
                viewer.setInput(rules);
                viewer.setSelection(new StructuredSelection(policy));
                updateButtons();
            }
        }
    });
    downButton = new Button(buttonComp, SWT.PUSH);
    downButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    downButton.setText(Messages.MigrateDialog_down);
    downButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            MigrationRule policy = (MigrationRule) viewer.getStructuredSelection().getFirstElement();
            int i = rules.indexOf(policy);
            if (i < rules.size() - 1) {
                rules.remove(i);
                rules.add(i + 1, policy);
                viewer.setInput(rules);
                viewer.setSelection(new StructuredSelection(policy));
                updateButtons();
            }
        }
    });
    return area;
}

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

License:Open Source License

/**
 * @param parent/*from ww w .j a  v a2s  .  c o m*/
 *            - parent composite
 * @param gridData
 *            - layout data
 * @param listener
 *            - is informed about all changes except changes in the subfolder
 *            option
 * @param subfolders
 *            - true if the subfolder option shall be shown
 * @param ftp
 *            - true if FTP targets are supported
 * @param showSettingsOption
 *            - true if target specific options can be selected
 */
@SuppressWarnings("unused")
public OutputTargetGroup(final Composite parent, GridData gridData, final Listener listener, boolean subfolders,
        boolean ftp, boolean showSettingsOption) {
    ftpAccounts = FtpAccount.getAllAccounts();
    ftpAccounts.add(0, new FtpAccount());
    group = new CGroup(parent, SWT.NONE);
    group.setText(Messages.OutputTargetGroup_output_target);
    group.setLayoutData(gridData);
    group.setLayout(new GridLayout(ftp ? 4 : 3, false));
    if (ftp) {
        fileButton = new Button(group, SWT.RADIO);
        fileButton.addListener(SWT.Selection, new Listener() {
            @Override
            public void handleEvent(Event event) {
                updateFields();
                notifyListener(listener, event, FILE);
                browseButton.setEnabled(true);
            }
        });
    }
    final Label folderLabel = new Label(group, SWT.NONE);
    folderLabel.setText(Messages.OutputTargetGroup_local_folder);
    folderField = new Combo(group, SWT.BORDER | SWT.READ_ONLY);
    GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    data.widthHint = 300;
    folderField.setLayoutData(data);
    if (listener != null)
        folderField.addListener(SWT.Modify, listener);
    browseButton = new Button(group, SWT.PUSH);
    browseButton.setText(Messages.WebGalleryEditDialog_browse);
    browseButton.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event event) {
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.OPEN);
            dialog.setText(Messages.OutputTargetGroup_output_folder);
            dialog.setMessage(Messages.OutputTargetGroup_select_output_folder);
            String path = folderField.getText();
            if (!path.isEmpty())
                dialog.setFilterPath(path);
            String dir = dialog.open();
            if (dir != null) {
                folderField.setItems(UiUtilities.addToHistoryList(folderField.getItems(), dir));
                folderField.setText(dir);
                notifyListener(listener, event, FILE);
            }
        }
    });
    if (ftp) {
        ftpButton = new Button(group, SWT.RADIO);
        ftpButton.addListener(SWT.Selection, new Listener() {
            @Override
            public void handleEvent(Event event) {
                updateFields();
                notifyListener(listener, event, FTP);
                browseButton.setEnabled(false);
            }
        });
        final Label ftpLabel = new Label(group, SWT.NONE);
        ftpLabel.setText(Messages.OutputTargetGroup_ftp_directory);
        ftpViewer = new ComboViewer(group, SWT.BORDER | SWT.READ_ONLY);
        ftpViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
        ftpViewer.setContentProvider(ArrayContentProvider.getInstance());
        ftpViewer.setLabelProvider(new LabelProvider() {
            @Override
            public String getText(Object element) {
                if (element instanceof FtpAccount) {
                    String name = ((FtpAccount) element).getName();
                    return name == null ? Messages.OutputTargetGroup_create_new_account : name;
                }
                return super.getText(element);
            }
        });
        editButton = new Button(group, SWT.PUSH);
        editButton.setText(Messages.OutputTargetGroup_edit);
        editButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                Object el = ftpViewer.getStructuredSelection().getFirstElement();
                if (el instanceof FtpAccount) {
                    FtpAccount account = (FtpAccount) el;
                    boolean createNew = account.getName() == null;
                    EditFtpDialog dialog = new EditFtpDialog(editButton.getShell(), account, false, null);
                    if (dialog.open() == Window.OK) {
                        FtpAccount result = dialog.getResult();
                        if (createNew) {
                            ftpAccounts.add(0, new FtpAccount());
                            ftpViewer.setInput(ftpAccounts);
                            ftpViewer.setSelection(new StructuredSelection(result));
                        } else
                            ftpViewer.update(result, null);
                        FtpAccount.saveAccounts(ftpAccounts);
                    }
                }
            }
        });
        ftpViewer.setInput(ftpAccounts);
        if (ftpAccounts.size() == 1)
            ftpViewer.setSelection(new StructuredSelection(ftpAccounts.get(0)));
        ftpViewer.getCombo().addListener(SWT.Selection, new Listener() {
            @Override
            public void handleEvent(Event event) {
                updateFields();
                notifyListener(listener, event, FTP);
            }
        });
    }
    if (subfolders) {
        Meta meta = Core.getCore().getDbManager().getMeta(true);
        String timelinemode = meta.getTimeline();
        final String[] subfolderoptions = Meta.timeline_no.equals(timelinemode)
                ? new String[] { Constants.BY_NONE, Constants.BY_RATING, Constants.BY_CATEGORY,
                        Constants.BY_STATE, Constants.BY_JOB, Constants.BY_EVENT, Constants.BY_DATE,
                        Constants.BY_TIME }
                : new String[] { Constants.BY_NONE, Constants.BY_TIMELINE, Constants.BY_NUM_TIMELINE,
                        Constants.BY_RATING, Constants.BY_CATEGORY, Constants.BY_STATE, Constants.BY_JOB,
                        Constants.BY_EVENT, Constants.BY_DATE, Constants.BY_TIME };
        final String[] OPTIONLABELS = Meta.timeline_no.equals(timelinemode)
                ? new String[] { Messages.OutputTargetGroup_none, Messages.OutputTargetGroup_rating,
                        Messages.OutputTargetGroup_category, Messages.OutputTargetGroup_state,
                        Messages.OutputTargetGroup_job_id, Messages.OutputTargetGroup_event,
                        Messages.OutputTargetGroup_export_date, Messages.OutputTargetGroup_export_time }
                : new String[] { Messages.OutputTargetGroup_none, Messages.OutputTargetGroup_timeline,
                        Messages.OutputTargetGroup_timeline_num, Messages.OutputTargetGroup_rating,
                        Messages.OutputTargetGroup_category, Messages.OutputTargetGroup_state,
                        Messages.OutputTargetGroup_job_id, Messages.OutputTargetGroup_event,
                        Messages.OutputTargetGroup_export_date, Messages.OutputTargetGroup_export_time };
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE).setText(Messages.OutputTargetGroup_group_by);
        subfolderViewer = new ComboViewer(group);
        subfolderViewer.setContentProvider(ArrayContentProvider.getInstance());
        subfolderViewer.setLabelProvider(new LabelProvider() {
            @Override
            public String getText(Object element) {
                for (int i = 0; i < subfolderoptions.length; i++)
                    if (subfolderoptions[i].equals(element))
                        return OPTIONLABELS[i];
                return super.getText(element);
            }
        });
        subfolderViewer.getCombo().addListener(SWT.Selection, new Listener() {
            @Override
            public void handleEvent(Event event) {
                subfolderoption = ((String) subfolderViewer.getStructuredSelection().getFirstElement());
                notifyListener(listener, event, SUBFOLDER);
            }
        });
        subfolderViewer.setInput(subfolderoptions);
    }
    if (showSettingsOption) {
        settingsOption = WidgetFactory.createCheckButton(group, Messages.OutputTargetGroup_target_specific,
                null, Messages.OutputTargetGroup_target_specific_tooltip);
        settingsOption.addListener(new Listener() {
            @Override
            public void handleEvent(Event event) {
                notifyListener(listener, event, SETTINGS);
            }
        });
    }
}

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

License:Open Source License

public void setFtpDir(String ftpDir) {
    if (ftpDir != null && ftpViewer != null)
        for (FtpAccount acc : ftpAccounts)
            if (ftpDir.equals(acc.getName())) {
                ftpViewer.setSelection(new StructuredSelection(acc));
                break;
            }/*from w w w  . j a  v  a  2  s .  c  o m*/
}

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

License:Open Source License

public void initValues(IDialogSettings settings) {
    try {//from  w ww  .j av a2  s .  c  o m
        setTarget(settings.getInt(OUTPUT_TARGET));
    } catch (NumberFormatException e) {
        setTarget(Constants.FILE);
    }
    String[] localFolders = settings.getArray(LOCAL_FOLDERS);
    if (localFolders != null) {
        List<String> validItems = new ArrayList<String>(localFolders.length);
        for (String folder : localFolders)
            if (new File(folder).exists())
                validItems.add(folder);
        folderField.setItems(validItems.toArray(new String[validItems.size()]));
        String s = settings.get(LOCAL_FOLDER);
        if (s != null)
            for (int i = 0; i < localFolders.length; i++)
                if (s.equals(localFolders[i])) {
                    folderField.select(i);
                    folderField.setText(s);
                    break;
                }
    } else
        folderField.setItems(EMPTYITEMS);
    String ftp = settings.get(SELECTED_ACCOUNT);
    if (ftp != null && ftpViewer != null)
        for (FtpAccount acc : ftpAccounts)
            if (ftp.equals(acc.getName())) {
                ftpViewer.setSelection(new StructuredSelection(acc));
                break;
            }
    if (settingsOption != null)
        settingsOption.setSelection(settings.getBoolean(OPTIONS));
    updateSubfolderOption(settings);
    updateFields();
}

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

License:Open Source License

public void updateSubfolderOption(IDialogSettings settings) {
    if (subfolderViewer != null) {
        String option = settings.get(SUBFOLDERS);
        subfolderViewer.setSelection(//from www.j a  va  2  s .c  om
                new StructuredSelection(subfolderoption = (option != null ? option : Constants.BY_NONE)));
    }
}

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

License:Open Source License

@Override
protected void buttonPressed(int buttonId) {
    if (buttonId == DELETEREGION) {
        deleteRegion = true;/*from   w w  w  . jav a 2s. co  m*/
        okPressed();
        return;
    }
    if (buttonId == DELETEALLREGIONS) {
        if (AcousticMessageDialog.openQuestion(getShell(), Messages.SetPersonDialog_delete_all_regions,
                Messages.SetPersonDialog_this_will_remove)) {
            deleteAllRegions = true;
            okPressed();
        }
        return;
    }
    if (buttonId == NEWALBUM) {
        CollectionEditDialog dialog = new CollectionEditDialog(getShell(), null,
                Messages.AlbumSelectionDialog_create_person, Messages.AlbumSelectionDialog_specify_person_name,
                false, true, true, false);
        if (dialog.open() == Window.OK) {
            final SmartCollectionImpl album = dialog.getResult();
            if (album != null) {
                Group group = dbManager.obtainById(GroupImpl.class, Constants.GROUP_ID_PERSONS);
                album.addSortCriterion(new SortCriterionImpl(QueryField.IPTC_DATECREATED.getKey(), null, true));
                group.addRootCollection(album.getStringId());
                album.setGroup_rootCollection_parent(Constants.GROUP_ID_PERSONS);
                Collection<Object> toBeStored = Utilities.storeCollection(album, true, null);
                toBeStored.add(group);
                dbManager.safeTransaction(null, toBeStored);
                fillValues(true);
                viewer.setSelection(new StructuredSelection(album), true);
                validate();
                CoreActivator.getDefault().fireStructureModified();
            }
        }
        return;
    }
    super.buttonPressed(buttonId);
}

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

License:Open Source License

private void fillValues(boolean keep) {
    albums = new ArrayList<SmartCollectionImpl>(
            dbManager.<SmartCollectionImpl>obtainObjects(SmartCollectionImpl.class, false, "album", true, //$NON-NLS-1$
                    QueryField.EQUALS, "system", true, //$NON-NLS-1$
                    QueryField.EQUALS));
    IAssetProvider assetProvider = Core.getCore().getAssetProvider();
    if (assetProvider != null)
        albums.remove(assetProvider.getCurrentCollection());
    IStructuredSelection selection = viewer.getStructuredSelection();
    SetModel model = new SetModel();
    model.addAll(albums);/*from   w w  w  . j a  v  a2s .  c o  m*/
    viewer.setInput(model);
    viewer.getControl().getDisplay().timerExec(500, new Runnable() {
        @Override
        public void run() {
            if (!viewer.getControl().isDisposed()) {
                if (keep)
                    viewer.setSelection(selection);
                else if (assignedAlbum != null)
                    for (SmartCollectionImpl sm : albums)
                        if (sm.getStringId().equals(assignedAlbum)) {
                            viewer.setSelection(new StructuredSelection(sm), true);
                            break;
                        }
            }

        }
    });
}

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

License:Open Source License

private void createHeaderGroup(Composite comp) {
    UiActivator activator = UiActivator.getDefault();
    fileEditor = new FileEditor(comp, SWT.SAVE | SWT.READ_ONLY, Messages.EditMetaDialog_file_name, true,
            activator.getCatFileExtensions(), activator.getSupportedCatFileNames(), null,
            '*' + Constants.CATALOGEXTENSION, true, getDialogSettings(UiActivator.getDefault(), SETTINGSID));
    fileEditor.addListener(new Listener() {
        @Override//ww w. ja v  a  2 s .  c  o  m
        public void handleEvent(Event event) {
            updateButtons();
        }
    });
    Composite header = new Composite(comp, SWT.NONE);
    header.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    header.setLayout(new GridLayout(2, false));
    new Label(header, SWT.NONE).setText(Messages.EditMetaDialog_description);
    final GridData gd_description = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd_description.heightHint = 100;
    gd_description.widthHint = 400;
    descriptionField = new CheckedText(header, SWT.V_SCROLL | SWT.BORDER | SWT.MULTI | SWT.WRAP);
    descriptionField.setLayoutData(gd_description);
    // timeline
    new Label(header, SWT.NONE).setText(Messages.EditMetaDialog_create_timeline);
    timelineViewer = new ComboViewer(header);
    timelineViewer.getControl().setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1));
    timelineViewer.setContentProvider(ArrayContentProvider.getInstance());
    timelineViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (Meta_type.timeline_year.equals(element))
                return Messages.EditMetaDialog_by_year;
            if (Meta_type.timeline_month.equals(element))
                return Messages.EditMetaDialog_by_month;
            if (Meta_type.timeline_day.equals(element))
                return Messages.EditMetaDialog_by_day;
            return Messages.EditMetaDialog_none;
        }
    });
    timelineViewer.setInput(Meta_type.timelineALLVALUES);
    timelineViewer.setSelection(new StructuredSelection(timeline == null ? Meta_type.timeline_no : timeline),
            true);
    // locations
    new Label(header, SWT.NONE).setText(Messages.EditMetaDialog_create_loc_folders);
    locationViewer = new ComboViewer(header);
    locationViewer.getControl().setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1));
    locationViewer.setContentProvider(ArrayContentProvider.getInstance());
    locationViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (Meta_type.locationFolders_country.equals(element))
                return Messages.EditMetaDialog_byCountry;
            if (Meta_type.locationFolders_state.equals(element))
                return Messages.EditMetaDialog_byState;
            if (Meta_type.locationFolders_city.equals(element))
                return Messages.EditMetaDialog_byCity;
            return Messages.EditMetaDialog_none;
        }
    });
    locationViewer.setInput(Meta_type.locationFoldersALLVALUES);
    locationViewer.setSelection(
            new StructuredSelection(locationOption == null ? Meta_type.locationFolders_no : locationOption),
            true);
    deleteButton = WidgetFactory.createCheckButton(header, Messages.SplitCatDialog_remove_extracted_entries,
            new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1));
    deleteButton.addListener(new Listener() {
        @Override
        public void handleEvent(Event event) {
            if (deleteButton.getSelection() && !AcousticMessageDialog.openQuestion(getShell(),
                    Messages.SplitCatDialog_delete_exported, Messages.SplitCatDialog_delete_exported_msg))
                deleteButton.setSelection(false);
        }
    });
}

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

License:Open Source License

public void add(IIdentifiableObject element) {
    objects.add(element);
    update();
    viewer.setSelection(new StructuredSelection(element), true);
}