Example usage for org.eclipse.jface.viewers TableViewer getTable

List of usage examples for org.eclipse.jface.viewers TableViewer getTable

Introduction

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

Prototype

public Table getTable() 

Source Link

Document

Returns this table viewer's table control.

Usage

From source file:com.contrastsecurity.ide.eclipse.ui.internal.views.TagDialog.java

License:Open Source License

private TableViewer createTableViewer(Composite composite) {
    TableViewer tableViewer = new TableViewer(composite,
            SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    tableViewer.getTable().setLayoutData(gd);
    tableViewer.setLabelProvider(new TagLabelProvider());

    tableViewer.getTable().setHeaderVisible(true);
    tableViewer.getTable().setLinesVisible(true);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    TableLayout layout = new TableLayout();
    tableViewer.getTable().setLayout(layout);

    TableColumn tagColumn = new TableColumn(tableViewer.getTable(), SWT.NONE);
    tagColumn.setText("Tag");
    tagColumn.setWidth(290);/*from w w  w. j av a2s .  c  o  m*/
    TableColumn removeColumn = new TableColumn(tableViewer.getTable(), SWT.NONE);
    removeColumn.setText("Remove");
    removeColumn.setWidth(70);

    tableViewer.getTable().addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {

        }

        @Override
        public void mouseDown(MouseEvent e) {
            onRemoveButtonClick(e.x, e.y);
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
        }
    });

    tableViewer.getTable().addListener(SWT.PaintItem, new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (event.index == 1) {
                Image tmpImage = ContrastUIActivator.getImage("/icons/remove.png");
                int tmpWidth = 0;
                int tmpHeight = 0;
                int tmpX = 0;
                int tmpY = 0;

                tmpWidth = tableViewer.getTable().getColumn(event.index).getWidth();
                tmpHeight = ((TableItem) event.item).getBounds().height;

                tmpX = tmpImage.getBounds().width;
                tmpX = (tmpWidth / 2 - tmpX / 2);
                tmpY = tmpImage.getBounds().height;
                tmpY = (tmpHeight / 2 - tmpY / 2);
                if (tmpX <= 0)
                    tmpX = event.x;
                else
                    tmpX += event.x;
                if (tmpY <= 0)
                    tmpY = event.y;
                else
                    tmpY += event.y;
                event.gc.drawImage(tmpImage, tmpX, tmpY);
            }
        }
    });
    return tableViewer;
}

From source file:com.density.ezsbt.preference.SbtPreferencePage.java

License:Apache License

protected void makeTable(Composite parent) {
    Composite tableComposite = new Composite(parent, SWT.NONE);
    tableComposite.setLayoutData(new RowData(300, 200));
    TableColumnLayout tableColumnLayout = new TableColumnLayout();
    tableComposite.setLayout(tableColumnLayout);
    TableViewer tableViewer = new TableViewer(tableComposite,
            SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    commandTable = tableViewer.getTable();
    commandTable.setLinesVisible(true);//from   w  w w.  j a  v  a2s .  co m
    commandTable.setHeaderVisible(true);
    for (String title : TABLE_COLUMNS_TITLE) {
        TableColumn column = new TableColumn(commandTable, SWT.CENTER);
        column.setText(title);
        tableColumnLayout.setColumnData(column, new ColumnWeightData(50, 150, false));
    }
    IPreferenceStore store = getPreferenceStore();
    String[] commandPairs = CommandsConvertor.stringToArray(store.getString(PluginConstants.COMMANDS_NAME_KEY));
    for (String pair : commandPairs) {
        TableItem item = new TableItem(commandTable, SWT.NONE);
        item.setText(CommandsConvertor.pairToArray(pair));
    }
    commandTable.pack();
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            if (commandTable.getSelectionCount() == 0) {
                editButton.setEnabled(false);
                removeButton.setEnabled(false);
            } else {
                editButton.setEnabled(true);
                removeButton.setEnabled(true);
            }
        }
    });
}

From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.SwtFactory.java

License:Open Source License

/**
 * Creates a file list with a browser to open a file dialog.
 * <p>//w  w  w . ja  v  a2 s  .c  om
 * When a file is added or removed, a selection listener is invoked.
 * </p>
 *
 * @param parent the parent
 * @param filterNames the filter names
 * @param fileExtensions the file extensions
 * @param files a non-null collection of files (can be empty)
 * @return the tree viewer that displays the selected files
 */
