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

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

Introduction

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

Prototype

public TableViewer(Composite parent, int style) 

Source Link

Document

Creates a table viewer on a newly-created table control under the given parent.

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.ja v  a 2  s .  com*/
    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.contrastsecurity.ide.eclipse.ui.internal.views.VulnerabilitiesView.java

License:Open Source License

private void createViewer(Composite composite) {
    table = new TableViewer(composite, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    table.getTable().setLayoutData(gd);// w  ww.java 2s.  co m
    table.setLabelProvider(new VulnerabilityLabelProvider());
    TableColumn column = new TableColumn(table.getTable(), SWT.NONE);
    column.setWidth(80);
    column.setText("Severity");

    column.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (traceSort.startsWith(Constants.SORT_DESCENDING)) {
                traceSort = Constants.SORT_BY_SEVERITY;
            } else {
                traceSort = Constants.SORT_DESCENDING + Constants.SORT_BY_SEVERITY;
            }
            prefs.put(Constants.TRACE_SORT, traceSort);
            currentTraceFilterForm.setSort(traceSort);
            refreshTraces(false);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }

    });

    column = new TableColumn(table.getTable(), SWT.NONE);
    column.setWidth(600);
    column.setText("Vulnerability");

    column.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (traceSort.startsWith(Constants.SORT_DESCENDING)) {
                traceSort = Constants.SORT_BY_TITLE;
            } else {
                traceSort = Constants.SORT_DESCENDING + Constants.SORT_BY_TITLE;
            }
            prefs.put(Constants.TRACE_SORT, traceSort);
            currentTraceFilterForm.setSort(traceSort);
            refreshTraces(false);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }

    });

    column = new TableColumn(table.getTable(), SWT.NONE);
    column.setWidth(400);
    column.setText("Application");

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

        @Override
        public void mouseUp(MouseEvent e) {

        }

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

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            openVulnerabilityByMouseEvent(e.x, e.y, true);
        }
    });

    column = new TableColumn(table.getTable(), SWT.NONE);
    column.setWidth(100);
    column.setText("");

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

From source file:com.cordys.coe.tools.jmx.tables.MBeanAttributesTable.java

License:Apache License

/**
 * Creates a new MBeanAttributesTable object.
 *
 * @param  parent          DOCUMENTME/*www  .j  ava 2  s . c o  m*/
 * @param  uadDetailsView  DOCUMENTME
 */
public MBeanAttributesTable(Composite parent, IUpdateAttributeDetails uadDetailsView) {
    m_uadDetailsView = uadDetailsView;
    viewer = new TableViewer(parent, SWT.BORDER | SWT.FULL_SELECTION);

    final Table attrTable = viewer.getTable();
    attrTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    createColumns(attrTable);
    attrTable.setLinesVisible(true);
    attrTable.setHeaderVisible(true);

    viewer.setContentProvider(new AttributesContentProvider());
    viewer.setLabelProvider(new AttributesLabelProvider());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection ssSelection = (IStructuredSelection) event.getSelection();
            Object oTemp = ssSelection.getFirstElement();

            if (oTemp != null) {
                m_uadDetailsView.updateDetails((MBeanAttributeInfoWrapper) oTemp);
            }
        }
    });
}

From source file:com.cordys.coe.tools.jmx.tables.MBeanOperationsTable.java

License:Apache License

/**
 * Creates a new MBeanOperationsTable object.
 *
 * @param  parent              DOCUMENTME
 * @param  ohOperationHandler  DOCUMENTME
 *//*from   w  ww .j  a  v  a  2  s.  c  om*/
public MBeanOperationsTable(Composite parent, IOperationsHandler ohOperationHandler) {
    viewer = new TableViewer(parent, SWT.BORDER | SWT.FULL_SELECTION);
    m_ohOperationHandler = ohOperationHandler;

    final Table operationsTable = viewer.getTable();
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);

    operationsTable.setLayoutData(gd);

    createColumns(operationsTable);
    operationsTable.setLinesVisible(true);
    operationsTable.setHeaderVisible(true);

    viewer.setContentProvider(new MBeanOpContentProvider());
    viewer.setLabelProvider(new MBeanOpLabelProvider());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection ssSelection = (IStructuredSelection) event.getSelection();
            Object oTemp = ssSelection.getFirstElement();

            if (oTemp != null) {
                m_ohOperationHandler.updateDetails((MBeanOperationInfoWrapper) oTemp);
            }
        }
    });
}

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  ww  .  j  a  v a 2 s . c  o  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.drgarbage.bytecode.jdi.dialogs.SelectDebugTargetDialog.java

