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:eu.esdihumboldt.hale.io.csv.ui.DefaultSchemaTypePage.java

License:Open Source License

/**
 * Update all fields (should be called if page is initialized or the
 * selection of input (file or table) has been changed
 *///from   w ww.j a  v a  2 s .c  om
protected void update() {
    int length = 0;

    // the header is not valid so clear all content
    if (header == null || header.length == 0) {
        // clear properties
        clearPage();
        return;
    }

    if (secondRow == null || secondRow.length == 0) {
        secondRow = header;
    }

    if (header.length != 0) {
        length = header.length;
    }

    // dispose all property names if the read configuration has been changed
    if (lastSecondRow != null && !Arrays.equals(header, lastSecondRow)) {
        for (TypeNameField properties : fields) {
            properties.dispose();
            properties.getTextControl(group).dispose();
            properties.getLabelControl(group).dispose();
        }
        for (ComboViewer combViewer : comboFields) {
            combViewer.getCombo().dispose();
        }
        fields.clear();
        comboFields.clear();
    }

    if (!Arrays.equals(header, lastSecondRow)) {
        for (int i = 0; i < length; i++) {
            final TypeNameField propField;
            final ComboViewer cv;

            validSel.add(true);

            propField = new TypeNameField("properties", Integer.toString(i + 1), group);
            fields.add(propField);
            propField.setEmptyStringAllowed(false);
            propField.setErrorMessage("Please enter a valid Property Name");
            propField.setPropertyChangeListener(new IPropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent event) {

                    HashSet<String> hs = new HashSet<String>();

                    if (event.getProperty().equals(StringFieldEditor.VALUE)) {
                        for (TypeNameField field : fields) {
                            if (!hs.add(field.getStringValue())) {
                                valid = false;
                                break;
                            } else {
                                valid = true;
                            }

                        }

                    }

                    if (event.getProperty().equals(StringFieldEditor.IS_VALID)) {
                        isValid = (Boolean) event.getNewValue();
                    }

                    setPageComplete(isValid());

                }
            });
            propField.setStringValue(header[i].replace(" ", ""));

            cv = new ComboViewer(group);
            comboFields.add(cv);
            cv.addSelectionChangedListener(new ISelectionChangedListener() {

                @Override
                public void selectionChanged(SelectionChangedEvent event) {

                    int i = comboFields.indexOf(event.getSource());
                    PropertyTypeFactory actualSelection = ((PropertyTypeFactory) ((IStructuredSelection) cv
                            .getSelection()).getFirstElement());

                    try {
                        actualSelection.createExtensionObject().convertFromField(secondRow[i]);
                        validSel.set(i, true);

                    } catch (Exception e) {
                        validSel.set(i, false);
                    }
                    if (validSel.contains(false)) {
                        int j = validSel.indexOf(false) + 1;
                        setMessage("Your selection in field # " + j + " is not valid!", WARNING);
                    } else {
                        setMessage(null);
                    }

                }
            });
            cv.setContentProvider(ArrayContentProvider.getInstance());
            cv.setLabelProvider(new LabelProvider() {

                /**
                 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
                 */
                @Override
                public String getText(Object element) {
                    if (element instanceof PropertyTypeFactory) {
                        return ((PropertyTypeFactory) element).getDisplayName();
                    }
                    return super.getText(element);
                }
            });
            Collection<PropertyTypeFactory> elements = PropertyTypeExtension.getInstance().getFactories();
            cv.setInput(elements);

            PropertyTypeFactory defaultSelection = PropertyTypeExtension.getInstance()
                    .getFactory("java.lang.String");
            if (defaultSelection != null) {
                cv.setSelection(new StructuredSelection(defaultSelection));
            } else if (!elements.isEmpty()) {
                cv.setSelection(new StructuredSelection(elements.iterator().next()));
            }

        }
    }
    group.setLayout(new GridLayout(3, false));

    lastSecondRow = header;

    group.layout();
    sc.layout();
    //      setPageComplete(sfe.isValid() && isValid && valid);
}

From source file:eu.esdihumboldt.hale.io.csv.ui.SchemaTypePage.java

License:Open Source License

/**
 * @see HaleWizardPage#onShowPage(boolean)
 *//*from w w w  .j av  a 2  s. c o  m*/
