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.nokia.carbide.remoteconnections.settings.ui.ConnectionSettingsPage.java

License:Open Source License

private void createSetupTabComposite(TabFolder tabFolder) {
    TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
    tabItem.setText(Messages.getString("ConnectionSettingsPage.SetupTabLabel")); //$NON-NLS-1$
    tabItem.setData(UID, "setupTab"); //$NON-NLS-1$
    setupTabComposite = new Composite(tabFolder, SWT.NONE);
    setupTabComposite.setLayout(new GridLayout(2, false));
    tabItem.setControl(setupTabComposite);

    boolean canEditConnection = !settingsWizard.isConnectionToEditDynamic();

    Label viewerLabel = new Label(setupTabComposite, SWT.NONE);
    viewerLabel.setText(Messages.getString("ConnectionTypePage.ViewerLabel")); //$NON-NLS-1$

    connectionTypeViewer = new ComboViewer(setupTabComposite, SWT.READ_ONLY);
    connectionTypeViewer.setLabelProvider(new LabelProvider() {
        @Override//from ww w .  j a v  a  2 s  . c o  m
        public String getText(Object element) {
            Check.checkState(element instanceof IConnectionType);
            IConnectionType connectionType = (IConnectionType) element;
            return connectionType.getDisplayName() + " (" + getServicesString(connectionType) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
        }
    });
    connectionTypeViewer.setContentProvider(new ArrayContentProvider());
    connectionTypeViewer.setInput(getConnectionTypes());
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    connectionTypeViewer.getControl().setLayoutData(gd);
    connectionTypeViewer.getControl().setData(UID, "viewer"); //$NON-NLS-1$
    connectionTypeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        private IConnectionType previousSelection;

        public void selectionChanged(SelectionChangedEvent event) {
            Object currentSelection = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (!currentSelection.equals(previousSelection)) {
                settingsWizard.connectionTypeChanged();
                previousSelection = (IConnectionType) currentSelection;
            }
        }
    });
    connectionTypeViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            getWizard().getContainer().showPage(getNextPage());
        }
    });
    connectionTypeViewer.setSorter(new ViewerSorter() {
        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            IConnectionType t1 = (IConnectionType) e1;
            IConnectionType t2 = (IConnectionType) e2;
            return t1.getDisplayName().compareToIgnoreCase(t2.getDisplayName());
        }
    });
    connectionTypeViewer.getCombo().select(getCurrentTypeIndex());
    connectionTypeViewer.getCombo().setEnabled(canEditConnection);

    Label nameLabel = new Label(setupTabComposite, SWT.NONE);
    nameLabel.setText(Messages.getString("ConnectionTypePage.NameLabel")); //$NON-NLS-1$
    nameText = new Text(setupTabComposite, SWT.BORDER);
    gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    nameText.setLayoutData(gd);
    nameText.setToolTipText(Messages.getString("ConnectionTypePage.NameTextToolTip")); //$NON-NLS-1$
    nameText.setData(UID, "nameText"); //$NON-NLS-1$
    nameText.setText(getInitialNameText());
    nameText.selectAll();
    nameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            modifiedName = true;
            setPageComplete(validatePage());
        }
    });
    nameText.setEnabled(canEditConnection);

    createSettingsGroup(setupTabComposite);
}

From source file:com.nokia.carbide.remoteconnections.settings.ui.ConnectionSettingsPage.java

License:Open Source License