public static ListWithButtonComposite createFileListViewer(final Composite parent, final String[] filterNames,
        final String[] fileExtensions, final Collection<File> files) {

    final ListWithButtonComposite lbc = new ListWithButtonComposite(parent);
    lbc.setLayoutData(new GridData(GridData.FILL_BOTH));
    final TableViewer viewer = lbc.getViewer();

    viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof File)
                return ((File) element).getAbsolutePath();
            return super.getText(element);
        }
    });

    // ADD button
    lbc.getAddButton().setText("Add");
    lbc.getAddButton().setImage(PetalsImages.INSTANCE.getAdd());
    lbc.getAddButton().addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            FileDialog dlg = new FileDialog(parent.getShell(), SWT.MULTI);
            dlg.setText("Select one or several files");
            dlg.setFilterNames(filterNames);
            dlg.setFilterExtensions(fileExtensions);

            String path = PreferencesManager.getSavedLocation();
            if (path.trim().length() > 0)
                dlg.setFilterPath(path);

            String fn = dlg.open();
            if (fn == null)
                return;

            // Process the files
            path = dlg.getFilterPath();
            PreferencesManager.setSavedLocation(path);

            File parent = new File(path);
            for (String filename : dlg.getFileNames()) {
                File chosenFile = new File(parent, filename);
                files.add(chosenFile);
            }

            viewer.setInput(files);
            viewer.refresh();
            lbc.notifyListeners();
        }
    });

    // REMOVE button
    lbc.getRemoveButton().setText("Remove");
    lbc.getRemoveButton().setImage(PetalsImages.INSTANCE.getDelete());
    lbc.getRemoveButton().addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            Iterator<?> it = ((IStructuredSelection) viewer.getSelection()).iterator();
            while (it.hasNext()) {
                File f = (File) it.next();
                files.remove(f);
            }

            viewer.setInput(files);
            viewer.refresh();
            lbc.notifyListeners();
        }
    });

    return lbc;
}