@Override
protected void onShowPage(boolean firstShow) {

    LocatableInputSupplier<? extends InputStream> source = getWizard().getProvider().getSource();

    int indexStart = 0;
    int indexEnd = source.getLocation().getPath().length() - 1;

    if (source.getLocation().getPath() != null) {
        indexStart = source.getLocation().getPath().lastIndexOf("/") + 1;
        if (source.getLocation().getPath().lastIndexOf(".") >= 0) {
            indexEnd = source.getLocation().getPath().lastIndexOf(".");
        }

        defaultString = source.getLocation().getPath().substring(indexStart, indexEnd);
        sfe.setStringValue(defaultString);
        setPageComplete(sfe.isValid());
    }

    try {
        CSVReader reader = CSVUtil.readFirst(getWizard().getProvider());

        String[] firstLine = reader.readNext();
        final String[] nextLine = reader.readNext();

        int length = 0;
        if (firstLine.length != 0) {
            length = firstLine.length;
        }

        // disposes all property names if the read configuration has changed
        if (last_firstLine != null && !Arrays.equals(firstLine, last_firstLine)) {
            for (TypeNameField properties : fields) {
                properties.dispose();
                properties.getTextControl(group).dispose();
                properties.getLabelControl(group).dispose();
            }
            for (ComboViewer combViewer : comboFields) {
                combViewer.getCombo().dispose();
            }
            fields.clear();
            comboFields.clear();
        }

        if (!Arrays.equals(firstLine, last_firstLine)) {
            for (int i = 0; i < length; i++) {
                final TypeNameField propField;
                final ComboViewer cv;

                validSel.add(true);

                propField = new TypeNameField("properties", Integer.toString(i + 1), group);
                fields.add(propField);
                propField.setEmptyStringAllowed(false);
                propField.setErrorMessage("Please enter a valid Property Name");
                propField.setPropertyChangeListener(new IPropertyChangeListener() {

                    @Override
                    public void propertyChange(PropertyChangeEvent event) {

                        HashSet<String> hs = new HashSet<String>();

                        if (event.getProperty().equals(StringFieldEditor.VALUE)) {
                            for (TypeNameField field : fields) {
                                if (!hs.add(field.getStringValue())) {
                                    valid = false;
                                    break;
                                } else {
                                    valid = true;
                                }

                            }

                        }

                        if (event.getProperty().equals(StringFieldEditor.IS_VALID)) {
                            isValid = (Boolean) event.getNewValue();
                        }
                        setPageComplete(isValid && valid);

                    }
                });
                propField.setStringValue(firstLine[i]);
                cv = new ComboViewer(group);
                comboFields.add(cv);
                cv.addSelectionChangedListener(new ISelectionChangedListener() {

                    @Override
                    public void selectionChanged(SelectionChangedEvent event) {

                        int i = comboFields.indexOf(event.getSource());
                        PropertyTypeFactory actualSelection = ((PropertyTypeFactory) ((IStructuredSelection) cv
                                .getSelection()).getFirstElement());

                        try {
                            actualSelection.createExtensionObject().convertFromField(nextLine[i]);
                            validSel.set(i, true);

                        } catch (Exception e) {
                            log.warn("Selection invalid!", e);
                            validSel.set(i, false);
                        }
                        if (validSel.contains(false)) {
                            int j = validSel.indexOf(false) + 1;
                            setMessage("Your selection in field # " + j + " is not valid!", WARNING);
                        } else {
                            setMessage(null);
                        }

                    }
                });
                cv.setContentProvider(ArrayContentProvider.getInstance());
                cv.setLabelProvider(new LabelProvider() {

                    /**
                     * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
                     */
                    @Override
                    public String getText(Object element) {
                        if (element instanceof PropertyTypeFactory) {
                            return ((PropertyTypeFactory) element).getDisplayName();
                        }
                        return super.getText(element);
                    }
                });
                Collection<PropertyTypeFactory> elements = PropertyTypeExtension.getInstance().getFactories();
                cv.setInput(elements);

                PropertyTypeFactory defaultSelection = PropertyTypeExtension.getInstance()
                        .getFactory("java.lang.String");
                if (defaultSelection != null) {
                    cv.setSelection(new StructuredSelection(defaultSelection));
                } else if (!elements.isEmpty()) {
                    cv.setSelection(new StructuredSelection(elements.iterator().next()));
                }

            }
        }
        group.setLayout(new GridLayout(3, false));

        last_firstLine = firstLine;

    } catch (IOException e) {
        setErrorMessage("File could not be read");
        setPageComplete(false);
        e.printStackTrace();
    }

    group.layout();
    sc.layout();

    super.onShowPage(firstShow);
}

