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.motorola.studio.android.wizards.monkey.DeviceSelectionDialog.java

License:Apache License

/**
* Default constructor /*from   ww w.  ja va 2 s . c  o m*/
* 
* @param parent Parent shell
* @param description Dialog description
*/
public DeviceSelectionDialog(Shell parent, String description) {
    super(parent, new LabelProvider() {
        @Override
        public String getText(Object element) {
            String result = "";
            if (element instanceof ISerialNumbered) {
                ISerialNumbered serialNumbered = (ISerialNumbered) element;
                result = serialNumbered.getFullName();
            }
            return result;
        }

    });

    this.setTitle(AndroidNLS.UI_MonkeyComposite_SelectDeviceScreenTitle);
    this.setMessage(description);

    Collection<ISerialNumbered> instances = DevicesManager.getInstance().getAllDevices();

    if ((instances != null) && (instances.size() > 0)) {

        Collection<ISerialNumbered> filteredInstances = new LinkedList<ISerialNumbered>();

        for (ISerialNumbered instance : instances) {
            if (DDMSFacade.isDeviceOnline(instance.getSerialNumber())) {
                filteredInstances.add(instance);
            }
        }
        Object[] filteredInstancesArray = filteredInstances.toArray();
        this.setElements(filteredInstancesArray);
    }

    this.setHelpAvailable(true);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, DEV_SELECTION_CONTEXT_HELP_ID);
}

From source file:com.motorolamobility.studio.android.db.core.command.UnmapDatabaseHandler.java

License:Apache License

@SuppressWarnings({ "unchecked", "rawtypes" })
private List<ITreeNode> queryDbPath(List<ITreeNode> mappedDbNodes) {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

    ElementListSelectionDialog listDialog = new ElementListSelectionDialog(shell, new LabelProvider() {
        /* (non-Javadoc)
         * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
         *//*  w  w w.  ja v a2s  .  com*/
        @Override
        public String getText(Object element) {
            if (element instanceof IDbNode) {
                IDbNode dbNode = (IDbNode) element;
                return dbNode.getName();
            }
            return super.getText(element);
        }
    });
    listDialog.setElements(mappedDbNodes.toArray());
    listDialog.setTitle(DbCoreNLS.UI_UnmapDatabaseAction_Title);
    listDialog.setBlockOnOpen(true);
    listDialog.setMultipleSelection(true);
    listDialog.open();
    Object[] result = listDialog.getResult();
    List asList = Arrays.asList(result);
    List<ITreeNode> checkedList = Collections.checkedList(asList, ITreeNode.class);
    return checkedList;
}

From source file:com.mountainminds.eclemma.internal.ui.handlers.SelectActiveSessionHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    final ListDialog dialog = new ListDialog(HandlerUtil.getActiveShell(event)) {
        protected void configureShell(Shell shell) {
            super.configureShell(shell);
            ContextHelp.setHelp(shell, ContextHelp.SELECT_ACTIVE_SESSION);
        }/*from  ww w  .  j  a v  a2s.co  m*/
    };
    dialog.setTitle(UIMessages.SelectActiveSessionDialog_title);
    dialog.setMessage(UIMessages.SelectActiveSessionDialog_message);
    dialog.setContentProvider(new ArrayContentProvider());
    dialog.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((ICoverageSession) element).getDescription();
        }

        @Override
        public Image getImage(Object element) {
            return EclEmmaUIPlugin.getImage(EclEmmaUIPlugin.OBJ_SESSION);
        }
    });
    dialog.setInitialElementSelections(Collections.singletonList(sessionManager.getActiveSession()));
    dialog.setInput(sessionManager.getSessions());
    if (dialog.open() == Dialog.OK) {
        final Object[] result = dialog.getResult();
        if (result.length == 1) {
            sessionManager.activateSession((ICoverageSession) result[0]);
        }
    }
    return null;
}

From source file:com.mountainminds.eclemma.internal.ui.wizards.SessionExportPage1.java

License:Open Source License