From source file:com.ebmwebsourcing.petals.components.drivers.ComponentConfigurationWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {

    setTitle("Configured Component");
    setMessage("Update a Petals component to use one or several shared libraries.");

    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout());
    container.setLayoutData(new GridData(GridData.FILL_BOTH));
    setControl(container);/* w  w w.  j  av a2s  .c  o m*/

    // Select the component's archive
    Composite subC = new Composite(container, SWT.NONE);
    GridLayout layout = new GridLayout(3, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    subC.setLayout(layout);
    subC.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Label l = new Label(subC, SWT.NONE);
    l.setText("Component's URL:");
    l.setToolTipText("The URL of the component's ZIP");

    final Text componentUrlText = new Text(subC, SWT.SINGLE | SWT.BORDER);
    componentUrlText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    componentUrlText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            ComponentConfigurationWizardPage.this.componentUrl = ((Text) e.widget).getText().trim();
            validate();
        }
    });

    Button browseButton = new Button(subC, SWT.PUSH);
    browseButton.setText("Browse...");
    browseButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {

            FileDialog dlg = new FileDialog(getShell(), SWT.SINGLE);
            dlg.setText("Select a zipped component file");
            dlg.setFilterNames(new String[] { "ZIP (*.zip)" });
            dlg.setFilterExtensions(new String[] { "*.zip" });

            String path = PreferencesManager.getSavedLocation();
            if (!StringUtils.isEmpty(path)) {
                try {
                    File f = new File(path);
                    dlg.setFilterPath(f.getParentFile().getAbsolutePath());
                    dlg.setFileName(f.getName());

                } catch (Exception e1) {
                    // nothing
                }
            }

            String fn = dlg.open();
            if (fn != null) {
                PreferencesManager.setSavedLocation(fn);
                fn = convertFilePathToUrl(fn);
                componentUrlText.setText(fn);
            }
        }
    });

    // Choose the output location
    l = new Label(subC, SWT.NONE);
    l.setText("Output Location:");
    l.setToolTipText("The location of the component after configuration");

    final Text outputLocationText = new Text(subC, SWT.SINGLE | SWT.BORDER);
    outputLocationText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    outputLocationText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            ComponentConfigurationWizardPage.this.updatedFileLocation = ((Text) e.widget).getText().trim();
            validate();
        }
    });

    browseButton = new Button(subC, SWT.PUSH);
    browseButton.setText("Browse...");
    browseButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {

            FileDialog dlg = new FileDialog(getShell(), SWT.SINGLE | SWT.SAVE);
            dlg.setText("Select a zipped component file");
            dlg.setFilterNames(new String[] { "ZIP (*.zip)" });
            dlg.setFilterExtensions(new String[] { "*.zip" });

            // File name
            String name = null;
            if (ComponentConfigurationWizardPage.this.componentUrl != null) {
                int index = Math.max(ComponentConfigurationWizardPage.this.componentUrl.lastIndexOf('/'),
                        ComponentConfigurationWizardPage.this.componentUrl.lastIndexOf('\\'));

                if (index > 0 && index < ComponentConfigurationWizardPage.this.componentUrl.length() - 1) {
                    name = ComponentConfigurationWizardPage.this.componentUrl.substring(index + 1);
                    name = StringUtils.insertSuffixBeforeFileExtension(name, "--patched");
                }
            }

            // Save location
            String path = PreferencesManager.getSavedLocation();
            if (!StringUtils.isEmpty(path)) {
                try {
                    File f = new File(path);
                    dlg.setFilterPath(f.getParentFile().getAbsolutePath());
                    dlg.setFileName(name == null ? f.getName() : name);

                } catch (Exception e1) {
                    // nothing
                }
            } else if (name != null) {
                dlg.setFileName(name);
            }

            String fn = dlg.open();
            if (fn != null)
                outputLocationText.setText(fn);
        }
    });

    new Label(subC, SWT.NO_FOCUS);
    final Button overwriteButton = new Button(subC, SWT.CHECK);
    overwriteButton.setText("Overwrite");
    overwriteButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            ComponentConfigurationWizardPage.this.overwrite = overwriteButton.getSelection();
            validate();
        }
    });

    // Add a table to display the shared libraries to add
    subC = new Composite(container, SWT.NONE);
    layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.marginTop = 18;
    subC.setLayout(layout);
    subC.setLayoutData(new GridData(GridData.FILL_BOTH));

    l = new Label(subC, SWT.NONE);
    l.setText("Select or define the shared libraries this component must use.");
    GridData layoutData = new GridData();
    layoutData.horizontalSpan = 2;
    l.setLayoutData(layoutData);

    final TableViewer slViewer = new TableViewer(subC,
            SWT.BORDER | SWT.HIDE_SELECTION | SWT.FULL_SELECTION | SWT.SINGLE);
    slViewer.setContentProvider(new ArrayContentProvider());
    slViewer.setLabelProvider(new ITableLabelProvider() {
        @Override
        public void removeListener(ILabelProviderListener listener) {
            // nothing
        }

        @Override
        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        @Override
        public void dispose() {
            // nothing
        }

        @Override
        public void addListener(ILabelProviderListener listener) {
            // nothing
        }

        @Override
        public String getColumnText(Object element, int columnIndex) {
            Object key = ((Map.Entry<?, ?>) element).getKey();
            Object value = ((Map.Entry<?, ?>) element).getValue();

            String result = "";
            ;
            if (columnIndex == 0)
                result = (String) key;
            else if (columnIndex == 1)
                result = (String) value;

            return result;
        }

        @Override
        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }
    });

    slViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    slViewer.getTable().setHeaderVisible(true);
    slViewer.getTable().setLinesVisible(true);

    TableLayout tlayout = new TableLayout();
    tlayout.addColumnData(new ColumnWeightData(85, 300, true));
    tlayout.addColumnData(new ColumnWeightData(15, 50, true));
    slViewer.getTable().setLayout(tlayout);

    TableColumn column = new TableColumn(slViewer.getTable(), SWT.LEFT);
    column.setText(NAME);
    column = new TableColumn(slViewer.getTable(), SWT.CENTER);
    column.setText(VERSION);
    slViewer.setColumnProperties(new String[] { NAME, VERSION });

    // Add some buttons
    Composite buttonsComposite = new Composite(subC, SWT.NONE);
    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    buttonsComposite.setLayout(layout);
    buttonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true));

    Button addSlFileButton = new Button(buttonsComposite, SWT.PUSH);
    addSlFileButton.setText("Add a File...");
    addSlFileButton.setToolTipText("Select a Shared Library file");
    addSlFileButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));

    Button addSlUrlButton = new Button(buttonsComposite, SWT.PUSH);
    addSlUrlButton.setText("Add an URL...");
    addSlUrlButton.setToolTipText("Add an URL pointing to a Shared Library");
    addSlUrlButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));

    Button specifySlButton = new Button(buttonsComposite, SWT.PUSH);
    specifySlButton.setText("Specify Manually...");
    specifySlButton.setToolTipText("Enter a shared library name and a shared library version manually");
    specifySlButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));

    final Button editButton = new Button(buttonsComposite, SWT.PUSH);
    editButton.setText("Edit...");
    editButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));

    final Button deleteButton = new Button(buttonsComposite, SWT.PUSH);
    deleteButton.setText("Delete");
    deleteButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));

    // Button listeners
    addSlFileButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            openSlFileDialog(slViewer, null);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            openSlFileDialog(slViewer, null);
        }
    });

    addSlUrlButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            openSlUrlDialog(slViewer, null);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            openSlUrlDialog(slViewer, null);
        }
    });

    specifySlButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            openSlDialog(slViewer, null);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            openSlDialog(slViewer, null);
        }
    });

    editButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {

            if (!slViewer.getSelection().isEmpty()) {
                Object o = ((IStructuredSelection) slViewer.getSelection()).getFirstElement();
                if (o instanceof Map.Entry<?, ?>) {
                    o = ((Map.Entry<?, ?>) o).getKey();
                    if (o instanceof String)
                        openSlDialog(slViewer, (String) o);
                }
            }
        }
    });

    deleteButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {

            if (!slViewer.getSelection().isEmpty()) {
                Object o = ((IStructuredSelection) slViewer.getSelection()).getFirstElement();
                ComponentConfigurationWizardPage.this.slNameToVersion.remove(o);
                slViewer.setInput(ComponentConfigurationWizardPage.this.slNameToVersion.entrySet());
                slViewer.refresh();
            }
        }
    });

    // Other listeners
    slViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {

            deleteButton.setEnabled(true);
            Object o = ((IStructuredSelection) slViewer.getSelection()).getFirstElement();
            if (o instanceof Map.Entry<?, ?>) {
                o = ((Map.Entry<?, ?>) o).getKey();
                boolean disabled = o instanceof File;
                editButton.setEnabled(!disabled);
            }
        }
    });

    setPageComplete(false);
}