private void createDeviceOSCombo(Composite parent) {
    Composite comboComposite = new Composite(parent, SWT.NONE);
    GridData gd_composite = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gd_composite.horizontalSpan = 2;/*from w  ww. ja va2s  .  com*/
    comboComposite.setLayoutData(gd_composite);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    comboComposite.setLayout(gridLayout);

    Label deviceOSLabel = new Label(comboComposite, SWT.NONE);
    GridData gd_sdkLabel = new GridData();
    deviceOSLabel.setLayoutData(gd_sdkLabel);
    deviceOSLabel.setText(Messages.getString("ConnectionSettingsPage.DeviceOSLabel")); //$NON-NLS-1$

    deviceOSComboViewer = new ComboViewer(comboComposite, SWT.READ_ONLY);
    GridData gd_sdkcombo = new GridData(SWT.LEFT, SWT.CENTER, true, false);
    gd_sdkcombo.widthHint = 150;
    deviceOSComboViewer.getCombo().setLayoutData(gd_sdkcombo);
    deviceOSComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @SuppressWarnings("unchecked")
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) deviceOSComboViewer.getSelection();
            Pair<String, String> pair = (Pair<String, String>) selection.getFirstElement();
            setSelectionToInstallComposite(pair);
            if (connectedService instanceof IConnectedService2)
                ((IConnectedService2) connectedService).setDeviceOS(pair.first, pair.second);
        }
    });
    deviceOSComboViewer.setContentProvider(new ArrayContentProvider());
    deviceOSComboViewer.setLabelProvider(new LabelProvider() {
        @SuppressWarnings({ "unchecked", "rawtypes" })
        @Override
        public String getText(Object element) {
            Check.checkState(element instanceof Pair);
            Pair<String, Version> pair = (Pair) element;
            return MessageFormat.format("{0} {1}", pair.first, pair.second); //$NON-NLS-1$
        }
    });
    deviceOSComboViewer.getControl()
            .setToolTipText(Messages.getString("ConnectionSettingsPage.DeviceOSComboToolTip")); //$NON-NLS-1$
    deviceOSComboViewer.getControl().setData(UID, "deviceOSComboViewer"); //$NON-NLS-1$
}

From source file:com.nokia.carbide.remoteconnections.settings.ui.ConnectionSettingsPage.java

License:Open Source License

private void createServiceTestComposite(Composite parent) {
    Composite serviceSelectionComposite = new Composite(parent, SWT.NONE);
    serviceSelectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    serviceSelectionComposite.setLayout(new GridLayout());
    Label label = new Label(serviceSelectionComposite, SWT.NONE);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    label.setText(Messages.getString("ConnectionSettingsPage.ServicesListLabel")); //$NON-NLS-1$
    servicesListViewer = new ListViewer(serviceSelectionComposite,
            SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridData gd_viewer = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
    servicesListViewer.getControl().setLayoutData(gd_viewer);
    servicesListViewer.setContentProvider(new ArrayContentProvider());
    servicesListViewer.setLabelProvider(new LabelProvider() {
        @Override/*from w  ww .  ja  va  2 s.  c o  m*/
        public String getText(Object element) {
            if (element instanceof IService)
                return ((IService) element).getDisplayName();
            return null;
        }
    });
    servicesListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) servicesListViewer.getSelection();
            IService curService = (IService) selection.getFirstElement();
            if (!curService.equals(service)) {
                service = curService;
                serviceTestButton.setEnabled(service.isTestable());
                resetServiceTesting(true);
            }
        }
    });
    servicesListViewer.getControl()
            .setToolTipText(Messages.getString("ConnectionSettingsPage.ServicesListToolTip")); //$NON-NLS-1$
    servicesListViewer.getControl().setData(UID, "servicesListViewer"); //$NON-NLS-1$

    Composite testButtonComposite = new Composite(parent, SWT.NONE);
    testButtonComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    testButtonComposite.setLayout(new GridLayout());
    serviceTestInfo = new Text(testButtonComposite, SWT.READ_ONLY | SWT.WRAP);
    serviceTestButton = new Button(testButtonComposite, SWT.PUSH);
    GridData gd_button = new GridData(SWT.CENTER, SWT.CENTER, false, false);
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    serviceTestButton.setText(Messages.getString("ConnectionSettingsPage.StartServiceTestButtonLabel")); //$NON-NLS-1$
    Point minSize = serviceTestButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd_button.widthHint = Math.max(widthHint, minSize.x);
    GridData gd_text = new GridData(SWT.CENTER, SWT.FILL, true, true);
    gd_text.widthHint = gd_button.widthHint;
    serviceTestInfo.setLayoutData(gd_text);
    serviceTestInfo.setData(UID, "serviceTestInfo"); //$NON-NLS-1$
    serviceTestButton.setLayoutData(gd_button);
    serviceTestButton.setToolTipText(Messages.getString("ConnectionSettingsPage.ServiceTestButtonToolTip")); //$NON-NLS-1$
    serviceTestButton.setData(UID, "serviceTestButton"); //$NON-NLS-1$
    serviceTestButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (isTesting) {
                serviceTestButton
                        .setText(Messages.getString("ConnectionSettingsPage.StartServiceTestButtonLabel")); //$NON-NLS-1$
                resetServiceTesting(true);
            } else {
                serviceTestButton
                        .setText(Messages.getString("ConnectionSettingsPage.StopServiceTestButtonLabel")); //$NON-NLS-1$
                testService();
            }
        }
    });

    Composite statusComposite = new Composite(parent, SWT.NONE);
    statusComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    statusComposite.setLayout(new GridLayout());
    statusLabel = new Label(statusComposite, SWT.NONE);
    statusLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
    statusLabel.setText(Messages.getString("ConnectionSettingsPage.StatusLabel")); //$NON-NLS-1$
    statusText = new Text(statusComposite, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.WRAP);
    statusText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    statusText.setText(STATUS_NOT_TESTED);
    statusText.setData(UID, "statusText"); //$NON-NLS-1$
}