From source file:eu.esdihumboldt.hale.io.deegree.ui.BasicMappingConfigurationPage.java

License:Open Source License

@Override
protected void createContent(Composite page) {
    page.setLayout(new GridLayout(1, false));
    GridDataFactory groupData = GridDataFactory.fillDefaults().grab(true, false);

    GridDataFactory defLabel = GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER);
    GridDataFactory longField = GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).span(2, 1).grab(true,
            false);/*from   w  w  w  .  ja va 2s . c  om*/

    // Database group

    Group database = new Group(page, SWT.NONE);
    database.setLayout(new GridLayout(3, false));
    database.setText("Database and mapping");
    groupData.applyTo(database);

    // connection ID
    Label connIdLabel = new Label(database, SWT.NONE);
    connIdLabel.setText("Connection ID");
    defLabel.applyTo(connIdLabel);
    connId = new Text(database, SWT.SINGLE | SWT.BORDER);
    connId.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            updateState();
        }
    });
    longField.applyTo(connId);

    // database type
    Label dbTypeLabel = new Label(database, SWT.NONE);
    dbTypeLabel.setText("Database type");
    defLabel.applyTo(dbTypeLabel);
    dbType = new ComboViewer(database);
    dbType.setContentProvider(EnumContentProvider.getInstance());
    dbType.setInput(DatabaseType.class);
    longField.applyTo(dbType.getControl());

    // and version
    Label dbVersionLabel = new Label(database, SWT.NONE);
    dbVersionLabel.setText("Database version");
    defLabel.applyTo(dbVersionLabel);
    dbVersion = new Text(database, SWT.SINGLE | SWT.BORDER);
    longField.applyTo(dbVersion);

    // mapping mode
    Label modeLabel = new Label(database, SWT.NONE);
    modeLabel.setText("Mapping mode");
    defLabel.applyTo(modeLabel);
    mode = new ComboViewer(database);
    mode.setContentProvider(EnumContentProvider.getInstance());
    mode.setInput(MappingMode.class);
    longField.applyTo(mode.getControl());

    // ID prefix
    Label idPrefixLabel = new Label(database, SWT.NONE);
    idPrefixLabel.setText("GML ID prefix");
    defLabel.applyTo(idPrefixLabel);
    idPrefix = new ComboViewer(database);
    idPrefix.setContentProvider(EnumContentProvider.getInstance());
    idPrefix.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IDPrefixMode) {
                return ((IDPrefixMode) element).getDescription();
            }
            return super.getText(element);
        }

    });
    idPrefix.setInput(IDPrefixMode.class);
    longField.applyTo(idPrefix.getControl());

    // Primitive link mode
    Label primitiveLinkLabel = new Label(database, SWT.NONE);
    primitiveLinkLabel.setText("Primitive links");
    defLabel.applyTo(primitiveLinkLabel);
    primitiveLink = new ComboViewer(database);
    primitiveLink.setContentProvider(EnumContentProvider.getInstance());
    primitiveLink.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof PrimitiveLinkMode) {
                return ((PrimitiveLinkMode) element).getDescription();
            }
            return super.getText(element);
        }

    });
    primitiveLink.setInput(PrimitiveLinkMode.class);
    longField.applyTo(primitiveLink.getControl());
    // TODO add explanation field?

    // max name length
    Label nameLengthLabel = new Label(database, SWT.NONE);
    nameLengthLabel.setText("Max name length");
    defLabel.applyTo(nameLengthLabel);
    nameLength = new Spinner(database, SWT.BORDER);
    nameLength.setMinimum(0);
    nameLength.setMaximum(1000);
    nameLength.setIncrement(1);
    nameLength.setPageIncrement(10);
    Label nameLengthDescr = new Label(database, SWT.NONE);
    nameLengthDescr.setText("(setting 0 uses a default value)");

    // namespace prefix
    useNamespacePrefix = new Button(database, SWT.CHECK);
    useNamespacePrefix.setText("Use namespace prefix for names");
    GridDataFactory.swtDefaults().span(3, 1).applyTo(useNamespacePrefix);

    // integer IDs
    useIntegerIDs = new Button(database, SWT.CHECK);
    useIntegerIDs.setText("Use integer IDs for GML IDs");
    GridDataFactory.swtDefaults().span(3, 1).applyTo(useIntegerIDs);

    // CRS group

    Group crs = new Group(page, SWT.NONE);
    crs.setLayout(new GridLayout(3, false));
    crs.setText("Storage CRS");
    groupData.applyTo(crs);

    // CRS reference
    Label crsRefLabel = new Label(crs, SWT.NONE);
    crsRefLabel.setText("CRS Reference");
    defLabel.applyTo(crsRefLabel);
    crsRef = new Text(crs, SWT.SINGLE | SWT.BORDER);
    crsRef.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            updateState();
        }
    });
    longField.applyTo(crsRef);

    // dimension
    Label dimensionLabel = new Label(crs, SWT.NONE);
    dimensionLabel.setText("Dimension");
    defLabel.applyTo(dimensionLabel);
    dimension = new Spinner(crs, SWT.BORDER);
    dimension.setMinimum(0);
    dimension.setMaximum(3);
    dimension.setIncrement(1);
    dimension.setPageIncrement(1);
    Label dimensionDescr = new Label(crs, SWT.NONE);
    dimensionDescr.setText("(setting 0 uses the CRS dimension)");

    // SRID
    Label sridLabel = new Label(crs, SWT.NONE);
    sridLabel.setText("Database SRID");
    defLabel.applyTo(sridLabel);
    srid = new Text(crs, SWT.SINGLE | SWT.BORDER);
    longField.applyTo(srid);
}