From source file:com.ebmwebsourcing.petals.services.sa.export.SaExportWizardPage.java

License:Open Source License

public void createControl(Composite parent) {

    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 10;/*from  www  .j  a  va2s . c o  m*/
    layout.marginWidth = 10;
    container.setLayout(layout);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    new Label(container, SWT.NONE).setText("Select the Service Assembly project(s) to export:");

    // Project viewer
    TableViewer viewer = new TableViewer(container, SWT.BORDER | SWT.CHECK);
    GridData layoutData = new GridData(GridData.FILL_BOTH);
    layoutData.heightHint = 180;
    viewer.getTable().setLayoutData(layoutData);
    viewer.setLabelProvider(new WorkbenchLabelProvider());
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setInput(this.saProjects.keySet());

    for (TableItem item : viewer.getTable().getItems()) {
        IProject p = (IProject) item.getData();
        if (this.saProjects.get(p))
            item.setChecked(true);
    }

    viewer.getTable().addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {

            boolean checked = ((TableItem) event.item).getChecked();
            IProject p = (IProject) ((TableItem) event.item).getData();
            SaExportWizardPage.this.saProjects.put(p, checked);
            validate();
        }
    });

    // Export mode
    Label label = new Label(container, SWT.NONE);
    label.setText("Select the export mode:");
    layoutData = new GridData();
    layoutData.verticalIndent = 17;
    label.setLayoutData(layoutData);

    // Export mode - one per project
    Button projectModeButton = new Button(container, SWT.RADIO);
    projectModeButton.setText("Export every selected Service Assembly in its project.");
    projectModeButton.setToolTipText(
            "The created archives will be placed at the root of the associated Service Assembly projects.");
    layoutData = new GridData();
    layoutData.verticalIndent = 3;
    projectModeButton.setLayoutData(layoutData);

    // Export mode - one per project, in a same directory
    Button separateModeButton = new Button(container, SWT.RADIO);
    separateModeButton.setText("Export the Service Assemblies separately, but in a same directory.");
    separateModeButton.setToolTipText("The created archive will be placed in the selected directory.");

    Composite subContainer = new Composite(container, SWT.NONE);
    layout = new GridLayout(3, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.marginLeft = 16;
    subContainer.setLayout(layout);
    subContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    final Label dirLabel = new Label(subContainer, SWT.NONE);
    dirLabel.setText("Output directory:");
    layoutData = new GridData();
    layoutData.widthHint = 90;
    dirLabel.setLayoutData(layoutData);

    final Text dirText = new Text(subContainer, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
    dirText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    String loc = PetalsServicesPlugin.getDefault().getPreferenceStore().getString(PREF_DIRECTORY_LOC);
    if (loc.length() != 0) {
        dirText.setText(loc);
        this.outputFile = new File(loc);
    }

    dirText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            SaExportWizardPage.this.outputFile = new File(dirText.getText());
            validate();
        }
    });

    final Button browseDirButton = new Button(subContainer, SWT.PUSH);
    browseDirButton.setText("Browse...");
    browseDirButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            DirectoryDialog dlg = new DirectoryDialog(dirText.getShell());
            dlg.setText("Output Directory");
            dlg.setMessage("Select the output directory.");
            if (SaExportWizardPage.this.outputFile != null && SaExportWizardPage.this.outputFile.exists())
                dlg.setFilterPath(SaExportWizardPage.this.outputFile.getAbsolutePath());

            String loc = dlg.open();
            if (loc != null) {
                dirText.setText(loc);
                PetalsServicesPlugin.getDefault().getPreferenceStore().setValue(PREF_DIRECTORY_LOC, loc);
            }
        }
    });

    // Selection listeners
    projectModeButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {

            dirLabel.setEnabled(false);
            dirText.setEnabled(false);
            browseDirButton.setEnabled(false);
            dirText.setBackground(dirText.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));

            SaExportWizardPage.this.outputFile = null;
            SaExportWizardPage.this.exportMode = SaExportMode.IN_PROJECT;
            validate();
        }
    });

    separateModeButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {

            dirLabel.setEnabled(true);
            dirText.setEnabled(true);
            browseDirButton.setEnabled(true);
            dirText.setBackground(dirText.getDisplay().getSystemColor(SWT.COLOR_WHITE));

            SaExportWizardPage.this.outputFile = new File(dirText.getText());
            SaExportWizardPage.this.exportMode = SaExportMode.IN_SAME_LOCATION;
            validate();
        }
    });

    // Last UI details
    setControl(container);
    viewer.getTable().setFocus();
    projectModeButton.setSelection(true);
    projectModeButton.notifyListeners(SWT.Selection, new Event());

    String msg = getErrorMessage();
    if (msg != null) {
        setErrorMessage(null);
        setMessage(msg, IMessageProvider.INFORMATION);
    }
}