From source file:com.nokia.carbide.remoteconnections.settings.ui.ConnectionSettingsPage.java

License:Open Source License

private void createInstallTabComposite(TabFolder tabFolder) {
    TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
    tabItem.setText(Messages.getString("ConnectionSettingsPage.InstallTabLabel")); //$NON-NLS-1$
    tabItem.setData(UID, "installTab"); //$NON-NLS-1$
    Composite composite = new Composite(tabFolder, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    composite.setLayout(gridLayout);//from   ww w  .  j  ava  2s.  co  m
    tabItem.setControl(composite);

    Composite installDebugAgentComposite = new Composite(tabFolder, SWT.NONE);
    installDebugAgentComposite.setLayout(new GridLayout(1, false));
    tabItem.setControl(installDebugAgentComposite);

    installerSashForm = new SashForm(installDebugAgentComposite, SWT.HORIZONTAL);
    GridData gd_sash = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd_sash.widthHint = 420;
    gd_sash.heightHint = 280;
    installerSashForm.setLayoutData(gd_sash);

    installerTreeViewer = new TreeViewer(installerSashForm, SWT.BORDER);
    GridData gd_tree = new GridData(SWT.CENTER, SWT.CENTER, false, false);
    installerTreeViewer.getTree().setLayoutData(gd_tree);
    installerTreeViewer.getControl().setData(UID, "installerTreeViewer"); //$NON-NLS-1$
    installerTreeViewer.setContentProvider(new TreeNodeContentProvider());
    installerTreeViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            TreeNode node = (TreeNode) element;
            Object value = node.getValue();
            if (value instanceof IRemoteAgentInstaller) {
                String label = ((IRemoteAgentInstaller) value).getLabel();
                return label == null ? Messages.getString("ConnectionSettingsPage.UnlabeledPackageLabel") //$NON-NLS-1$
                        : label;
            }
            return value.toString();
        }

        @Override
        public Image getImage(Object element) {
            if (element.equals(LOADING_CONTENT_TREENODE))
                return null;

            TreeNode node = (TreeNode) element;
            Object value = node.getValue();
            if (value instanceof IRemoteAgentInstaller)
                return ((IRemoteAgentInstaller) value).getImage();

            return FOLDER_ICON_IMG;
        }
    });
    installerTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            TreeNode node = (TreeNode) ((StructuredSelection) event.getSelection()).getFirstElement();
            if (node == null)
                return;
            Object value = node.getValue();
            boolean isPackage = value instanceof IRemoteAgentInstaller;
            boolean installable = false;
            String information = null;
            if (isPackage) {
                IRemoteAgentInstaller installer = (IRemoteAgentInstaller) value;
                installable = installer.fileSupportsInstall();
                information = installer.getInformation();
            }
            if (information != null)
                installerInfoText.setText(information);
            else
                installerInfoText.setText(""); //$NON-NLS-1$
            installButton.setEnabled(isPackage && installable);
            installerSaveButton.setEnabled(isPackage);
        }
    });

    installerInfoText = new Text(installerSashForm, SWT.READ_ONLY | SWT.BORDER | SWT.WRAP);
    String errorText = Messages.getString("ConnectionSettingsPage.NoInstallerDataInfoString"); //$NON-NLS-1$
    errorText += "\n" + Messages.getString("ConnectionSettingsPage.NoInstallerDataInfoString2"); //$NON-NLS-1$ //$NON-NLS-2$
    installerInfoText.setText(errorText);
    installerInfoText.setData(UID, "installerInfoText"); //$NON-NLS-1$
    installerSashForm.setWeights(new int[] { 160, 100 });

    Composite buttonsArea = new Composite(installDebugAgentComposite, SWT.NONE);
    buttonsArea.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
    gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    buttonsArea.setLayout(gridLayout);

    installerSaveButton = new Button(buttonsArea, SWT.NONE);
    final GridData gd_saveButton = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
    gd_saveButton.widthHint = 125;
    installerSaveButton.setLayoutData(gd_saveButton);
    installerSaveButton.setText(Messages.getString("ConnectionSettingsPage.SaveButtonLabel")); //$NON-NLS-1$
    installerSaveButton.setEnabled(false);
    installerSaveButton.setToolTipText(Messages.getString("ConnectionSettingsPage.SaveButtonToolTip")); //$NON-NLS-1$
    installerSaveButton.setData(UID, "installerSaveButton"); //$NON-NLS-1$
    installerSaveButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Display.getDefault().syncExec(new Runnable() {
                public void run() {
                    try {
                        IRemoteAgentInstaller installer = getCurrentInstaller();
                        saveAs(installer.getPackageContents(getContainer()));
                    } catch (Exception e) {
                        RemoteConnectionsActivator.logError(e);
                    }
                }
            });
        }
    });

    installButton = new Button(buttonsArea, SWT.NONE);
    final GridData gd_installButton = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
    gd_installButton.widthHint = 125;
    installButton.setLayoutData(gd_installButton);
    installButton.setText(Messages.getString("ConnectionSettingsPage.InstallButtonLabel")); //$NON-NLS-1$
    installButton.setEnabled(false);
    installButton.setToolTipText(Messages.getString("ConnectionSettingsPage.InstallButtonToolTip")); //$NON-NLS-1$
    installButton.setData(UID, "installButton"); //$NON-NLS-1$
    installButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Display.getDefault().syncExec(new Runnable() {
                public void run() {
                    try {
                        IRemoteAgentInstaller installer = getCurrentInstaller();
                        attemptInstall(installer.getPackageContents(getContainer()));
                    } catch (Exception e) {
                        RemoteConnectionsActivator.logError(e);
                    }
                }
            });
        }
    });
}