private void createExportOptionsGroup(Composite parent) {
    parent.setLayout(new GridLayout(3, false));
    new Label(parent, SWT.NONE).setText(UIMessages.ExportReportPage1Format_label);
    formatcombo = new ComboViewer(parent, SWT.READ_ONLY);
    formatcombo.setContentProvider(new ArrayContentProvider());
    formatcombo.setLabelProvider(new LabelProvider() {
        @Override//from  w  w  w  .ja  v a 2  s.co  m
        public String getText(Object element) {
            return ((ExportFormat) element).getLabel();
        }
    });
    formatcombo.setInput(ExportFormat.values());
    formatcombo.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IPath path = Path.fromOSString(destinationcombo.getText());
            path = path.removeFileExtension();
            final ExportFormat format = getExportFormat();
            if (!format.isFolderOutput()) {
                path = path.addFileExtension(format.getFileExtension());
            }
            destinationcombo.setText(path.toOSString());
        }
    });
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    formatcombo.getControl().setLayoutData(gd);
    new Label(parent, SWT.NONE).setText(UIMessages.ExportReportPage1Destination_label);
    destinationcombo = new Combo(parent, SWT.BORDER);
    destinationcombo.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            update();
        }
    });
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = convertHorizontalDLUsToPixels(120);
    destinationcombo.setLayoutData(gd);
    Button browsebutton = new Button(parent, SWT.NONE);
    browsebutton.setText(UIMessages.BrowseAction_label);
    setButtonLayoutData(browsebutton);
    browsebutton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (getExportFormat().isFolderOutput()) {
                openFolderDialog();
            } else {
                openFileDialog();
            }
        }
    });
    update();
}

From source file:com.mousefeed.eclipse.preferences.presentation.PresentationModePreferencePage.java

License:Open Source License

protected void addItem(TableViewer viewer) {

    Scheme initialValue = bindingService.getActiveScheme();
    List<Scheme> input = Arrays.asList(bindingService.getDefinedSchemes());

    IBaseLabelProvider labelProvider = new LabelProvider() {
        @Override/*ww w  . j a va 2 s . c om*/
        public String getText(Object element) {
            try {
                return ((Scheme) element).getName();
            } catch (NotDefinedException e) {
                Activator.getDefault().getLog().log(
                        new Status(IStatus.WARNING, Activator.PLUGIN_ID, "Could not get label for scheme", e));
                return "(Undefined)";
            }
        }
    };
    ComboInputDialog<Scheme> comboInputDialog = new ComboInputDialog<Scheme>(getShell(), "Select Scheme",
            "Select the Scheme which should be added to the configuration", initialValue, input, labelProvider);
    if (comboInputDialog.open() == Window.OK) {
        Scheme value = comboInputDialog.getValue();
        SchemeConfig config = new SchemeConfig(value.getId());
        preferences.addPresentationModeSchemeConfigs(config);
        viewer.refresh();
        viewer.setSelection(new StructuredSelection(config), true);
    }

}

From source file:com.netxforge.netxstudio.callflow.screens.protocols.NewEditProtocol.java

License:Open Source License

public EMFDataBindingContext initDataBindings_() {
    EMFDataBindingContext context = new EMFDataBindingContext();

    // text widgets. 

    IObservableValue nameObservable = SWTObservables.observeText(txtName, SWT.Modify);

    IObservableValue specificationObservable = SWTObservables.observeText(this.txtSpecification, SWT.Modify);

    IObservableValue descriptionObservable = SWTObservables.observeText(txtDescription, SWT.Modify);

    // Properties
    IEMFValueProperty nameProperty = EMFEditProperties.value(editingService.getEditingDomain(),
            ProtocolsPackage.Literals.PROTOCOL__NAME);

    IEMFValueProperty descriptionProperty = EMFEditProperties.value(editingService.getEditingDomain(),
            ProtocolsPackage.Literals.PROTOCOL__DESCRIPTION);

    IEMFValueProperty specificationProperty = EMFEditProperties.value(editingService.getEditingDomain(),
            ProtocolsPackage.Literals.PROTOCOL__SPECIFICATION);

    context.bindValue(nameObservable, nameProperty.observe(protocol), null, null);
    context.bindValue(descriptionObservable, descriptionProperty.observe(protocol), null, null);
    context.bindValue(specificationObservable, specificationProperty.observe(protocol), null, null);

    // Combo viewer. 

    cmbLevelViewer.setContentProvider(new ArrayContentProvider());
    cmbLevelViewer.setLabelProvider(new LabelProvider());
    cmbLevelViewer.setInput(OSIType.VALUES);

    IEMFValueProperty osiProperty = EMFEditProperties.value(editingService.getEditingDomain(),
            ProtocolsPackage.Literals.PROTOCOL__OSI);
    IValueProperty selectionProperty = ViewerProperties.singleSelection();

    context.bindValue(selectionProperty.observe(cmbLevelViewer), osiProperty.observe(protocol), null, null);

    return context;
}