From source file:com.ebmwebsourcing.petals.services.su.editor.SuEditionComposite.java

License:Open Source License

/**
 * Constructor./*  w  ww . j av  a2s  .c  om*/
 * @param parent
 */
public SuEditionComposite(Composite parent, ISharedEdition ise) {
    super(parent, SWT.NONE);
    this.ise = ise;
    this.labelProvider = new EMFPCStyledLabelProvider(this);

    setLayoutData(new GridData(GridData.FILL_BOTH));
    getFormToolkit().adapt(this);
    getFormToolkit().paintBordersFor(this);

    // Create the widgets
    initModel();
    createLeftWidgets();
    createRightWidgets();
    setWeights(new int[] { 1, 1 });

    // Initial selection
    AbstractEndpoint ae = null;
    TableViewer viewer = null;

    if (!getJbiModel().getServices().getProvides().isEmpty()) {
        ae = getJbiModel().getServices().getProvides().get(0);
        viewer = this.providesViewer;
    } else if (!getJbiModel().getServices().getConsumes().isEmpty()) {
        ae = getJbiModel().getServices().getConsumes().get(0);
        viewer = this.consumesViewer;
    }

    if (viewer != null) {
        viewer.setSelection(new StructuredSelection(ae));
        viewer.getTable().notifyListeners(SWT.Selection, new Event());
    }
}

