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

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

Introduction

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

Prototype

public LabelProvider() 

Source Link

Document

Creates a new label provider.

Usage

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

License:Open Source License

/**
 * @param parent/* w  w w. j  a  v a2s . co 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.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/*from w  ww . java 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.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 w w . ja v  a2 s.c  om*/
    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 createEngineGroup(Composite comp) {
    comp.setLayout(new GridLayout(2, false));
    CGroup group = new CGroup(comp, SWT.NONE);
    group.setText(Messages.WebGalleryEditDialog_engine);
    group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
    group.setLayout(new GridLayout());
    engineViewer = new ComboViewer(group, SWT.READ_ONLY);
    engineViewer.getControl().setLayoutData(new GridData(150, SWT.DEFAULT));
    engineViewer.setContentProvider(ArrayContentProvider.getInstance());
    engineViewer.setLabelProvider(new LabelProvider() {
        @Override/* w  ww.j  a v  a 2  s.  c o m*/
        public String getText(Object element) {
            if (element instanceof IConfigurationElement)
                return ((IConfigurationElement) element).getAttribute("name"); //$NON-NLS-1$
            return super.getText(element);
        }
    });
    engineViewer.setComparator(ZViewerComparator.INSTANCE);
    engineViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateParms();
            fillPreview();
        }
    });
    parmComp = new Composite(comp, SWT.NONE);
    parmComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    parmComp.setLayout(new StackLayout());
    emptyComp = new Composite(parmComp, SWT.NONE);
    for (IConfigurationElement element : generators) {
        Composite genComp = new Composite(parmComp, SWT.NONE);
        genComp.setLayout(new GridLayout(2, false));
        String ns = element.getNamespaceIdentifier();
        compMap.put(element.getAttribute("id"), genComp); //$NON-NLS-1$
        Composite lastParent = genComp;
        for (IConfigurationElement child : element.getChildren()) {
            if ("group".equals(child.getName())) { //$NON-NLS-1$
                group = new CGroup(genComp, SWT.NONE);
                group.setText(child.getAttribute("name")); //$NON-NLS-1$
                group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
                group.setLayout(new GridLayout(2, false));
                lastParent = group;
            } else
                createParmControl(lastParent, ns, child);
        }
    }
}

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

License:Open Source License