From source file:eu.esdihumboldt.hale.io.gml.ui.PartitionConfigurationPage.java

License:Open Source License

/**
 * Create an element for selecting the partitioning mode.
 * //from  ww  w .ja  va  2  s  .co  m
 * @param parent the parent composite
 * 
 * @return the combo viewer
 */
public static ComboViewer createPartitionModeSelector(Composite parent) {
    ComboViewer viewer = new ComboViewer(parent, SWT.READ_ONLY);

    // for now fixed configuration - rather based on IOProviderDescriptor
    // (which is only available later)

    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof String) {
                switch (((String) element)) {
                case StreamGmlWriter.PARTITION_MODE_CUT:
                    return "Cut strictly at threshold (may break local references)";
                case StreamGmlWriter.PARTITION_MODE_RELATED:
                    return "Keep instances that reference each other together";
                case StreamGmlWriter.PARTITION_MODE_NONE:
                    return "No partitioning (create one part)";
                }
            }

            return super.getText(element);
        }

    });
    viewer.setInput(Arrays.asList(StreamGmlWriter.PARTITION_MODE_CUT, StreamGmlWriter.PARTITION_MODE_RELATED,
            StreamGmlWriter.PARTITION_MODE_NONE));
    // set default
    viewer.setSelection(new StructuredSelection(StreamGmlWriter.PARTITION_MODE_RELATED));

    return viewer;
}

From source file:eu.esdihumboldt.hale.io.gml.ui.PartitionConfigurationPage.java

License:Open Source License

/**
 * Create an element for selecting the extent partitioning mode.
 * /*from w  w w . j av  a2s . c o  m*/
 * @param parent the parent composite
 * 
 * @return the combo viewer
 */
public static ComboViewer createExtentPartitionModeSelector(Composite parent) {
    ComboViewer viewer = new ComboViewer(parent, SWT.READ_ONLY);

    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof String) {
                switch (((String) element)) {
                case StreamGmlWriter.PARTITION_BY_EXTENT_MODE_DATASET:
                    return "Partition instances based on the bounding box of the exported data set";
                case StreamGmlWriter.PARTITION_BY_EXTENT_MODE_WORLD:
                    return "Partition instances based on world extent";
                }
            }

            return super.getText(element);
        }

    });
    viewer.setInput(Arrays.asList(StreamGmlWriter.PARTITION_BY_EXTENT_MODE_DATASET,
            StreamGmlWriter.PARTITION_BY_EXTENT_MODE_WORLD));
    // set default
    viewer.setSelection(new StructuredSelection(StreamGmlWriter.PARTITION_BY_EXTENT_MODE_DATASET));

    return viewer;
}

From source file:eu.esdihumboldt.hale.io.gml.ui.RootElementPage.java

License:Open Source License

/**
 * @see HaleWizardPage#createContent(Composite)
 *//*  ww w  .ja v  a 2s .  co m*/