From source file:com.ebmwebsourcing.petals.services.su.export.SuExportWizardPage.java

License:Open Source License

public void createControl(Composite parent) {

    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = 10;//  w  ww .java 2 s . c o  m
    layout.marginWidth = 10;
    container.setLayout(layout);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Project viewer
    Label l = new Label(container, SWT.NONE);
    l.setText("Select the Service Unit project(s) to export:");

    GridData layoutData = new GridData();
    layoutData.horizontalSpan = 2;
    l.setLayoutData(layoutData);

    final TableViewer viewer = new TableViewer(container, SWT.BORDER | SWT.CHECK);
    layoutData = new GridData(GridData.FILL_BOTH);
    layoutData.heightHint = 140;
    layoutData.widthHint = 440;
    layoutData.horizontalSpan = 2;

    viewer.getTable().setLayoutData(layoutData);
    viewer.setLabelProvider(new WorkbenchLabelProvider());
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setInput(this.suProjects.keySet());

    for (TableItem item : viewer.getTable().getItems()) {
        IProject p = (IProject) item.getData();
        if (this.suProjects.get(p))
            item.setChecked(true);
    }

    viewer.getTable().addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {

            boolean checked = ((TableItem) event.item).getChecked();
            IProject p = (IProject) ((TableItem) event.item).getData();
            SuExportWizardPage.this.suProjects.put(p, checked);
            validate();
        }
    });

    // Export options
    final Composite exportComposite = new Composite(container, SWT.SHADOW_ETCHED_OUT);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    exportComposite.setLayout(layout);

    layoutData = new GridData(GridData.FILL_HORIZONTAL);
    layoutData.verticalIndent = 17;
    layoutData.horizontalSpan = 2;
    exportComposite.setLayoutData(layoutData);

    l = new Label(exportComposite, SWT.NONE);
    l.setText("Export mode:");

    final Combo exportCombo = new Combo(exportComposite, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
    exportCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    exportCombo.setItems(new String[] { "Distinct export, in a same directory",
            "Distinct export, in the project directories", "All-in-one export, in a same service assembly" });

    this.lastLabel = new Label(exportComposite, SWT.NONE);
    exportCombo.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {

            // Get the export type
            int selectionIndex = exportCombo.getSelectionIndex();

            // Delete the last two widgets
            boolean found = false;
            if (SuExportWizardPage.this.lastLabel != null) {
                for (Control control : exportComposite.getChildren()) {
                    if (found)
                        control.dispose();
                    else
                        found = control.equals(SuExportWizardPage.this.lastLabel);
                }
            }

            // Add new widgets - separate, external directory
            if (selectionIndex == 0) {
                SuExportWizardPage.this.exportMode = SuExportMode.SEPARATE_IN_DIRECTORY;
                SuExportWizardPage.this.lastLabel.setVisible(true);
                SuExportWizardPage.this.lastLabel.setText("Output directory:");

                Composite subContainer = new Composite(exportComposite, SWT.NONE);
                GridLayout layout = new GridLayout(2, false);
                layout.marginWidth = 0;
                layout.marginHeight = 0;
                subContainer.setLayout(layout);
                subContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

                final Text dirText = new Text(subContainer, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
                dirText.setBackground(dirText.getDisplay().getSystemColor(SWT.COLOR_WHITE));
                dirText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                String loc = PetalsServicesPlugin.getDefault().getPreferenceStore()
                        .getString(PREF_DIRECTORY_LOC);
                if (loc.length() != 0) {
                    dirText.setText(loc);
                    SuExportWizardPage.this.outputFile = new File(loc);
                }

                dirText.addModifyListener(new ModifyListener() {
                    public void modifyText(ModifyEvent e) {
                        SuExportWizardPage.this.outputFile = new File(dirText.getText());
                        validate();
                    }
                });

                final Button browseDirButton = new Button(subContainer, SWT.PUSH);
                browseDirButton.setText("Browse...");
                browseDirButton.addSelectionListener(new SelectionListener() {
                    public void widgetSelected(SelectionEvent e) {
                        widgetDefaultSelected(e);
                    }

                    public void widgetDefaultSelected(SelectionEvent e) {
                        DirectoryDialog dlg = new DirectoryDialog(dirText.getShell());
                        dlg.setText("Output Directory");
                        dlg.setMessage("Select the output directory.");
                        if (SuExportWizardPage.this.outputFile != null
                                && SuExportWizardPage.this.outputFile.exists())
                            dlg.setFilterPath(SuExportWizardPage.this.outputFile.getAbsolutePath());

                        String loc = dlg.open();
                        if (loc != null) {
                            dirText.setText(loc);
                            PetalsServicesPlugin.getDefault().getPreferenceStore().setValue(PREF_DIRECTORY_LOC,
                                    loc);
                        }
                    }
                });
            }

            // Separate, project directories
            else if (selectionIndex == 1) {
                SuExportWizardPage.this.exportMode = SuExportMode.SEPARATE_IN_PROJECT;
                SuExportWizardPage.this.lastLabel.setVisible(false);
            }

            // Same SA
            else if (selectionIndex == 2) {
                SuExportWizardPage.this.exportMode = SuExportMode.ALL_IN_ONE;
                SuExportWizardPage.this.lastLabel.setVisible(true);
                SuExportWizardPage.this.lastLabel.setText("Output file:");

                Composite subContainer = new Composite(exportComposite, SWT.NONE);
                GridLayout layout = new GridLayout(2, false);
                layout.marginWidth = 0;
                layout.marginHeight = 0;
                subContainer.setLayout(layout);
                subContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

                final Text fileText = new Text(subContainer, SWT.SINGLE | SWT.BORDER);
                fileText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                String loc = PetalsServicesPlugin.getDefault().getPreferenceStore().getString(PREF_FILE_LOC);
                if (loc.length() != 0) {
                    fileText.setText(loc);
                    SuExportWizardPage.this.outputFile = new File(loc);
                }

                fileText.addModifyListener(new ModifyListener() {
                    public void modifyText(ModifyEvent e) {
                        SuExportWizardPage.this.outputFile = new File(fileText.getText());
                        validate();
                    }
                });

                final Button browseFileButton = new Button(subContainer, SWT.PUSH);
                browseFileButton.setText("Browse...");
                browseFileButton.addSelectionListener(new SelectionListener() {
                    public void widgetSelected(SelectionEvent e) {
                        widgetDefaultSelected(e);
                    }

                    public void widgetDefaultSelected(SelectionEvent e) {
                        FileDialog dlg = new FileDialog(fileText.getShell());
                        dlg.setText("Target Service Assembly");
                        dlg.setFilterExtensions(new String[] { "*.zip" });
                        dlg.setOverwrite(true);

                        if (SuExportWizardPage.this.outputFile != null) {
                            dlg.setFileName(SuExportWizardPage.this.outputFile.getName());
                            File parentFile = SuExportWizardPage.this.outputFile.getParentFile();
                            if (parentFile != null)
                                dlg.setFilterPath(parentFile.getAbsolutePath());
                        }

                        String loc = dlg.open();
                        if (loc != null) {
                            if (!loc.endsWith(".zip"))
                                loc += ".zip";

                            fileText.setText(loc);
                            PetalsServicesPlugin.getDefault().getPreferenceStore().setValue(PREF_FILE_LOC, loc);
                        }
                    }
                });
            }

            // Refresh the container
            exportComposite.layout();
            validate();
        }
    });

    // Last UI details
    setControl(container);
    viewer.getTable().setFocus();
    exportCombo.select(0);
    exportCombo.notifyListeners(SWT.Selection, new Event());

    String msg = getErrorMessage();
    if (msg != null) {
        setErrorMessage(null);
        setMessage(msg, IMessageProvider.INFORMATION);
    }
}