private Control createColorSchemeGroup(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    composite.setLayout(new GridLayout(1, false));
    CGroup schemeGroup = UiUtilities.createGroup(composite, 2,
            Messages.getString("AppearancePreferencePage.bg_color")); //$NON-NLS-1$
    List<String> dropins = new ArrayList<String>();
    String path = Platform.getInstallLocation().getURL().getPath();
    File installFolder = new File(path);
    scanCSSDropins(dropins, new File(installFolder, CssActivator.DROPINFOLDER));
    scanCSSDropins(dropins, new File(installFolder.getParentFile(), CssActivator.DROPINFOLDER));
    String[] colorOptions = new String[dropins.size() + 5];
    String[] colorLabels = new String[dropins.size() + 5];
    if (Constants.OSX)
        colorLabels[0] = "OS X"; //$NON-NLS-1$
    else if (Constants.WIN32)
        colorLabels[0] = "Windows"; //$NON-NLS-1$
    else if (Platform.WS_GTK.equals(Platform.getWS()))
        colorLabels[0] = "GTK"; //$NON-NLS-1$
    else if (Platform.WS_MOTIF.equals(Platform.getWS()))
        colorLabels[0] = "Motif"; //$NON-NLS-1$
    else//from  w  ww  . j a  v  a 2 s .co m
        colorLabels[0] = Messages.getString("AppearancePreferencePage.platform"); //$NON-NLS-1$
    colorOptions[0] = PreferenceConstants.BACKGROUNDCOLOR_PLATFORM;
    colorLabels[1] = Messages.getString("AppearancePreferencePage.black"); //$NON-NLS-1$
    colorOptions[1] = PreferenceConstants.BACKGROUNDCOLOR_BLACK;
    colorLabels[2] = Messages.getString("AppearancePreferencePage.dark_grey"); //$NON-NLS-1$
    colorOptions[2] = PreferenceConstants.BACKGROUNDCOLOR_DARKGREY;
    colorLabels[3] = Messages.getString("AppearancePreferencePage.grey"); //$NON-NLS-1$
    colorOptions[3] = PreferenceConstants.BACKGROUNDCOLOR_GREY;
    colorLabels[4] = Messages.getString("AppearancePreferencePage.white"); //$NON-NLS-1$
    colorOptions[4] = PreferenceConstants.BACKGROUNDCOLOR_WHITE;
    int j = 5;
    for (String name : dropins)
        colorOptions[j] = colorLabels[j++] = name;
    colorViewer = createComboViewer(schemeGroup, null, colorOptions, colorLabels, false);
    comment = new Label(schemeGroup, SWT.NONE);
    comment.setText(Messages.getString("AppearancePreferencePage.switching_to_platform_colors")); //$NON-NLS-1$
    GridData layoutData = new GridData();
    layoutData.horizontalIndent = 15;
    comment.setLayoutData(layoutData);
    comment.setVisible(false);
    colorViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Object newTheme = colorViewer.getStructuredSelection().getFirstElement();
            comment.setVisible(
                    PreferenceConstants.BACKGROUNDCOLOR_PLATFORM.equals(newTheme) && !newTheme.equals(theme));
        }
    });
    CGroup unitGroup = UiUtilities.createGroup(composite, 2,
            Messages.getString("AppearancePreferencePage.units")); //$NON-NLS-1$
    new Label(unitGroup, SWT.NONE).setText(Messages.getString("AppearancePreferencePage.distances")); //$NON-NLS-1$
    distViewer = new ComboViewer(unitGroup, SWT.NONE);
    distViewer.setContentProvider(ArrayContentProvider.getInstance());
    distViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof String) {
                if (((String) element).startsWith("m")) //$NON-NLS-1$
                    return Messages.getString("AppearancePreferencePage.miles"); //$NON-NLS-1$
                if (((String) element).startsWith("n")) //$NON-NLS-1$
                    return Messages.getString("AppearancePreferencePage.nautical"); //$NON-NLS-1$
            }
            return Messages.getString("AppearancePreferencePage.kilometers"); //$NON-NLS-1$
        }
    });
    distViewer.setInput(new String[] { "k", "m", "n" }); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
    new Label(unitGroup, SWT.NONE).setText(Messages.getString("AppearancePreferencePage.physical_dims")); //$NON-NLS-1$
    dimViewer = new ComboViewer(unitGroup, SWT.NONE);
    dimViewer.setContentProvider(ArrayContentProvider.getInstance());
    dimViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof String) {
                if (((String) element).startsWith("i")) //$NON-NLS-1$
                    return Messages.getString("AppearancePreferencePage.inches"); //$NON-NLS-1$
            }
            return Messages.getString("AppearancePreferencePage.centimeters"); //$NON-NLS-1$
        }
    });
    dimViewer.setInput(new String[] { "c", "i" }); //$NON-NLS-1$//$NON-NLS-2$
    return composite;
}

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

License:Open Source License