From source file:com.nokia.carbide.remoteconnections.settings.ui.ConnectionTypePage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    container.setData(UID, "ConnectionTypePage"); //$NON-NLS-1$

    Label nameLabel = new Label(container, SWT.NONE);
    nameLabel.setText(Messages.getString("ConnectionTypePage.NameLabel")); //$NON-NLS-1$
    nameText = new Text(container, SWT.BORDER);
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    nameText.setLayoutData(gd);/*from w  w  w.  j  a  v  a2 s.  c om*/
    nameText.setToolTipText(Messages.getString("ConnectionTypePage.NameTextToolTip")); //$NON-NLS-1$
    nameText.setData(UID, "nameText"); //$NON-NLS-1$
    nameText.setText(getInitialNameText());
    nameText.selectAll();
    nameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            setPageComplete(validatePage());
        }
    });
    boolean canEditConnection = !settingsWizard.isConnectionToEditDynamic();
    nameText.setEnabled(canEditConnection);

    Label label = new Label(container, SWT.NONE);
    label.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
    label.setText(Messages.getString("ConnectionTypePage.ViewerLabel")); //$NON-NLS-1$

    viewer = new ListViewer(container, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL);
    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            Check.checkState(element instanceof IConnectionType);
            IConnectionType connectionType = (IConnectionType) element;
            return connectionType.getDisplayName();
        }
    });
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setInput(getConnectionTypes());
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    viewer.getControl().setLayoutData(gd);
    viewer.getControl().setData(UID, "viewer"); //$NON-NLS-1$
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        private IConnectionType previousSelection;

        public void selectionChanged(SelectionChangedEvent event) {
            Object currentSelection = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (!currentSelection.equals(previousSelection)) {
                connectionTypeDescLabel.setText(getConnectionTypeDescription());
                servicesLabel.setText(getServicesString());
                settingsWizard.connectionTypeChanged();
                previousSelection = (IConnectionType) currentSelection;
            }
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            getWizard().getContainer().showPage(getNextPage());
        }
    });
    viewer.setSorter(new ViewerSorter() {
        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            IConnectionType t1 = (IConnectionType) e1;
            IConnectionType t2 = (IConnectionType) e2;
            return t1.getDisplayName().compareToIgnoreCase(t2.getDisplayName());
        }
    });
    viewer.getList().select(getCurrentTypeIndex());
    viewer.getList().setEnabled(canEditConnection);

    connectionTypeDescLabel = new Label(container, SWT.WRAP);
    connectionTypeDescLabel.setText(getConnectionTypeDescription());
    gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gd.horizontalSpan = 2;
    connectionTypeDescLabel.setLayoutData(gd);
    connectionTypeDescLabel.setData(UID, "additionalNotesLabel"); //$NON-NLS-1$

    servicesLabel = new Label(container, SWT.WRAP);
    servicesLabel.setText(getServicesString());
    gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gd.horizontalSpan = 2;
    servicesLabel.setLayoutData(gd);
    servicesLabel.setData(UID, "servicesLabel"); //$NON-NLS-1$

    setControl(container);
    RemoteConnectionsActivator.setHelp(container, ".connection_type_page"); //$NON-NLS-1$
}