@Override
protected void createContent(Composite page) {
    page.setLayout(new GridLayout(1, false));

    // add filter text
    filterText = new Text(page, SWT.SINGLE | SWT.BORDER);
    filterText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    filterText.setText(""); //$NON-NLS-1$

    // add filtered list
    list = new ListViewer(page, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    list.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof XmlElement) {
                QName name = ((XmlElement) element).getName();

                return name.getLocalPart() + " (" + name.getNamespaceURI() + ")";
            }
            if (element instanceof Definition) {
                return ((Definition<?>) element).getDisplayName();
            }
            return super.getText(element);
        }

    });
    list.setContentProvider(ArrayContentProvider.getInstance());
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
    layoutData.widthHint = SWT.DEFAULT;
    layoutData.heightHint = 8 * list.getList().getItemHeight();
    list.getControl().setLayoutData(layoutData);

    // page status update
    list.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            setPageComplete(!selection.isEmpty());
        }
    });

    list.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (canFlipToNextPage()) {
                getContainer().showPage(getNextPage());
                return;
            }
        }
    });

    // search filter & update
    list.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            String filter = filterText.getText();
            // handle empty filter
            if (filter == null || filter.isEmpty()) {
                return true;
            }

            if (element instanceof Definition) {
                Definition<?> def = (Definition<?>) element;
                filter = filter.toLowerCase();

                if (def.getDisplayName().toLowerCase().contains(filter)) {
                    return true;
                }
            }

            return false;
        }
    });
    list.setComparator(new ViewerComparator());
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            // refilter
            list.refresh();
        }
    });

    updateList();
}

From source file:eu.esdihumboldt.hale.io.gml.ui.wfs.wizard.FilterPage.java

License:Open Source License

/**
 * @see AbstractWfsPage#createContent(Composite)
 *///from ww w .  ja v  a2  s . c  o  m
@Override
protected void createContent(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(3, false));

    Label typeLabel = new Label(page, SWT.NONE);
    typeLabel.setText(Messages.FilterPage_3); //$NON-NLS-1$
    typeLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));

    // init combo
    typeCombo = new ComboViewer(page);
    typeCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
    typeCombo.setContentProvider(ArrayContentProvider.getInstance());
    typeCombo.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof FeatureType) {
                return ((FeatureType) element).getName().getLocalPart();
            }

            return super.getText(element);
        }

    });

    typeCombo.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection.isEmpty()) {
                updateEditor(null);
            } else {
                if (selection instanceof IStructuredSelection) {
                    updateEditor((FeatureType) ((IStructuredSelection) selection).getFirstElement());
                }
            }
        }

    });

    Label editorLabel = new Label(page, SWT.NONE);
    editorLabel.setText(Messages.FilterPage_4); //$NON-NLS-1$
    editorLabel.setLayoutData(new GridData(SWT.END, SWT.BEGINNING, false, false));

    // init editor
    final Display display = Display.getCurrent();
    CompositeRuler ruler = new CompositeRuler(3);
    LineNumberRulerColumn lineNumbers = new LineNumberRulerColumn();
    lineNumbers.setBackground(display.getSystemColor(SWT.COLOR_GRAY)); // SWT.COLOR_INFO_BACKGROUND));
    lineNumbers.setForeground(display.getSystemColor(SWT.COLOR_BLACK)); // SWT.COLOR_INFO_FOREGROUND));
    lineNumbers.setFont(JFaceResources.getTextFont());
    ruler.addDecorator(0, lineNumbers);

    filterEditor = new SourceViewer(page, ruler, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    filterEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    filterEditor.getTextWidget().setFont(JFaceResources.getTextFont());
    SourceViewerConfiguration conf = new SourceViewerConfiguration();
    filterEditor.configure(conf);

    // create initial document
    IDocument doc = new Document();
    doc.set(""); //$NON-NLS-1$
    filterEditor.setInput(doc);

    // create edit button
    editButton = new Button(page, SWT.PUSH);
    editButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
    editButton.setText(Messages.FilterPage_6); //$NON-NLS-1$
    editButton.setToolTipText(Messages.FilterPage_7); //$NON-NLS-1$
    editButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (lastSelected != null) {
                FeatureType type = lastSelected;

                OGCFilterDialog dialog = new OGCFilterDialog(display.getActiveShell(),
                        MessageFormat.format(Messages.FilterPage_8, type.getName().getLocalPart())); //$NON-NLS-1$
                dialog.setFeatureType(type);
                String filter = dialog.open();
                if (filter != null) {
                    filterEditor.getDocument().set(filter);
                }
            }
        }

    });

    setControl(page);
}