private Composite createRawGroup(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    composite.setLayout(new GridLayout(1, false));
    Composite rccomp = new Composite(composite, SWT.NONE);
    rccomp.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    rccomp.setLayout(new GridLayout(2, false));
    new Label(rccomp, SWT.NONE).setText(Messages.getString("ImportPreferencePage.raw_converter2")); //$NON-NLS-1$

    rcViewer = new ComboViewer(rccomp, SWT.NONE);
    rcViewer.setContentProvider(ArrayContentProvider.getInstance());
    rcViewer.setLabelProvider(new LabelProvider() {
        @Override/*from   w w w .  j av a 2s . c  o m*/
        public String getText(Object element) {
            if (element instanceof IRawConverter)
                return ((IRawConverter) element).getName();
            return super.getText(element);
        }
    });
    Map<String, IRawConverter> rawConverters = BatchActivator.getDefault().getRawConverters();
    rcViewer.setInput(rawConverters.values());
    rcViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateRawOptions();
            validate();
        }
    });
    basicsGroup = new CGroup(composite, SWT.NONE);
    basicsGroup.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    basicsLayout = new StackLayout();
    basicsGroup.setLayout(basicsLayout);
    basicsGroup.setText(Messages.getString("ImportPreferencePage.converter")); //$NON-NLS-1$
    for (IRawConverter rc : rawConverters.values()) {
        String exec = rc.getExecutable();
        if (!IRawConverter.NONE.equals(exec)) {
            Composite basicsComp = new Composite(basicsGroup, SWT.NONE);
            basicsComp.setLayout(new GridLayout(1, false));
            FileEditor fileEditor = new FileEditor(basicsComp, SWT.OPEN | SWT.READ_ONLY,
                    NLS.bind(IRawConverter.OPTIONAL.equals(exec)
                            ? Messages.getString("ImportPreferencePage.external_executable") //$NON-NLS-1$
                            : Messages.getString("ImportPreferencePage.executable"), rc.getName()), //$NON-NLS-1$
                    true, Constants.EXEEXTENSION, Constants.EXEFILTERNAMES, null, null, false, true,
                    dialogSettings);
            fileEditor.addListener(new Listener() {
                @Override
                public void handleEvent(Event event) {
                    validate();
                }
            });
            String msg = rc.getVersionMessage();
            if (msg != null)
                new Label(basicsComp, SWT.NONE).setText(msg);
            basicsFileEditors.put(rc.getId(), fileEditor);
        }
    }
    optionsGroup = new CGroup(composite, SWT.NONE);
    optionsGroup.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    optionsLayout = new StackLayout();
    optionsGroup.setLayout(optionsLayout);
    optionsGroup.setText(Messages.getString("ImportPreferencePage.options2")); //$NON-NLS-1$
    for (IRawConverter rc : rawConverters.values()) {
        final IRawConverter rawConverter = rc;
        List<RawProperty> props = rawConverter.getProperties();
        if (!props.isEmpty()) {
            Composite optionComp = new Composite(optionsGroup, SWT.NONE);
            optionComp.setLayout(new GridLayout(2, false));
            for (RawProperty prop : props) {
                String type = prop.type;
                List<RawEnum> enums = prop.enums;
                if (enums != null && !enums.isEmpty()) {
                    new Label(optionComp, SWT.NONE).setText(prop.name);
                    ComboViewer viewer = new ComboViewer(optionComp, SWT.NONE);
                    viewer.setLabelProvider(new LabelProvider() {
                        @Override
                        public String getText(Object element) {
                            if (element instanceof RawEnum)
                                return ((RawEnum) element).value;
                            return super.getText(element);
                        }
                    });
                    viewer.setContentProvider(ArrayContentProvider.getInstance());
                    viewer.setInput(enums);
                    optionProps.put(prop.id, viewer);
                    for (RawEnum rawEnum : enums)
                        if (rawEnum.recipe) {
                            viewer.addSelectionChangedListener(new ISelectionChangedListener() {
                                public void selectionChanged(SelectionChangedEvent event) {
                                    RawEnum e = (RawEnum) ((IStructuredSelection) event.getSelection())
                                            .getFirstElement();
                                    rawConverter.setUsesRecipes(e == null ? "" //$NON-NLS-1$
                                            : e.id);
                                    updateThumbnailWarning();
                                }
                            });
                            break;
                        }
                } else if ("int".equals(type)) { //$NON-NLS-1$
                    new Label(optionComp, SWT.NONE).setText(prop.name);
                    Spinner field = new Spinner(optionComp, SWT.BORDER);
                    if (prop.max != null)
                        try {
                            field.setMaximum(Integer.parseInt(prop.max));
                        } catch (NumberFormatException e) {
                            // do nothing
                        }
                    if (prop.min != null)
                        try {
                            field.setMinimum(Integer.parseInt(prop.min));
                        } catch (NumberFormatException e) {
                            // do nothing
                        }
                    optionProps.put(prop.id, field);
                } else if ("boolean".equals(type)) //$NON-NLS-1$
                    optionProps.put(prop.id, WidgetFactory.createCheckButton(optionComp, prop.name,
                            new GridData(SWT.BEGINNING, SWT.CENTER, true, false, 2, 1)));
                else if ("label".equals(type)) //$NON-NLS-1$
                    new Label(optionComp, SWT.NONE).setText(prop.name);
                else {
                    new Label(optionComp, SWT.NONE).setText(prop.name);
                    optionProps.put(prop.id, new Text(optionComp, SWT.BORDER));
                }
            }
            optionComps.put(rc.getId(), optionComp);
        }
    }

    allDetectors = CoreActivator.getDefault().getRecipeDetectors();
    if (allDetectors != null && !allDetectors.isEmpty())
        createRecipeGroup(composite);
    thumbnailWarning = new Label(composite, SWT.NONE);
    thumbnailWarning.setData(CSSProperties.ID, CSSProperties.ERRORS);
    thumbnailWarning.setText(Messages.getString("ImportPreferencePage.raw_thumbnail_warning")); //$NON-NLS-1$
    archiveRecipesButton = WidgetFactory.createCheckButton(composite,
            Messages.getString("ImportPreferencePage.archive_recipes"), new GridData(SWT.BEGINNING, SWT.CENTER, //$NON-NLS-1$
                    false, false, 2, 1));
    synchronizeRecipesButton = WidgetFactory.createCheckButton(composite,
            Messages.getString("ImportPreferencePage.immediate_update"), new GridData(SWT.BEGINNING, SWT.CENTER, //$NON-NLS-1$
                    false, false, 2, 1));
    return composite;
}