From source file:com.nokia.carbide.remoteconnections.ui.ClientServiceSiteUI.java

License:Open Source License

public void createComposite(Composite parent) {
    initializeDialogUnits(parent);/*  ww  w .j a va  2 s . c  om*/
    Group group = new Group(parent, SWT.NONE);
    group.setText(Messages.getString("ClientServiceSiteUI.UseConnectionGroupLabel")); //$NON-NLS-1$
    group.setLayout(new GridLayout());
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    group.setData(UID, "useConnectionGroup"); //$NON-NLS-1$

    viewer = new ComboViewer(group, SWT.READ_ONLY);
    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            Check.checkContract(element instanceof IConnection);
            return ((IConnection) element).getDisplayName();
        }
    });
    viewer.setContentProvider(new ArrayContentProvider());
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    viewer.getCombo().setLayoutData(gd);
    viewer.getControl().setData(UID, "viewer"); //$NON-NLS-1$
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            IConnection connection = (IConnection) selection.getFirstElement();
            if (!connection.equals(ClientServiceSiteUI.this.connection)) {
                ClientServiceSiteUI.this.connection = connection;
                fireConnectionSelected();
            }
        }
    });

    final Composite composite = new Composite(group, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    layout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_MARGIN);
    layout.marginHeight = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_MARGIN);
    layout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_SPACING);
    layout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_SPACING);
    composite.setLayout(layout);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_CENTER);
    composite.setLayoutData(gd);
    composite.setFont(parent.getFont());

    newButton = new Button(composite, SWT.PUSH);
    newButton.setText(Messages.getString("ClientServiceSiteUI.NewButtonLabel")); //$NON-NLS-1$
    newButton.setFont(JFaceResources.getDialogFont());
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd.widthHint = Math.max(widthHint, minSize.x);
    newButton.setLayoutData(gd);
    newButton.setData(UID, "newButton"); //$NON-NLS-1$
    newButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            SettingsWizard wizard = new SettingsWizard(null, service);
            wizard.open(composite.getShell());
            setViewerInput(wizard.getConnectionToEdit());
        }
    });

    editButton = new Button(composite, SWT.PUSH);
    editButton.setText(Messages.getString("ClientServiceSiteUI.EditButtonLabel")); //$NON-NLS-1$
    editButton.setFont(JFaceResources.getDialogFont());
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd.widthHint = Math.max(widthHint, minSize.x);
    editButton.setLayoutData(gd);
    editButton.setData(UID, "editButton"); //$NON-NLS-1$
    editButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object value = selection.getFirstElement();
            if (value instanceof IConnection) {
                SettingsWizard wizard = new SettingsWizard((IConnection) value, service);
                wizard.open(composite.getShell());
                setViewerInput(wizard.getConnectionToEdit());
            }
        }
    });

    setViewerInput(null);
}

From source file:com.nokia.carbide.search.system.internal.ui.SearchDialog.java

License:Open Source License