From source file:com.netxforge.netxstudio.callflow.screens.referenceNetwork.ComboBoxCellEditingSupport.java

License:Open Source License

public ComboBoxCellEditingSupport(ColumnViewer viewer, DataBindingContext dbc, Composite control,
        EditingDomain domain, FeaturePath path) {
    super(viewer, dbc);

    this.editingDomain = domain;
    this.path = path;

    cellEditor = new ComboBoxViewerCellEditor(control, SWT.READ_ONLY);

    // TODO, In a better version, use the editing service adapterfactory for
    // naming./*w w  w  .  ja  v a2s  . c  o m*/
    cellEditor.setLabelProvider(new LabelProvider() {

        /*
         * (non-Javadoc)
         * 
         * @see
         * org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            if (element instanceof NodeType) {
                return ((NodeType) element).getName();
            } else if (element instanceof Protocol) {
                return ((Protocol) element).getName();
            } else if (element instanceof ReferenceRelationship) {

                ReferenceRelationship rel = (ReferenceRelationship) element;
                NodeType nt1 = rel.getRefInterface1Ref();
                NodeType nt2 = rel.getRefInterface2Ref();

                StringBuffer buf = new StringBuffer();
                buf.append(" (");
                buf.append(nt1 != null ? nt1.getName() : " ?");
                buf.append(" <--> ");
                buf.append(nt2 != null ? nt2.getName() : " ?");
                buf.append(")");

                String name = rel.getName();
                return name != null ? name : buf.toString();
            } else if (element instanceof ServiceFlowDirection) {
                switch (((ServiceFlowDirection) element).getValue()) {
                case ServiceFlowDirection.LEFTTORIGHT_VALUE: {
                    return "-->";
                }
                case ServiceFlowDirection.RIGHTTOLEFT_VALUE: {
                    return "<--";
                }
                }
            } else if (element instanceof Message) {
                Message m = (Message) element;
                String name = m.getName();
                return name;
            }
            return super.getText(element);
        }

    });
    ObservableListContentProvider listContentProvider = new ObservableListContentProvider();
    cellEditor.setContentProvider(listContentProvider);

}

From source file:com.netxforge.netxstudio.callflow.screens.ServiceFlowFilterDialog.java

License:Open Source License

/**
 * Create a new dialog//w w  w.  j  a  va  2  s. c o m
 * 
 * @param shell
 *            the parent shell
 * @param resource
 *            the model resource
 */
public ServiceFlowFilterDialog(Shell shell, Resource resource) {
    super(shell, true);
    setTitle("Select an existing Service Flow");
    this.resource = resource;

    setListLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element == null) {
                return "";
            }
            return ServiceFlowFilterDialog.this.getText(

                    (ServiceFlow) element

            );
        }
    });

    setDetailsLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element == null) {
                return "";
            } else if (element instanceof String) {
                return (String) element;
            }
            return ServiceFlowFilterDialog.this.getText((ServiceFlow) element);
        }
    });
}

From source file:com.netxforge.netxstudio.screens.AbstractSmartTableScreen.java

License:Open Source License

protected IBaseLabelProvider delegateGetListLabelProvider() {
    return new LabelProvider() {

        @Override// w  w  w  .ja  va2  s .  c  o m
        public String getText(Object element) {
            return adapterFactoryItemDelegator.getText(element);
        }
    };
}

From source file:com.netxforge.netxstudio.screens.dialog.ComponentFilterDialog.java

License:Open Source License

/**
 * Create a new dialog//from  w  w  w. j  av  a 2  s  .  c  o  m
 * 
 * @param shell
 *            the parent shell
 * @param scope
 *            the model resource
 */
public ComponentFilterDialog(Shell shell, Object scope) {
    super(shell);
    super.setTitle("Select a Component");
    this.scope = scope;

    setListLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element == null) {
                return "";
            }
            return ComponentFilterDialog.this.getParentText((Component) element) + " -- "
                    + ComponentFilterDialog.this.getText((Component) element);
        }
    });

    setDetailsLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element == null) {
                return "";
            }
            return ComponentFilterDialog.this.getParentText((Component) element);
        }
    });
}