License:Apache License

private void createDebugTargetSelectionTable(Composite parent) {
    tableViewer = new TableViewer(parent, SWT.BORDER);
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            buttonPressed(OK);/* ww  w. j a v  a2s . c o  m*/
        }

    });

    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            updateEnablement();
        }

    });

    tableViewer.setContentProvider(new ArrayContentProvider());
    //        vmsTableViewer.setLabelProvider(new DefaultLabelProvider());
    tableViewer.setLabelProvider(new ITableLabelProvider() {

        public void addListener(ILabelProviderListener listener) {
        }

        public void dispose() {
        }

        public Image getColumnImage(Object element, int columnIndex) {
            if (columnIndex == 0 && element instanceof IJavaType[]) {
                IJavaType[] jts = (IJavaType[]) element;
                if (jts.length > 0) {
                    IJavaType firstType = jts[0];
                    // determine the image from the launch config type
                    String imageKey = getImageKey(firstType.getDebugTarget().getLaunch());

                    if (imageKey != null) {
                        return DebugPluginImages.getImage(imageKey);
                    }
                }
            }

            return null;
        }

        public String getColumnText(Object element, int columnIndex) {

            if (element instanceof IJavaType[]) {
                IJavaType[] jts = (IJavaType[]) element;
                if (jts.length > 0) {
                    IJavaType firstType = jts[0];
                    try {
                        return firstType.getDebugTarget().getName();
                    } catch (DebugException e) {
                    }
                }
            }
            return null;
        }

        private String getImageKey(ILaunch launch) {
            ILaunchConfiguration configuration = launch.getLaunchConfiguration();
            if (configuration != null) {
                try {
                    return configuration.getType().getIdentifier();
                } catch (CoreException e) {
                    BytecodeVisualizerPlugin.log(e);
                    return null;
                }
            }
            // if no config, use the old "mode" way
            if (launch.getLaunchMode().equals(ILaunchManager.DEBUG_MODE)) {
                return IDebugUIConstants.IMG_OBJS_LAUNCH_DEBUG;
            } else if (launch.isTerminated()) {
                return IDebugUIConstants.IMG_OBJS_LAUNCH_RUN_TERMINATED;
            } else {
                return IDebugUIConstants.IMG_OBJS_LAUNCH_RUN;
            }
        }

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

        public void removeListener(ILabelProviderListener listener) {
        }

    });
    tableViewer.addFilter(new ViewerFilter() {
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return true;
        }
    });
    tableViewer.setInput(displayCandidates);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
    data.heightHint = IDialogConstants.ENTRY_FIELD_WIDTH;
    tableViewer.getTable().setLayoutData(data);

}

From source file:com.drgarbage.bytecode.jdi.dialogs.SelectJavaTypeDialog.java

License:Apache License

private void createDebugTargetSelectionTable(Composite parent) {
    tableViewer = new TableViewer(parent, SWT.BORDER);

    Table t = tableViewer.getTable();//from w  w  w .  ja v  a2  s  .  c  o  m
    t.setHeaderVisible(true);

    TableColumn tc1 = new TableColumn(t, SWT.NONE);
    tc1.setText(BytecodeVisualizerMessages.SelectJavaTypeDialog_column_Type);
    TableColumn tc2 = new TableColumn(t, SWT.NONE);
    tc2.setText(BytecodeVisualizerMessages.SelectJavaTypeDialog_column_Class_Loader);

    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            buttonPressed(OK);
        }

    });

    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            updateEnablement();
        }

    });

    tableViewer.setContentProvider(new ArrayContentProvider());
    //        vmsTableViewer.setLabelProvider(new DefaultLabelProvider());
    tableViewer.setLabelProvider(new ITableLabelProvider() {

        public void addListener(ILabelProviderListener listener) {
        }

        public void dispose() {
        }

        public Image getColumnImage(Object element, int columnIndex) {
            if (columnIndex == 0) {
                return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_CLASS);
            }
            return null;
        }

        public String getColumnText(Object element, int columnIndex) {

            if (element instanceof JDIReferenceType) {
                try {
                    JDIReferenceType jt = (JDIReferenceType) element;

                    if (columnIndex == 0) {
                        return jt.getName();
                    } else if (columnIndex == 1) {
                        IJavaObject o = jt.getClassLoaderObject();
                        return o.getJavaType().getName() + JavaLexicalConstants.SPACE
                                + JavaLexicalConstants.LEFT_PARENTHESIS + ByteCodeConstants.ID
                                + JavaLexicalConstants.EQUALS + o.getUniqueId()
                                + JavaLexicalConstants.RIGHT_PARENTHESIS;
                    }
                } catch (DebugException ignore) {
                }
            }
            return null;
        }

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

        public void removeListener(ILabelProviderListener listener) {
        }

    });
    tableViewer.addFilter(new ViewerFilter() {
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return true;
        }
    });
    tableViewer.setInput(displayCandidates);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
    data.heightHint = IDialogConstants.ENTRY_FIELD_WIDTH;
    t.setLayoutData(data);

    tc1.pack();
    tc2.pack();

}