private void handleCustomizePressed() {
    List input = SearchPlugin.getDefault().getSearchPageDescriptors();
    input = filterByActivities(input);//from   w  w  w .jav  a2s.  co  m

    final ArrayList createdImages = new ArrayList(input.size());
    ILabelProvider labelProvider = new LabelProvider() {
        public String getText(Object element) {
            if (element instanceof SearchPageDescriptor)
                return LegacyActionTools.removeMnemonics(((SearchPageDescriptor) element).getLabel());
            return null;
        }

        public Image getImage(Object element) {
            if (element instanceof SearchPageDescriptor) {
                ImageDescriptor imageDesc = ((SearchPageDescriptor) element).getImage();
                if (imageDesc == null)
                    return null;
                Image image = imageDesc.createImage();
                if (image != null)
                    createdImages.add(image);
                return image;
            }
            return null;
        }
    };

    String message = SearchMessages.SearchPageSelectionDialog_message;

    ListSelectionDialog dialog = new ListSelectionDialog(getShell(), input, new ArrayContentProvider(),
            labelProvider, message) {
        public void create() {
            super.create();
            final CheckboxTableViewer viewer = getViewer();
            final Button okButton = this.getOkButton();
            viewer.addCheckStateListener(new ICheckStateListener() {
                public void checkStateChanged(CheckStateChangedEvent event) {
                    okButton.setEnabled(viewer.getCheckedElements().length > 0);
                }
            });
            SelectionListener listener = new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    okButton.setEnabled(viewer.getCheckedElements().length > 0);
                }
            };
            this.getButton(IDialogConstants.SELECT_ALL_ID).addSelectionListener(listener);
            this.getButton(IDialogConstants.DESELECT_ALL_ID).addSelectionListener(listener);
        }
    };
    dialog.setTitle(SearchMessages.SearchPageSelectionDialog_title);
    dialog.setInitialSelections(
            SearchPlugin.getDefault().getEnabledSearchPageDescriptors(fInitialPageId).toArray());
    if (dialog.open() == Window.OK) {
        SearchPageDescriptor.setEnabled(dialog.getResult());
        Display display = getShell().getDisplay();
        close();
        if (display != null && !display.isDisposed()) {
            display.asyncExec(new Runnable() {
                public void run() {
                    new OpenSearchDialogAction().run();
                }
            });
        }
    }
    destroyImages(createdImages);
}

From source file:com.nokia.carbide.trk.support.connection.SerialConnectionFactory.java

License:Open Source License

private void createComboForSettings(Composite composite, String labelStr, final String key, String[] input) {
    Label label = new Label(composite, SWT.NONE);
    label.setText(labelStr);/*from   w w w.  jav a  2  s. co  m*/

    final ComboViewer viewer = new ComboViewer(composite, SWT.READ_ONLY);
    viewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            int index = SerialConnectionSettings.toIndex(key, element.toString());
            return SerialConnectionSettings.toDisplayString(key, index);
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            int index = viewer.getCombo().getSelectionIndex();
            settings.setByIndex(key, index);
        }
    });
    viewer.setInput(input);
    viewer.getControl().setData(".uid", "SerialConnectionFactory." + key); //$NON-NLS-1$ //$NON-NLS-2$
    viewers.put(key, viewer);
}