From source file:com.ebmwebsourcing.petals.services.su.ui.ServiceOperationDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {

    // Create the parent
    Composite bigContainer = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;//from  w  w  w  .j ava 2  s  .  c o m
    bigContainer.setLayout(layout);
    bigContainer.setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite container = new Composite(bigContainer, SWT.NONE);
    container.setLayout(new GridLayout(2, true));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Put a viewer on the left
    final TableViewer viewer = new TableViewer(container, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new OperationLabelProvider()));
    viewer.setInput(this.opNameToMep.keySet());

    // Add widgets on the right
    Composite rightPart = new Composite(container, SWT.NONE);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    rightPart.setLayout(layout);
    rightPart.setLayoutData(new GridData(GridData.FILL_BOTH));

    final Button customOpButton = new Button(rightPart, SWT.CHECK);
    customOpButton.setText("Define a custom operation");
    GridData layoutData = new GridData();
    layoutData.horizontalSpan = 2;
    customOpButton.setLayoutData(layoutData);

    Label l = new Label(rightPart, SWT.NONE);
    l.setText("Name space:");
    l.setToolTipText("The operation's name space");

    this.nsText = new Text(rightPart, SWT.BORDER | SWT.SINGLE);
    this.nsText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    l = new Label(rightPart, SWT.NONE);
    l.setText("Name:");
    l.setToolTipText("The operation's name");

    this.nameText = new Text(rightPart, SWT.BORDER | SWT.SINGLE);
    this.nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    l = new Label(rightPart, SWT.NONE);
    l.setText("MEP:");
    l.setToolTipText("The Message Exchange Pattern");

    this.mepViewer = new ComboViewer(rightPart, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
    this.mepViewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    this.mepViewer.setContentProvider(new ArrayContentProvider());
    this.mepViewer.setLabelProvider(new LabelProvider());
    this.mepViewer.setInput(Mep.values());

    // Complete the dialog properties
    getShell().setText("Operation Viewer");
    setTitle("Operation Viewer");
    setMessage("View and edit service operations.");

    // Add the listeners
    customOpButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {

            ServiceOperationDialog.this.useCustomOperation = customOpButton.getSelection();
            ServiceOperationDialog.this.nsText.setEditable(customOpButton.getSelection());
            ServiceOperationDialog.this.nameText.setEditable(customOpButton.getSelection());
            ServiceOperationDialog.this.mepViewer.getCombo().setEnabled(customOpButton.getSelection());
            validate();
        }
    });

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            Object o = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            ServiceOperationDialog.this.nsText.setText(((QName) o).getNamespaceURI());
            ServiceOperationDialog.this.nameText.setText(((QName) o).getLocalPart());

            Mep mep = ServiceOperationDialog.this.opNameToMep.get(o);
            ServiceOperationDialog.this.mepViewer.setSelection(new StructuredSelection(mep));
        }
    });

    customOpButton.setSelection(false);
    customOpButton.notifyListeners(SWT.Selection, new Event());

    ModifyListener modifyListener = new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if ((((Text) e.widget).getStyle() & SWT.READ_ONLY) == 0)
                validate();
        }
    };

    this.nameText.addModifyListener(modifyListener);
    this.nsText.addModifyListener(modifyListener);
    this.mepViewer.getCombo().addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            if (((Combo) e.widget).isEnabled())
                validate();
        }
    });

    return bigContainer;
}