From source file:com.dubture.composer.ui.parts.TablePart.java

License:Open Source License

protected StructuredViewer createStructuredViewer(Composite parent, int style, FormToolkit toolkit) {
    style |= SWT.H_SCROLL | SWT.V_SCROLL;
    if (toolkit == null)
        style |= SWT.BORDER;/*from  w ww  .  ja va2  s  .  co  m*/
    else
        style |= toolkit.getBorderStyle();
    TableViewer tableViewer = new TableViewer(parent, style);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent e) {
            TablePart.this.selectionChanged((IStructuredSelection) e.getSelection());
        }
    });
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent e) {
            TablePart.this.handleDoubleClick((IStructuredSelection) e.getSelection());
        }
    });
    return tableViewer;
}

From source file:com.dubture.pdt.ui.wizards.classes.ClassCreationWizardPage.java

License:Open Source License

protected void createClassControls(final Composite container, int nColumns) {

    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = 200;//  w  w w  .  j  a v  a2 s. c  o  m

    filenameLabel = new Label(container, SWT.NONE);
    filenameLabel.setText("Filename:");

    filenameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    filenameText.setLayoutData(gd);

    if (initialFilename != null) {
        filenameText.setText(initialFilename);
        filename = initialFilename;
    }

    filenameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            filename = filenameText.getText();
            dialogChanged();

        }
    });

    Label ph3 = new Label(container, SWT.None);
    ph3.setText("");

    namespaceLabel = new Label(container, SWT.NONE);
    namespaceLabel.setText("Namespace:");

    namespaceText = new Text(container, SWT.BORDER | SWT.SINGLE);
    namespaceText.setLayoutData(gd);

    if (initialNamespace != null) {
        namespaceText.setText(initialNamespace);
    }

    namespaceText.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
            namespace = namespaceText.getText();
        }

        @Override
        public void keyPressed(KeyEvent e) {

        }
    });

    List<INamespaceResolver> resolvers = ExtensionManager.getDefault().getNamespaceResolvers();

    IScriptFolder folder = getScriptFolder();

    for (INamespaceResolver resolver : resolvers) {
        String ns = resolver.resolve(folder);
        if (ns != null && ns.length() > 0) {
            namespaceText.setText(ns);
            break;
        }
    }

    namespace = namespaceText.getText();

    Label ph1 = new Label(container, SWT.None);
    ph1.setText("");

    superClassLabel = new Label(container, SWT.NONE);
    superClassLabel.setText("Superclass:");

    superClassText = new Text(container, SWT.BORDER | SWT.SINGLE);
    superClassText.setLayoutData(gd);
    superClassText.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
            sClass = superClassText.getText();
        }

        @Override
        public void keyPressed(KeyEvent e) {

        }
    });

    superClassText.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            //            decoration.hide();            
        }

        @Override
        public void focusGained(FocusEvent e) {
            //            decoration.show();

        }
    });

    //TODO: find a way to retrieve the fully qualified name in the autocompletion
    // this doesn't perform when simply calling type.getFullyQualifiedname() in the proposal handler

    //      acField = new AutoCompleteField(superClassText, new TextContentAdapter(), null);

    //      decoration = new ControlDecoration(superClassLabel, SWT.RIGHT | SWT.TOP);

    //      Image errorImage = FieldDecorationRegistry.getDefault()
    //              .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL).getImage();
    //      decoration.setImage(errorImage);
    //      decoration.setDescriptionText("Content assist available.");
    //      decoration.setShowHover(true);
    //      decoration.hide();

    Button button = new Button(container, SWT.NULL);
    button.setText("Browse...");

    button.addSelectionListener(superClassSelectionListener);

    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = nColumns;
    gd.heightHint = 20;

    Label separator = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(gd);

    targetResourceLabel = new Label(container, SWT.NULL);
    targetResourceLabel.setText("Name:");

    fileText = new Text(container, SWT.BORDER | SWT.SINGLE);
    fileText.setFocus();
    gd = new GridData(GridData.FILL_HORIZONTAL);

    fileText.setLayoutData(gd);

    if (initialClassName != null) {
        fileText.setText(initialClassName);
        className = initialClassName;
    }

    fileText.addModifyListener(new ModifyListener() {
        public void modifyText(final ModifyEvent e) {
            dialogChanged();
            className = fileText.getText();
            filename = className + ".php";
            filenameText.setText(filename);
        }
    });

    Label empty = new Label(container, SWT.None);
    empty.setText("");

    Label modifierLabel = new Label(container, SWT.NULL);
    modifierLabel.setText("Modifiers:");

    gd = new GridData();
    gd.verticalAlignment = SWT.LEFT;

    RowLayout modifierLayout = new RowLayout(SWT.HORIZONTAL);

    Composite modifierContainer = new Composite(container, SWT.NULL);
    modifierContainer.setLayout(modifierLayout);

    abstractCheckbox = new Button(modifierContainer, SWT.CHECK | SWT.LEFT);
    abstractCheckbox.setText("abstract");
    abstractCheckbox.addSelectionListener(changeListener);

    finalCheckbox = new Button(modifierContainer, SWT.CHECK | SWT.LEFT);
    finalCheckbox.setText("final");
    finalCheckbox.addSelectionListener(changeListener);

    Label dummyLabel = new Label(container, SWT.NULL);
    dummyLabel.setText("");

    gd = new GridData();
    gd.verticalAlignment = SWT.TOP;

    Label interfaceLabel = new Label(container, SWT.NULL);
    interfaceLabel.setText("Interfaces:");
    interfaceLabel.setLayoutData(gd);

    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;

    interfaceTable = new TableViewer(container,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);

    interfaceTable.setContentProvider(ArrayContentProvider.getInstance());
    interfaceTable.setInput(interfaces);
    interfaceTable.getControl().setLayoutData(gridData);

    FillLayout buttonLayout = new FillLayout();
    buttonLayout.type = SWT.VERTICAL;

    gd = new GridData();
    gd.verticalAlignment = SWT.TOP;

    Composite buttonContainer = new Composite(container, SWT.NULL);
    buttonContainer.setLayout(buttonLayout);
    buttonContainer.setLayoutData(gd);

    Button addInterface = new Button(buttonContainer, SWT.NULL);
    addInterface.setText("Add...");
    addInterface.addSelectionListener(interfaceSelectionListener);

    Button removeInterface = new Button(buttonContainer, SWT.NULL);
    removeInterface.setText("Remove");

    removeInterface.addSelectionListener(interfaceRemoveListener);

    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalSpan = nColumns;
    gd.heightHint = 20;

    Label methodLabel = new Label(container, SWT.NONE);
    methodLabel.setText("Which method stubs would you like to create?");
    methodLabel.setLayoutData(gd);

    Label methodDummy = new Label(container, SWT.NONE);
    methodDummy.setText("");

    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalSpan = nColumns - 1;

    superClassConstructors = new Button(container, SWT.CHECK);
    superClassConstructors.setText("Superclass constructor");
    superClassConstructors.setLayoutData(gd);
    superClassConstructors.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            generateConstructor = superClassConstructors.getSelection();
        }
    });

    Label methodDummy2 = new Label(container, SWT.NONE);
    methodDummy2.setText("");

    abstractMethods = new Button(container, SWT.CHECK);
    abstractMethods.setText("Inherited abstract methods");
    abstractMethods.setSelection(true);
    abstractMethods.setLayoutData(gd);
    abstractMethods.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            generateAbstract = abstractMethods.getSelection();
        }
    });

    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalSpan = nColumns;
    gd.heightHint = 20;

    Label commentLabel = new Label(container, SWT.NONE);
    commentLabel.setText("Do you want to add comments?");
    commentLabel.setLayoutData(gd);

    Label dummy = new Label(container, SWT.NONE);
    dummy.setText("");

    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalSpan = nColumns - 1;

    commentCheckbox = new Button(container, SWT.CHECK);
    commentCheckbox.setText("Generate element comments");
    commentCheckbox.setLayoutData(gd);
    commentCheckbox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            generateComments = commentCheckbox.getSelection();
        }
    });

    dialogChanged();
    //      setControl(container);
    //      Dialog.applyDialogFont(container);

}

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);//from w  ww.  j  a v  a 2s  .  com

    // 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);
}