From source file:com.nokia.cdt.internal.debug.launch.newwizard.ConnectToDeviceDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    initializeDialogUnits(parent);/*w w  w  .j  a  va2 s. co m*/
    final Composite composite = initDialogArea(parent, Messages.getString("ConnectToDeviceDialog.Title"), //$NON-NLS-1$
            LaunchWizardHelpIds.WIZARD_DIALOG_CHANGE_CONNECTION);

    Group viewerGroup = new Group(composite, SWT.NONE);
    viewerGroup.setText(Messages.getString("ConnectToDeviceDialog.GroupLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().applyTo(viewerGroup);
    GridLayoutFactory.swtDefaults().applyTo(viewerGroup);

    viewer = new ComboViewer(viewerGroup, SWT.READ_ONLY);
    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof IConnection)
                return ((IConnection) element).getDisplayName();

            return Messages.getString("ConnectToDeviceDialog.NoCurrentItem"); //$NON-NLS-1$
        }
    });
    viewer.setContentProvider(new ArrayContentProvider());
    Combo combo = viewer.getCombo();
    GridDataFactory.defaultsFor(combo).grab(true, false).applyTo(combo);
    viewer.getControl().setData(UID, "combo_viewer"); //$NON-NLS-1$
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            if (getDialogArea() != null)
                connectionSelected(getConnectionFromSelection(event.getSelection()));
        }
    });
    manager.addConnectionListener(this);

    parent.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            manager.removeConnectionListener(ConnectToDeviceDialog.this);

            if (currentServiceListener != null)
                currentServiceListener.removeStatusChangedListener(ConnectToDeviceDialog.this);
        }
    });

    final Composite buttonGroup = new Composite(viewerGroup, SWT.NONE);
    int w = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_MARGIN);
    int h = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_MARGIN);
    int hs = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_SPACING);
    int vs = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_SPACING);
    GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(true).margins(w, h).spacing(hs, vs)
            .applyTo(buttonGroup);
    GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).applyTo(buttonGroup);
    buttonGroup.setFont(parent.getFont());

    newButton = new Button(buttonGroup, SWT.PUSH);
    newButton.setText(Messages.getString("ConnectToDeviceDialog.NewLabel")); //$NON-NLS-1$
    newButton.setFont(JFaceResources.getDialogFont());
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    widthHint = Math.max(widthHint, minSize.x);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.TOP).hint(widthHint, SWT.DEFAULT).applyTo(newButton);
    newButton.setData(UID, "newButton"); //$NON-NLS-1$
    newButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            SettingsWizard wizard = new SettingsWizard(null, connectionData.getService());
            wizard.open(composite.getShell());
            IConnection connection = wizard.getConnectionToEdit();
            setViewerInput(connection);
        }
    });

    editButton = new Button(buttonGroup, SWT.PUSH);
    editButton.setText(Messages.getString("ConnectToDeviceDialog.EditLabel")); //$NON-NLS-1$
    editButton.setFont(JFaceResources.getDialogFont());
    widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    widthHint = Math.max(widthHint, minSize.x);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).hint(widthHint, SWT.DEFAULT).applyTo(editButton);
    editButton.setData(UID, "editButton"); //$NON-NLS-1$
    editButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IConnection connection = getConnectionFromSelection(viewer.getSelection());
            if (connection != null) {
                SettingsWizard wizard = new SettingsWizard(connection, connectionData.getService());
                wizard.open(composite.getShell());
            }
        }
    });

    descriptionLabel = new Label(composite, SWT.WRAP);
    GridDataFactory.defaultsFor(descriptionLabel).grab(false, true).applyTo(descriptionLabel);
    composite.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            descriptionLabel.pack();
        }
    });

    setViewerInput(connectionData.getConnection());

    return composite;
}

From source file:com.nokia.cdt.internal.debug.launch.newwizard.DebugRunProcessDialog.java

License:Open Source License

/**
 * Allow selecting an executable detected to be built by the program.
 * @param radioGroup//from ww  w. j  av a  2s .c om
 */
private void createProjectExecutableRadioButton(Composite radioGroup) {
    projectExecutableRadioButton = new Button(radioGroup, SWT.RADIO);
    GridDataFactory.fillDefaults().grab(false, false).applyTo(projectExecutableRadioButton);
    projectExecutableRadioButton.setText(Messages.getString("DebugRunProcessDialog.LaunchProjectExeLabel")); //$NON-NLS-1$
    projectExecutableRadioButton.setData(UID, "radio_project_executable"); //$NON-NLS-1$
    projectExecutableRadioButton
            .setToolTipText(Messages.getString("DebugRunProcessDialog.LaunchProjectExecutableRadioTooltip")); //$NON-NLS-1$

    projectExecutableViewer = new ComboViewer(radioGroup, SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(projectExecutableViewer.getControl());
    projectExecutableViewer.getControl().setData(UID, "combo_project_executable"); //$NON-NLS-1$
    projectExecutableViewer.getControl()
            .setToolTipText(Messages.getString("DebugRunProcessDialog.LaunchProjectExecutableSelectorTooltip")); //$NON-NLS-1$

    projectExecutableViewer.setContentProvider(new ArrayContentProvider());
    projectExecutableViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof IPath)
                return ((IPath) element).lastSegment();
            return super.getText(element);
        }
    });

    projectExecutableRadioButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            handleProjectExecutableRadioSelected();
        }

    });

    projectExecutableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            Object sel = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (sel instanceof IPath) {
                if (projectExecutableRadioButton.getSelection()) {
                    debugRunProcessWizardData.setExeSelectionPath((IPath) sel);
                }

                // track the default remote program from the executable, for easy editing
                if (remoteProgramViewer != null && !remoteExecutableRadioButton.getSelection()) {
                    IPath exeSelectionPath = createSuggestedRemotePath(
                            debugRunProcessWizardData.getExeSelectionPath());
                    // path should already be in model
                    remoteProgramViewer.setSelection(new StructuredSelection(exeSelectionPath));
                }

                validate();
            }
        }
    });
}