From source file:com.bdaum.zoom.ui.internal.widgets.AutoRatingGroup.java

License:Open Source License

public AutoRatingGroup(Composite parent, IAiService aiService, IDialogSettings dialogSettings) {
    super(parent, SWT.NONE);
    setLayout(new FillLayout());
    this.aiService = aiService;
    ratingProviderIds = aiService.getRatingProviderIds();
    String[] ratingProviderNames = aiService.getRatingProviderNames();
    this.dialogSettings = dialogSettings;
    CGroup group = new CGroup(this, SWT.NONE);
    group.setText(Messages.AutoRatingGroup_auto_rating);
    group.setLayout(new GridLayout(3, false));
    enableButton = WidgetFactory.createCheckButton(group, Messages.AutoRatingGroup_enable,
            new GridData(SWT.FILL, SWT.BEGINNING, true, false, 3, 1));
    enableButton.addListener(new Listener() {
        @Override/*  www. j  ava2s  .  co  m*/
        public void handleEvent(Event event) {
            updateControls();
            fireEvent(event);
        }
    });
    Label label = new Label(group, SWT.NONE);
    label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    label.setText(Messages.AutoRatingGroup_provider);
    if (ratingProviderIds.length > 1) {
        providerViewer = new ComboViewer(group, SWT.NONE);
        GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false);
        layoutData.widthHint = 100;
        providerViewer.getControl().setLayoutData(layoutData);
        providerViewer.setContentProvider(ArrayContentProvider.getInstance());
        providerViewer.setLabelProvider(new LabelProvider() {
            @Override
            public String getText(Object element) {
                for (int i = 0; i < ratingProviderIds.length; i++)
                    if (ratingProviderIds[i].equals(element))
                        return ratingProviderNames[i];
                return super.getText(element);
            }
        });
        providerViewer.getCombo().addListener(SWT.Selection, new Listener() {
            @Override
            public void handleEvent(Event event) {
                selectedProvider = (String) providerViewer.getStructuredSelection().getFirstElement();
                updateModelViewer();
                fireEvent(event);
            }
        });
    } else {
        label = new Label(group, SWT.NONE);
        label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
        label.setText(ratingProviderNames[0]);
        selectedProvider = ratingProviderIds[0];
    }
    Composite modelcomp = new Composite(group, SWT.NONE);
    modelcomp.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = layout.marginWidth = 0;
    modelcomp.setLayout(layout);
    label = new Label(modelcomp, SWT.NONE);
    label.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
    label.setText(Messages.AutoRatingGroup_theme);
    modelViewer = new ComboViewer(modelcomp, SWT.NONE);
    GridData layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, true, false);
    layoutData.widthHint = 80;
    modelViewer.getControl().setLayoutData(layoutData);
    modelViewer.setContentProvider(ArrayContentProvider.getInstance());
    modelViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            for (int i = 0; i < modelIds.length; i++)
                if (modelIds[i].equals(element))
                    return modelLabels[i];
            return super.getText(element);
        }
    });
    modelViewer.getCombo().addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event event) {
            fireEvent(event);
        }
    });
    Composite maxGroup = new Composite(group, SWT.NONE);
    maxGroup.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 3, 1));
    layout = new GridLayout(3, false);
    layout.marginHeight = layout.marginWidth = 0;
    maxGroup.setLayout(layout);
    new Label(maxGroup, SWT.NONE).setText(Messages.AutoRatingGroup_rating);
    maxField = new NumericControl(maxGroup, SWT.NONE);
    maxField.setMinimum(1);
    maxField.setMaximum(5);
    maxField.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    overwriteButton = WidgetFactory.createCheckButton(maxGroup, Messages.AutoRatingGroup_overwrite,
            new GridData(SWT.END, SWT.CENTER, true, false));
}