From source file:eu.esdihumboldt.hale.io.haleconnect.ui.projects.ChooseHaleConnectProjectWizardPage.java

License:Open Source License

/**
 * @see eu.esdihumboldt.hale.ui.util.wizard.ConfigurationWizardPage#createContent(org.eclipse.swt.widgets.Composite)
 *//* www  .  j a  va2  s. c  om*/
@Override
protected void createContent(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(4, false));

    keywordFilter = new Text(page, SWT.SEARCH | SWT.ICON_SEARCH | SWT.BORDER | SWT.ICON_CANCEL);
    keywordFilter.setMessage("Enter search text here...");
    GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(keywordFilter);

    ownerFilter = new ComboViewer(page);
    GridDataFactory.fillDefaults().grab(false, false).applyTo(ownerFilter.getControl());
    ownerFilter.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            new Object();
        }

        @Override
        public void dispose() {
            //
        }

        @Override
        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof List<?>) {
                List<?> elements = (List<?>) inputElement;
                return elements.toArray();
            } else if (inputElement instanceof Object[]) {
                return (Object[]) inputElement;
            }

            return new Object[] {};
        }
    });
    ownerFilter.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof OwnerFilterEntry) {
                return ((OwnerFilterEntry) element).getLabel();
            }

            return super.getText(element);
        }

    });

    List<OwnerFilterEntry> availableFilters = new ArrayList<>();
    availableFilters.add(NULL_FILTER);
    availableFilters.add(new OwnerFilterEntry(
            new Owner[] { new Owner(OwnerType.USER, haleConnect.getSession().getUserId()) }, "My projects"));

    List<Owner> orgs = new ArrayList<>();
    for (String orgId : haleConnect.getSession().getOrganisationIds()) {
        orgs.add(new Owner(OwnerType.ORGANISATION, orgId));
    }
    if (!orgs.isEmpty()) {
        availableFilters.add(new OwnerFilterEntry(orgs.toArray(new Owner[] {}), "My organisation's projects"));
    }

    ownerFilter.setInput(availableFilters);
    ownerFilter.setSelection(new StructuredSelection(NULL_FILTER));

    Composite tableComposite = new Composite(page, SWT.NONE);
    TableColumnLayout columnLayout = new TableColumnLayout();
    tableComposite.setLayout(columnLayout);

    projects = new TableViewer(tableComposite,
            SWT.V_SCROLL | SWT.BORDER | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
    projects.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            update();
        }
    });

    TableViewerColumn nameColumn = new TableViewerColumn(projects, SWT.LEAD);
    nameColumn.getColumn().setText("Project name");
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            if (element instanceof HaleConnectProjectInfo) {
                return ((HaleConnectProjectInfo) element).getName();
            }

            return element.toString();
        }

    });
    columnLayout.setColumnData(nameColumn.getColumn(), new ColumnWeightData(45, 200, true));

    TableViewerColumn authorColumn = new TableViewerColumn(projects, SWT.LEAD);
    authorColumn.getColumn().setText("Author");
    authorColumn.setLabelProvider(new ColumnLabelProvider() {

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            if (element instanceof HaleConnectProjectInfo) {
                return ((HaleConnectProjectInfo) element).getAuthor();
            }

            return element.toString();
        }

    });
    columnLayout.setColumnData(authorColumn.getColumn(), new ColumnWeightData(20, 50, true));

    TableViewerColumn ownerColumn = new TableViewerColumn(projects, SWT.LEAD);
    ownerColumn.getColumn().setText("Owner");
    ownerColumn.setLabelProvider(new ColumnLabelProvider() {

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            if (element instanceof HaleConnectProjectInfo) {
                Owner owner = ((HaleConnectProjectInfo) element).getOwner();
                if (owner.isUser()) {
                    try {
                        HaleConnectUserInfo user = haleConnect.getUserInfo(owner.getId());
                        if (!StringUtils.isEmpty(user.getFullName())) {
                            return user.getFullName();
                        } else if (!StringUtils.isEmpty(user.getScreenName())) {
                            return user.getScreenName();
                        } else {
                            return MessageFormat.format("<user {0}>", user.getUserId());
                        }
                    } catch (HaleConnectException e) {
                        log.error(e.getMessage(), e);
                        return MessageFormat.format("<user {0}>", owner.getId());
                    }
                } else if (owner.isOrganisation()) {
                    try {
                        return haleConnect.getOrganisationInfo(owner.getId()).getName();
                    } catch (HaleConnectException e) {
                        log.error(e.getMessage(), e);
                        return MessageFormat.format("<organisation {0}>", owner.getId());
                    }
                } else {
                    return "<unknown owner type> ID: " + owner.getId();
                }
            }

            return element.toString();
        }

    });
    columnLayout.setColumnData(ownerColumn.getColumn(), new ColumnWeightData(35, 100, true));

    final Table projectsTable = projects.getTable();
    projectsTable.setHeaderVisible(true);
    projectsTable.setLinesVisible(true);

    tableComposite.setLayoutData(GridDataFactory.fillDefaults().span(4, 1).grab(true, true).create());
    projects.setContentProvider(ArrayContentProvider.getInstance());

    populateProjects(projectsTable);

    final ProjectFilter projectFilter = new ProjectFilter(projects);
    projects.addFilter(projectFilter);

    ownerFilter.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection() instanceof StructuredSelection) {
                StructuredSelection selection = (StructuredSelection) event.getSelection();
                if (selection.getFirstElement() instanceof OwnerFilterEntry) {
                    OwnerFilterEntry selectedFilter = (OwnerFilterEntry) selection.getFirstElement();
                    if (selectedFilter.equals(NULL_FILTER)) {
                        projectFilter.clearOwnerFilter();
                    } else {
                        projectFilter.filterByOwners(Arrays.asList(selectedFilter.getOwner()));
                    }
                }
            }
        }
    });

    keywordFilter.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            projectFilter.setSearchText(keywordFilter.getText());
        }
    });

    final Button refresh = new Button(page, SWT.FLAT);
    refresh.setText("Refresh");
    GridDataFactory.fillDefaults().span(1, 1).grab(false, false).applyTo(refresh);
    refresh.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            populateProjects(projectsTable);
        }

    });

    ownerFilter.getControl().setFocus();
    setControl(page);

    update();

}