From source file:com.eclipsesource.rowtemplate.demo.RowTemplateDemo.java

License:Open Source License

private void createTable(Composite parent) {
    TableViewer tableViewer = new TableViewer(parent, getStyle());
    exampleControl = tableViewer.getTable();
    tableViewer.setContentProvider(new ArrayContentProvider());
    configColumnViewer(tableViewer);// w  ww. ja v a  2s.co m
    tableViewer.getTable().setHeaderVisible(headerVisible.getSelection());
    tableViewer.getTable().setLinesVisible(headerVisible.getSelection());
    tableViewer.getTable().addSelectionListener(new SelectionListener(parent));
}

From source file:com.exmaple.e4.tableFunctionality.edit.Snippet027ComboBoxCellEditors.java

License:Open Source License

public Snippet027ComboBoxCellEditors(Shell shell) {
    final Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
    final TableViewer v = new TableViewer(table);
    final MyCellModifier modifier = new MyCellModifier(v);

    TableColumn column = new TableColumn(table, SWT.NONE);
    column.setWidth(200);//from   w  ww .  ja va  2s . co  m

    v.setLabelProvider(new LabelProvider());
    v.setContentProvider(ArrayContentProvider.getInstance());
    v.setCellModifier(modifier);
    v.setColumnProperties(new String[] { "column1" });
    v.setCellEditors(new CellEditor[] { new ComboBoxCellEditor(v.getTable(), new String[] { "Zero", "Ten",
            "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" }) });

    v.setInput(createModel());
    v.getTable().setLinesVisible(true);
}