From source file:com.bdaum.zoom.ui.internal.widgets.SearchResultGroup.java

License:Open Source License

public SearchResultGroup(Composite parent, int style, boolean methods, boolean scoreAndHits, boolean keywords,
        Button okButton, Object layoutData) {
    Composite area = new Composite(parent, SWT.NONE);
    area.setLayout(new GridLayout(2, false));
    this.okButton = okButton;
    CGroup group = new CGroup(area, style);
    group.setText(methods ? Messages.SearchResultGroup_search_algorithm
            : Messages.SearchResultGroup_search_parameters);
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    group.setLayout(new GridLayout());
    composite = new Composite(group, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    if (layoutData != null)
        area.setLayoutData(layoutData);/*from   w w w  . j  ava 2 s.c om*/
    else {
        int columns = -1;
        Layout layout = parent.getLayout();
        if (layout instanceof GridLayout)
            columns = ((GridLayout) layout).numColumns;
        if (columns > 0)
            area.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, columns, 1));
        else
            area.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    }
    int numColumns = (style & SWT.VERTICAL) != 0 ? 2 : 4;
    GridLayout gridlayout = new GridLayout(numColumns, false);
    gridlayout.marginHeight = 0;
    gridlayout.marginWidth = 0;
    composite.setLayout(gridlayout);
    if (methods) {
        Composite methodGroup = new Composite(composite, SWT.NONE);
        methodGroup.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, numColumns, 1));
        GridLayout glayout = new GridLayout(2, false);
        glayout.marginWidth = 0;
        methodGroup.setLayout(glayout);

        algoViewer = new ComboViewer(methodGroup);
        algoViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        algoViewer.setContentProvider(ArrayContentProvider.getInstance());
        algoViewer.setLabelProvider(new LabelProvider());
        algoViewer.setComparator(ZViewerComparator.INSTANCE);
        fillAlgoViewer();
        algoViewer.getCombo().setVisibleItemCount(opts.size());
        algoExplanation = new Label(composite, SWT.WRAP);
        GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, numColumns, 1);
        gridData.heightHint = 60;
        gridData.widthHint = 250;
        gridData.horizontalIndent = 15;
        algoExplanation.setLayoutData(gridData);
        algoViewer.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent event) {
                updateControls();
            }
        });
        link = new CLink(methodGroup, SWT.NONE);
        link.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
        link.setText(Messages.SearchResultGroup_configure);
        link.addListener(new Listener() {
            @Override
            public void handleEvent(Event event) {
                BusyIndicator.showWhile(link.getDisplay(), () -> {
                    IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench()
                            .getActiveWorkbenchWindow();
                    if (activeWorkbenchWindow != null) {
                        IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
                        if (activePage != null) {
                            EditMetaDialog mdialog = new EditMetaDialog(link.getShell(), activePage,
                                    Core.getCore().getDbManager(), false, null);
                            mdialog.setInitialPage(EditMetaDialog.INDEXING);
                            if (mdialog.open() == Dialog.OK) {
                                ISelection selection = algoViewer.getSelection();
                                fillAlgoViewer();
                                algoViewer.setSelection(selection);
                            }
                        }
                    }
                });
            }
        });
    }
    if (scoreAndHits) {
        Label numberlabel = new Label(composite, SWT.NONE);
        numberlabel.setText(com.bdaum.zoom.ui.internal.widgets.Messages.SearchResultGroup_maxNumber);
        numberField = new NumericControl(composite, NumericControl.LOGARITHMIC);
        numberField.setMaximum(1000);
        numberField.setMinimum(3);
        new Label(composite, SWT.NONE)
                .setText(com.bdaum.zoom.ui.internal.widgets.Messages.SearchResultGroup_minScore);
        scoreField = new NumericControl(composite, SWT.NONE);
        scoreField.setMaximum(99);
        scoreField.setMinimum(1);
    }
    if (keywords) {
        CGroup keyGroup = new CGroup(area, SWT.NONE);
        GridData data = new GridData(SWT.FILL, SWT.FILL, false, true);
        data.widthHint = 120;
        keyGroup.setLayoutData(data);
        keyGroup.setLayout(new GridLayout());
        keyGroup.setText(Messages.SearchResultGroup_search_by);
        Label label = new Label(keyGroup, SWT.NONE);
        label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
        label.setText(Messages.SearchResultGroup_keywords);

        scale = new Scale(keyGroup, SWT.VERTICAL);
        data = new GridData(SWT.CENTER, SWT.CENTER, true, true);
        data.heightHint = 90;
        scale.setLayoutData(data);
        scale.setMaximum(100);
        scale.setIncrement(5);
        scale.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                scale.setToolTipText(String.valueOf(scale.getMaximum() - scale.getSelection()));
            }
        });
        label = new Label(keyGroup, SWT.NONE);
        label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
        label.setText(Messages.SearchResultGroup_visual);
    }
}