From source file:eu.esdihumboldt.hale.io.haleconnect.ui.projects.HaleConnectTarget.java

License:Open Source License

@Override
public void createControls(Composite parent) {
    getPage().setDescription("Please select a destination file for the export");

    parent.setLayout(new GridLayout(4, false));

    Composite loginGroup = new Composite(parent, SWT.BORDER);
    loginGroup.setLayout(new GridLayout(4, false));
    GridData loginGroupLayout = new GridData(SWT.LEAD, SWT.LEAD, false, false, 4, 1);
    loginGroupLayout.widthHint = 550;/*from www. j a v  a 2s  . c o  m*/
    loginGroup.setLayoutData(loginGroupLayout);

    /*
     * Login status label
     */
    loginStatusLabel = new Label(loginGroup, SWT.NONE);
    loginStatusLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));

    loginButton = new Button(loginGroup, SWT.PUSH);
    loginButton.setText("Login");
    loginButton.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, false, false, 1, 1));
    loginButton.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            HaleConnectLoginDialog loginDialog = HaleConnectLoginHandler
                    .createLoginDialog(Display.getCurrent().getActiveShell());
            if (loginDialog != null && loginDialog.open() == Dialog.OK) {
                HaleConnectLoginHandler.performLogin(loginDialog);
                updateState();
                prefillTargetProject();
            }
        }

    });

    updateOrNewGroup = new Group(parent, SWT.NONE);
    updateOrNewGroup.setText("Please choose whether you would like to...");
    updateOrNewGroup.setLayout(new GridLayout(4, false));
    updateOrNewGroup.setLayoutData(new GridData(SWT.LEAD, SWT.LEAD, false, false, 4, 1));

    newProject = new Button(updateOrNewGroup, SWT.RADIO);
    newProject.setText("create a new project on hale connect");
    newProject.setSelection(true);
    newProject.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            updateState();
        }

    });

    updateProject = new Button(updateOrNewGroup, SWT.RADIO);
    updateProject.setText("update an existing project");
    updateProject.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            updateState();
        }

    });

    controlsStackLayout = new StackLayout();
    controlsStack = new Composite(parent, SWT.NONE);
    controlsStack.setLayout(controlsStackLayout);

    newProjectControls = new Composite(controlsStack, SWT.NONE);
    newProjectControls.setLayout(new GridLayout(4, true));
    GridData grid = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1);
    newProjectControls.setLayoutData(grid);

    ownershipGroup = new Composite(newProjectControls, SWT.NONE);
    ownershipGroup.setLayout(new GridLayout(4, false));
    ownershipGroup.setLayoutData(new GridData(SWT.LEAD, SWT.LEAD, false, false, 4, 1));

    Label ownerLabel = new Label(ownershipGroup, SWT.NONE);
    ownerLabel.setText("Who should own the uploaded project?");

    ownerUser = new Button(ownershipGroup, SWT.RADIO);
    ownerUser.setText("You");

    ownerOrg = new Button(ownershipGroup, SWT.RADIO);
    ownerOrg.setText("Your organisation");

    orgSelector = new ComboViewer(ownershipGroup);
    GridData orgSelectorGrid = new GridData(SWT.LEAD, SWT.LEAD, false, false);
    orgSelectorGrid.widthHint = 175;
    orgSelector.getCombo().setLayoutData(orgSelectorGrid);
    orgSelector.setContentProvider(ArrayContentProvider.getInstance());
    orgSelector.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof HaleConnectOrganisationInfo) {
                return ((HaleConnectOrganisationInfo) element).getName();
            }

            return super.getText(element);
        }

    });

    Composite bucketOptions = new Composite(parent, SWT.NONE);
    bucketOptions.setLayout(new RowLayout());
    bucketOptions.setLayoutData(new GridData(SWT.LEAD, SWT.LEAD, true, true, 4, 1));

    enableVersioning = new Button(bucketOptions, SWT.CHECK);
    enableVersioning.setText("Enable versioning?");

    publicAccess = new Button(bucketOptions, SWT.CHECK);
    publicAccess.setText("Allow public access?");

    updateProjectControls = new Composite(controlsStack, SWT.NONE);
    updateProjectControls.setVisible(false);
    updateProjectControls.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1));

    /*
     * Project name text field
     */
    projectName = new StringFieldEditor("project", "Project to update", updateProjectControls) {

        // the following methods are overridden so the button
        // may appear on the same line

        @Override
        public int getNumberOfControls() {
            return super.getNumberOfControls() + 1;
        }

        @Override
        protected void doFillIntoGrid(Composite parent, int numColumns) {
            super.doFillIntoGrid(parent, numColumns - 1);
        }
    };
    projectName.setEmptyStringAllowed(false);
    projectName.setErrorMessage("Please select a project before continuing.");
    projectName.setPage(getPage());
    projectName.getTextControl(updateProjectControls).setEditable(false);
    projectName.getTextControl(updateProjectControls).addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            selectProject();
        }

    });

    projectName.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(FieldEditor.IS_VALID)) {
                getPage().setMessage(null);
                updateState();
            } else if (event.getProperty().equals(FieldEditor.VALUE)) {
                getPage().setMessage(null);
                updateState();
            }
        }
    });

    /*
     * Select project button
     */
    selectProjectButton = new Button(updateProjectControls, SWT.PUSH);
    selectProjectButton.setText("Select");
    selectProjectButton.setToolTipText("Select project");
    selectProjectButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    selectProjectButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectProject();
        }
    });

    FontData currentFont = loginStatusLabel.getFont().getFontData()[0];

    upstreamModifiedWarning = new Label(updateProjectControls, SWT.WRAP);
    upstreamModifiedWarning.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false, 4, 1));
    upstreamModifiedWarning.setFont(new Font(upstreamModifiedWarning.getDisplay(),
            new FontData(currentFont.getName(), currentFont.getHeight(), SWT.BOLD)));
    upstreamModifiedWarning.setVisible(false);

    Composite writerOptions = new Composite(parent, SWT.NONE);
    writerOptions.setLayout(new RowLayout());
    writerOptions.setLayoutData(new GridData(SWT.LEAD, SWT.LEAD, true, true, 4, 2));

    includeWebResources = new Button(writerOptions, SWT.CHECK);
    includeWebResources.setText("Include web resources?");

    excludeData = new Button(writerOptions, SWT.CHECK);
    excludeData.setText("Exclude source data?");
    excludeData.setSelection(true);

    excludeCachedResources = new Button(writerOptions, SWT.CHECK);
    excludeCachedResources
            .setText("Use cached internal schema representation (required for big schema files)?");
    excludeCachedResources.setSelection(true);

    prefillTargetProject();

    updateState();
}