From source file:com.bdaum.zoom.ui.preferences.AbstractPreferencePage.java

License:Open Source License

/**
 * Creates a combo viewer/* ww w. ja  v  a2  s  . co  m*/
 *
 * @param parent
 *            - parent container
 * @param lab
 *            - label
 * @param options
 *            - combo items
 * @param labelling
 *            - either a String[] object with corresponding labels or a
 *            LabelProvider
 * @param sort
 *            - true if items are to be sorted alphabetically
 * @return combo viewer
 */
public static ComboViewer createComboViewer(Composite parent, String lab, final String[] options,
        final Object labelling, boolean sort) {
    if (lab != null)
        new Label(parent, SWT.NONE).setText(lab);
    ComboViewer viewer = new ComboViewer(parent);
    viewer.getControl().setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    if (labelling instanceof LabelProvider)
        viewer.setLabelProvider((LabelProvider) labelling);
    else
        viewer.setLabelProvider(new LabelProvider() {

            @Override
            public String getText(Object element) {
                if (labelling instanceof String[])
                    for (int i = 0; i < options.length; i++)
                        if (options[i].equals(element))
                            return ((String[]) labelling)[i];
                return super.getText(element);
            }
        });
    if (sort)
        viewer.setComparator(ZViewerComparator.INSTANCE);
    viewer.setInput(options);
    return viewer;
}

From source file:com.bdaum.zoom.video.youtube.internal.wizard.ExportToYouTubePage.java

License:Open Source License

@SuppressWarnings("unused")
@Override//from ww  w  .  j ava  2  s . co m
public void createControl(Composite parent) {
    Composite composite = createComposite(parent, 1);
    new Label(composite, SWT.NONE);
    createAccountGroup(composite);
    CGroup group = CGroup.create(composite, 1, Messages.ExportToYouTubePage_settings);
    new Label(group, SWT.NONE).setText(Messages.ExportToYouTubePage_youtube_category);
    catViewer = new ComboViewer(group);
    catViewer.setContentProvider(new IStructuredContentProvider() {

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            // do nothing
        }

        public void dispose() {
            // do nothing
        }

        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof Map) {
                return ((Map<?, ?>) inputElement).keySet().toArray();
            }
            return new Object[0];
        }
    });
    catViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            String label = categories.get(element);
            return (label != null) ? label : super.getText(element);
        }
    });
    catViewer.setComparator(ZViewerComparator.INSTANCE);
    YouTubeUploadClient api = (YouTubeUploadClient) ((AbstractCommunityExportWizard) getWizard()).getApi();
    try {
        categories = api.getCategories();
    } catch (IOException e) {
        setErrorMessage(NLS.bind(Messages.ExportToYouTubePage_error_fetching_category, api.getSiteName(), e));
    }
    if (categories != null)
        catViewer.setInput(categories);
    keywordsButton = WidgetFactory.createCheckButton(group, Messages.ExportToYouTubePage_include_keywords,
            new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1));
    keywordsButton.setSelection(true);
    geoButton = WidgetFactory.createCheckButton(group, Messages.ExportToYouTubePage_include_geo,
            new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1));
    geoButton.setSelection(true);
    setTitle(Messages.ExportToYouTubePage_exporting);
    setMessage(msg);
    fillValues();
    setControl(composite);
    setHelp(HelpContextIds.EXPORT_WIZARD);
    super.createControl(parent);
}