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

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

Introduction

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

Prototype

public TableViewerColumn(TableViewer viewer, TableColumn column) 

Source Link

Document

Creates a new viewer column for the given TableViewer on the given TableColumn .

Usage

From source file:com.bmw.spdxeditor.editors.spdx.SPDXEditor.java

License:Apache License

/**
 * Create the linked files group panel//  ww w.  j a  v  a2  s  .c o m
 * 
 * @param parent
 * @return
 * @throws InvalidSPDXAnalysisException
 */
private Composite createLinkedFilesDetailsPanel(Composite parent) throws InvalidSPDXAnalysisException {
    Group linkedFilesDetailsGroup = new Group(parent, SWT.SHADOW_ETCHED_IN);
    linkedFilesDetailsGroup.setText("Referenced files");
    GridLayout linkedFilesDetailsGroupLayout = new GridLayout();
    linkedFilesDetailsGroup.setLayout(linkedFilesDetailsGroupLayout);

    // Add table viewer
    final TableViewer tableViewer = new TableViewer(linkedFilesDetailsGroup,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);

    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.heightHint = 80;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    tableViewer.getControl().setLayoutData(gridData);

    // SWT Table
    final Table table = tableViewer.getTable();

    table.setToolTipText("Right-click to add or remove files");

    // Make header and columns visible
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());

    // Add context menu to TableViewer
    Menu linkesFileTableMenu = new Menu(parent.getShell(), SWT.POP_UP);
    MenuItem addNewLicenseText = new MenuItem(linkesFileTableMenu, SWT.PUSH);
    addNewLicenseText.setText("Add source code archive");
    addNewLicenseText.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // Retrieve the corresponding Services
            IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
            ICommandService commandService = (ICommandService) getSite().getService(ICommandService.class);

            // Retrieve the command
            Command generateCmd = commandService.getCommand("SPDXEditor.addLinkedSourceCodeFile");

            // Create an ExecutionEvent
            ExecutionEvent executionEvent = handlerService.createExecutionEvent(generateCmd, new Event());

            // Launch the command
            try {
                generateCmd.executeWithChecks(executionEvent);
            } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) {
                MessageDialog.openError(getSite().getShell(), "Error", e1.getMessage());
            }

        }
    });

    final MenuItem deleteSelectedLicenseTexts = new MenuItem(linkesFileTableMenu, SWT.PUSH);
    deleteSelectedLicenseTexts.setText("Delete selected source code archive");
    deleteSelectedLicenseTexts.setEnabled(false);
    deleteSelectedLicenseTexts.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // Retrieve the corresponding Services
            IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
            ICommandService commandService = (ICommandService) getSite().getService(ICommandService.class);
            // Retrieve the command
            Command generateCmd = commandService.getCommand("SPDXEditor.removedLinkedSourceCodeFile");
            // Create an ExecutionEvent
            ExecutionEvent executionEvent = handlerService.createExecutionEvent(generateCmd, new Event());
            // Launch the command
            try {
                generateCmd.executeWithChecks(executionEvent);
            } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) {
                MessageDialog.openError(getSite().getShell(), "Error", e1.getMessage());
            }
        }
    });

    table.setMenu(linkesFileTableMenu);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            deleteSelectedLicenseTexts.setEnabled(table.getSelectionCount() != 0);
        }
    });

    // Create TableViewer for each column
    TableViewerColumn viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    viewerNameColumn.getColumn().setText("File name");
    viewerNameColumn.getColumn().setWidth(160);

    viewerNameColumn.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            SPDXFile currentFile = (SPDXFile) cell.getElement();
            cell.setText(currentFile.getName());
        }
    });

    viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    viewerNameColumn.getColumn().setText("Type");
    viewerNameColumn.getColumn().setWidth(120);

    viewerNameColumn.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            SPDXFile currentFile = (SPDXFile) cell.getElement();
            cell.setText(currentFile.getType());
        }
    });
    // License choice for file
    viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    viewerNameColumn.getColumn().setText("Concluded License");
    viewerNameColumn.getColumn().setWidth(120);

    // // LabelProvider fr jede Spalte setzen
    viewerNameColumn.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            SPDXFile currentFile = (SPDXFile) cell.getElement();
            SPDXLicenseInfo spdxConcludedLicenseInfo = currentFile.getConcludedLicenses();
            cell.setText(getLicenseIdentifierTextForLicenseInfo(spdxConcludedLicenseInfo));

        }
    });

    viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    viewerNameColumn.getColumn().setText("SHA1 hash");
    viewerNameColumn.getColumn().setWidth(120);

    // LabelProvider fr jede Spalte setzen
    viewerNameColumn.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            SPDXFile currentFile = (SPDXFile) cell.getElement();
            cell.setText(currentFile.getSha1());
        }
    });

    SPDXFile[] referencedFiles = getInput().getAssociatedSPDXFile().getSpdxPackage().getFiles();
    tableViewer.setInput(referencedFiles);
    getSite().setSelectionProvider(tableViewer);

    this.getInput().addChangeListener(new IResourceChangeListener() {
        @Override
        public void resourceChanged(IResourceChangeEvent event) {
            SPDXFile[] referencedFiles;
            try {
                referencedFiles = getInput().getAssociatedSPDXFile().getSpdxPackage().getFiles();
                tableViewer.setInput(referencedFiles);
                tableViewer.refresh();
                setDirtyFlag(true);
            } catch (InvalidSPDXAnalysisException e) {
                MessageDialog.openError(getSite().getShell(), "SPDX Analysis invalid", e.getMessage());
            }
        }
    });

    GridData spdxDetailsPanelGridData = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
    spdxDetailsPanelGridData.horizontalSpan = 1;

    spdxDetailsPanelGridData.grabExcessVerticalSpace = true;
    spdxDetailsPanelGridData.grabExcessHorizontalSpace = true;
    spdxDetailsPanelGridData.minimumHeight = 90;
    linkedFilesDetailsGroup.setLayoutData(spdxDetailsPanelGridData);

    return linkedFilesDetailsGroup;
}

From source file:com.cisco.yangide.ext.model.editor.editors.YangDiagramModuleInfoPanel.java

License:Open Source License

protected Composite createImportTable(Composite parent) {
    final Table t = toolkit.createTable(parent, SWT.FULL_SELECTION | SWT.V_SCROLL);
    t.setLinesVisible(false);//from   w  w  w  .  ja va2  s  .co  m
    t.setHeaderVisible(false);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(t);
    importTable = new TableViewer(t);
    importTable.setContentProvider(new ArrayContentProvider());
    final TableViewerColumn col = new TableViewerColumn(importTable, SWT.NONE);
    col.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            return GraphitiUi.getImageService().getImageForId(YangDiagramImageProvider.DIAGRAM_TYPE_PROVIDER_ID,
                    YangDiagramImageProvider.IMG_IMPORT_PROPOSAL);
        }

        @Override
        public String getText(Object element) {
            if (YangModelUtil.checkType(YangModelUtil.MODEL_PACKAGE.getImport(), element)) {
                return ((Import) element).getPrefix() + " : " + ((Import) element).getModule();
            }
            return super.getText(element);
        }
    });
    t.addControlListener(new ControlListener() {
        @Override
        public void controlResized(ControlEvent e) {
            col.getColumn().setWidth(t.getSize().x - 30);
        }

        @Override
        public void controlMoved(ControlEvent e) {
        }
    });
    col.getColumn().setWidth(t.getSize().x - 30);
    return t;
}

From source file:com.cisco.yangide.ext.refactoring.ui.ChangeRevisionInputWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    Composite content = new Composite(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(3).spacing(0, 5).applyTo(content);

    new Label(content, SWT.NONE).setText(Messages.ChangeRevisionInputWizardPage_revisionLabel);
    revisionTxt = new Text(content, SWT.BORDER);
    revisionTxt.setEditable(false);/*  w w w  .  ja va 2 s  .c  o m*/
    Button revisionBtn = new Button(content, SWT.FLAT | SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.TOP).hint(24, 24).applyTo(revisionBtn);
    revisionBtn.setImage(RefactoringImages.getImage(RefactoringImages.IMG_CALENDAR));
    revisionBtn.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            RevisionDialog dialog = new RevisionDialog(getShell());
            try {
                dialog.setRevision(revisionTxt.getText());
            } catch (ParseException ex) {
                setErrorMessage(ex.getMessage());
                setPageComplete(false);
            }
            if (dialog.open() == Window.OK) {
                revisionTxt.setText(dialog.getRevision());
                setState();
            }
        }
    });

    new Label(content, SWT.NONE).setText(Messages.ChangeRevisionInputWizardPage_descriptionLabel);
    descriptionTxt = new Text(content, SWT.BORDER | SWT.MULTI);
    GridDataFactory.fillDefaults().span(4, 1).align(SWT.FILL, SWT.TOP).grab(true, false).hint(SWT.DEFAULT, 50)
            .applyTo(descriptionTxt);

    descriptionTxt.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            setState();
        }
    });

    newFileCheck = new Button(content, SWT.CHECK);
    GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.TOP).applyTo(newFileCheck);
    newFileCheck.setText(Messages.ChangeRevisionInputWizardPage_newFileCheckLabel);
    newFileCheck.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            setState();
        }
    });

    Label tableLabel = new Label(content, SWT.NONE);
    tableLabel.setText(Messages.ChangeRevisionInputWizardPage_refGroupLabel);
    GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(tableLabel);

    Composite group = new Composite(content, SWT.NONE);
    GridLayoutFactory.swtDefaults().margins(0, 0).numColumns(2).applyTo(group);
    GridDataFactory.fillDefaults().span(3, 1).grab(true, true).align(SWT.FILL, SWT.TOP).applyTo(group);

    table = new TableViewer(group, SWT.CHECK | SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, true).hint(SWT.DEFAULT, 200)
            .applyTo(table.getControl());
    table.setContentProvider(ArrayContentProvider.getInstance());
    table.getTable().setHeaderVisible(true);
    table.getTable().setLinesVisible(true);

    TableViewerColumn viewerColumn = new TableViewerColumn(table, SWT.NONE);
    TableColumn column = viewerColumn.getColumn();
    column.setText(Messages.ChangeRevisionInputWizardPage_refTableName);
    column.setWidth(250);
    column.setResizable(true);
    viewerColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public Image getImage(Object element) {
            return YangUIImages.getImage(IYangUIConstants.IMG_YANG_FILE);
        }

        @Override
        public String getText(Object element) {
            IFile file = (IFile) element;
            return file.getName();
        }
    });

    viewerColumn = new TableViewerColumn(table, SWT.NONE);
    column = viewerColumn.getColumn();
    column.setText(Messages.ChangeRevisionInputWizardPage_refTablePath);
    column.setWidth(300);
    column.setResizable(true);
    viewerColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            IFile file = (IFile) element;
            return file.getProjectRelativePath().toString();
        }
    });

    viewerColumn = new TableViewerColumn(table, SWT.NONE);
    column = viewerColumn.getColumn();
    column.setText(Messages.ChangeRevisionInputWizardPage_refTableProject);
    column.setWidth(200);
    column.setResizable(true);
    viewerColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            IFile file = (IFile) element;
            return file.getProject().getName();
        }
    });

    Composite controls = new Composite(group, SWT.NONE);
    GridLayoutFactory.swtDefaults().margins(0, 0).applyTo(controls);
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.TOP).applyTo(controls);

    Button tableSelectAllBtn = new Button(controls, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).applyTo(tableSelectAllBtn);
    tableSelectAllBtn.setText(Messages.ChangeRevisionInputWizardPage_refTableSellectAllBtn);
    tableSelectAllBtn.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            for (int i = 0; i < table.getTable().getItemCount(); i++) {
                table.getTable().getItem(i).setChecked(true);
            }
            setState();
        }
    });

    Button tableDeselectAllBtn = new Button(controls, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).applyTo(tableDeselectAllBtn);
    tableDeselectAllBtn.setText(Messages.ChangeRevisionInputWizardPage_refTableDeselectAllBtn);
    tableDeselectAllBtn.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            for (int i = 0; i < table.getTable().getItemCount(); i++) {
                table.getTable().getItem(i).setChecked(false);
            }
            setState();
        }
    });
    table.getTable().addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            setState();
        }
    });

    Dialog.applyDialogFont(content);
    setControl(content);
}

From source file:com.cloudbees.eclipse.dev.ui.views.build.BuildHistoryView.java

License:Open Source License

private TableViewerColumn createColumn(final String colName, final int width, final int sortCol,
        final CellLabelProvider cellLabelProvider) {
    final TableViewerColumn treeViewerColumn = new TableViewerColumn(this.table, SWT.NONE);
    TableColumn col = treeViewerColumn.getColumn();

    if (width > 0) {
        col.setWidth(width);/*from  ww  w .j  a  v  a  2s. c  o m*/
    }

    col.setText(colName);
    col.setMoveable(true);

    treeViewerColumn.setLabelProvider(cellLabelProvider);

    if (sortCol >= 0) {

        treeViewerColumn.getColumn().addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(final SelectionEvent e) {

                int newOrder = SWT.DOWN;

                if (BuildHistoryView.this.table.getTable().getSortColumn().equals(treeViewerColumn.getColumn())
                        && BuildHistoryView.this.table.getTable().getSortDirection() == SWT.DOWN) {
                    newOrder = SWT.UP;
                }

                BuildHistoryView.this.table.getTable().setSortColumn(treeViewerColumn.getColumn());
                BuildHistoryView.this.table.getTable().setSortDirection(newOrder);
                BuildSorter newSorter = new BuildSorter(sortCol);
                newSorter.setDirection(newOrder);
                BuildHistoryView.this.table.setSorter(newSorter);
            }
        });
    }
    return treeViewerColumn;
}

From source file:com.cloudbees.eclipse.run.ui.wizards.ClickStartComposite.java

License:Open Source License

private void init() {

    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = 0;//from  w  w w.j  a  v a  2s.c  o m
    layout.marginWidth = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginTop = 10;
    setLayout(layout);

    GridData d1 = new GridData();
    d1.horizontalSpan = 1;
    d1.grabExcessHorizontalSpace = true;
    d1.grabExcessVerticalSpace = true;
    d1.horizontalAlignment = SWT.FILL;
    d1.verticalAlignment = SWT.FILL;
    setLayoutData(d1);

    Group group = new Group(this, SWT.FILL);
    group.setText(GROUP_LABEL);

    GridLayout grl = new GridLayout(1, false);
    grl.horizontalSpacing = 0;
    grl.verticalSpacing = 0;
    grl.marginHeight = 0;
    grl.marginWidth = 0;
    grl.marginTop = 4;
    group.setLayout(grl);

    GridData data = new GridData();
    data.horizontalSpan = 1;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    data.horizontalAlignment = SWT.FILL;
    data.verticalAlignment = SWT.FILL;
    group.setLayoutData(data);

    /*   this.addTemplateCheck = new Button(group, SWT.CHECK);
       this.addTemplateCheck.setText(FORGE_REPO_CHECK_LABEL);
       this.addTemplateCheck.setSelection(false);
       this.addTemplateCheck.setLayoutData(data);
       this.addTemplateCheck.addSelectionListener(new MakeForgeRepoSelectionListener());
            
       data = new GridData();
       data.verticalAlignment = SWT.CENTER;
            
       this.templateLabel = new Label(group, SWT.NULL);
       this.templateLabel.setLayoutData(data);
       this.templateLabel.setText("Template:");
       this.templateLabel.setEnabled(false);
            
       data = new GridData();
       data.grabExcessHorizontalSpace = true;
       data.horizontalAlignment = SWT.FILL;
            
       this.templateCombo = new Combo(group, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
       this.templateCombo.setLayoutData(data);
       this.templateCombo.setEnabled(false);
       this.repoComboViewer = new ComboViewer(this.templateCombo);
       this.repoComboViewer.setLabelProvider(new TemplateLabelProvider());
       this.repoComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
            
         public void selectionChanged(final SelectionChangedEvent event) {
           ISelection selection = ClickStartComposite.this.repoComboViewer.getSelection();
           if (selection instanceof StructuredSelection) {
     ClickStartComposite.this.selectedTemplate = (ClickStartTemplate) ((StructuredSelection) selection)
         .getFirstElement();
           }
           validate();
         }
       });*/
    /*
            
    Composite compositeJenkinsInstances = new Composite(group, SWT.NONE);
    compositeJenkinsInstances.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    GridLayout gl_compositeJenkinsInstances = new GridLayout(2, false);
    gl_compositeJenkinsInstances.marginWidth = 0;
    compositeJenkinsInstances.setLayout(gl_compositeJenkinsInstances);
    */
    Composite compositeTable = new Composite(group, SWT.NONE);
    compositeTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    GridLayout gl_compositeTable = new GridLayout(1, false);
    gl_compositeTable.marginHeight = 0;
    gl_compositeTable.marginWidth = 0;
    compositeTable.setLayout(gl_compositeTable);

    v = new TableViewer(compositeTable, SWT.BORDER | SWT.FULL_SELECTION);
    v.getTable().setLinesVisible(true);
    v.getTable().setHeaderVisible(true);
    v.setContentProvider(templateProvider);
    v.setInput("");

    v.getTable().setLayout(new GridLayout(1, false));

    GridData vgd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    v.getTable().setLayoutData(vgd);
    ColumnViewerToolTipSupport.enableFor(v, ToolTip.NO_RECREATE);

    CellLabelProvider labelProvider = new CellLabelProvider() {

        public String getToolTipText(Object element) {
            ClickStartTemplate t = (ClickStartTemplate) element;
            return t.description;
        }

        public Point getToolTipShift(Object object) {
            return new Point(5, 5);
        }

        public int getToolTipDisplayDelayTime(Object object) {
            return 200;
        }

        public int getToolTipTimeDisplayed(Object object) {
            return 10000;
        }

        public void update(ViewerCell cell) {
            int idx = cell.getColumnIndex();
            ClickStartTemplate t = (ClickStartTemplate) cell.getElement();
            if (idx == 0) {
                cell.setText(t.name);
            } else if (idx == 1) {
                String comps = "";

                for (int i = 0; i < t.components.length; i++) {
                    comps = comps + t.components[i].name;
                    if (i < t.components.length - 1) {
                        comps = comps + ", ";
                    }
                }
                cell.setText(comps);
            }

        }

    };

    /*    this.table = new Table(compositeTable, SWT.BORDER | SWT.FULL_SELECTION);
        this.table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        this.table.setHeaderVisible(true);
        this.table.setLinesVisible(true);
    */
    v.getTable().addSelectionListener(new SelectionListener() {

        public void widgetSelected(final SelectionEvent e) {
            selectedTemplate = (ClickStartTemplate) e.item.getData();
            ClickStartComposite.this.fireTemplateChanged();
        }

        public void widgetDefaultSelected(final SelectionEvent e) {
            selectedTemplate = (ClickStartTemplate) e.item.getData();
            ClickStartComposite.this.fireTemplateChanged();
        }
    });

    //ColumnViewerToolTipSupport

    TableViewerColumn tblclmnLabel = new TableViewerColumn(v, SWT.NONE);
    tblclmnLabel.getColumn().setWidth(300);
    tblclmnLabel.getColumn().setText("Template");//TODO i18n
    tblclmnLabel.setLabelProvider(labelProvider);

    TableViewerColumn tblclmnUrl = new TableViewerColumn(v, SWT.NONE);
    tblclmnUrl.getColumn().setWidth(800);
    tblclmnUrl.getColumn().setText("Components");//TODO i18n
    tblclmnUrl.setLabelProvider(labelProvider);

    loadData();

    //Group group2 = new Group(this, SWT.NONE);
    //group2.setText("");
    //group2.setLayout(ld2);
    GridData data2 = new GridData();
    data2.horizontalSpan = 1;
    data2.grabExcessHorizontalSpace = true;
    //data2.grabExcessVerticalSpace = true;
    data2.horizontalAlignment = SWT.FILL;
    //data2.verticalAlignment = SWT.FILL;
    //group2.setLayoutData(data2);

    browser = new Browser(this, SWT.NONE);
    //browser.getVerticalBar().setVisible(false);
    //browser.getHorizontalBar().setVisible(false);

    GridLayout ld2 = new GridLayout(2, true);
    ld2.horizontalSpacing = 0;
    ld2.verticalSpacing = 0;
    ld2.marginHeight = 0;
    ld2.marginWidth = 0;

    GridData gd2 = new GridData(SWT.FILL, SWT.FILL);
    gd2.heightHint = 50;
    gd2.horizontalSpan = 1;
    gd2.grabExcessHorizontalSpace = true;
    gd2.grabExcessVerticalSpace = false;
    gd2.horizontalAlignment = SWT.FILL;

    browser.setLayout(ld2);
    browser.setLayoutData(gd2);

    Color bg = this.getBackground();
    bgStr = "rgb(" + bg.getRed() + "," + bg.getGreen() + "," + bg.getBlue() + ")";

    browser.setText("<html><head><style>body{background-color:" + bgStr
            + ";margin:0px;padding:0px;width:100%;}</style></head><body style='overflow:hidden;'></body></html>");

    //shell.open();

    //browser.setUrl("https://google.com");

    browser.addLocationListener(new LocationListener() {

        @Override
        public void changing(LocationEvent event) {
            String url = event.location;
            try {
                if (url != null && url.startsWith("http")) {
                    event.doit = false;
                    PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(url));
                }
            } catch (PartInitException e) {
                e.printStackTrace();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void changed(LocationEvent event) {
            //event.doit = false;
        }
    });

    v.getTable().setFocus();

    /*    getParent().setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
        setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
        group.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_CYAN));
        v.getTable().setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GREEN));
        browser.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_YELLOW));
    */}

From source file:com.clustercontrol.hub.composite.LogSearchComposite.java

License:Open Source License

private void initialize() {
    setLayout(new GridLayout(1, false));

    // UI/*from   www  .  j a va 2  s .  com*/
    Composite searchComposite = new Composite(this, SWT.NONE);
    searchComposite.setLayout(new GridLayout(1, false));

    Composite compositePeriod = new Composite(searchComposite, SWT.NONE);
    GridLayout gl_groupPeriod = new GridLayout(12, false);
    gl_groupPeriod.verticalSpacing = 0;
    compositePeriod.setLayout(gl_groupPeriod);
    GridData gd_groupPeriod = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_groupPeriod.widthHint = 50;
    compositePeriod.setLayoutData(gd_groupPeriod);

    Label lblPeriod = new Label(compositePeriod, SWT.NONE);
    GridData gd_lblPeriod = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
    gd_lblPeriod.widthHint = 81;
    lblPeriod.setLayoutData(gd_lblPeriod);
    lblPeriod.setText(Messages.getString("view.hub.log.search.condition.period.select"));

    cmbPeriod = new Combo(compositePeriod, SWT.READ_ONLY);
    GridData gd_cmbPeriod = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_cmbPeriod.widthHint = 111;
    cmbPeriod.setLayoutData(gd_cmbPeriod);
    cmbPeriod.setText(LogSearchPeriodConstants.ALL);
    cmbPeriod.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Combo select = (Combo) e.getSource();
            List<Calendar> list = LogSearchPeriodConstants.getPeriod(select.getText());
            if (list == null) {
                cmbPeriod.setText(LogSearchPeriodConstants.ALL);
            } else {
                dateTimeCompositeFrom.setPeriod(list.get(0));
                dateTimeCompositeTo.setPeriod(list.get(1));
            }
            if (LogSearchPeriodConstants.ALL.equals(select.getText())) {
                enableDateTime(false);
            } else {
                enableDateTime(true);
            }
            update();
        }
    });

    Label label = new Label(compositePeriod, SWT.NONE);
    GridData gd_label = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_label.widthHint = 10;
    label.setLayoutData(gd_label);

    dateTimeCompositeFrom = new LogSearchDateTimeComposite(compositePeriod, SWT.NONE);
    GridData gd_dateTimeComposite = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    gd_dateTimeComposite.widthHint = 250;
    dateTimeCompositeFrom.setLayoutData(gd_dateTimeComposite);
    GridLayout gridLayout = (GridLayout) dateTimeCompositeFrom.getLayout();
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;

    Label lblFromTo = new Label(compositePeriod, SWT.NONE);
    lblFromTo.setAlignment(SWT.CENTER);
    GridData gd_lblFromTo = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_lblFromTo.widthHint = 39;
    lblFromTo.setLayoutData(gd_lblFromTo);
    lblFromTo.setText(Messages.getString("wave"));

    dateTimeCompositeTo = new LogSearchDateTimeComposite(compositePeriod, SWT.NONE);
    gd_dateTimeComposite = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    gd_dateTimeComposite.widthHint = 250;
    dateTimeCompositeTo.setLayoutData(gd_dateTimeComposite);
    gridLayout = (GridLayout) dateTimeCompositeTo.getLayout();
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    enableDateTime(false);

    // UI - 
    Composite compositeKeyword = new Composite(searchComposite, SWT.NONE);
    GridLayout gl_compositeKeyword = new GridLayout(4, false);
    gl_compositeKeyword.marginHeight = 0;
    compositeKeyword.setLayout(gl_compositeKeyword);
    GridData gd_compositeKeyword = new GridData(SWT.FILL, SWT.TOP, true, true, 1, 1);
    gd_compositeKeyword.heightHint = 60;
    compositeKeyword.setLayoutData(gd_compositeKeyword);

    Label lblMonitorId = new Label(compositeKeyword, SWT.NONE);
    GridData gd_lblMonitorId = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_lblMonitorId.widthHint = 81;
    lblMonitorId.setLayoutData(gd_lblMonitorId);
    lblMonitorId.setText(Messages.getString("monitor.id"));

    cmbMonitorId = new Combo(compositeKeyword, SWT.READ_ONLY);
    GridData gd_monitorId = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
    gd_monitorId.heightHint = 18;
    gd_monitorId.widthHint = 481;
    cmbMonitorId.setLayoutData(gd_monitorId);
    cmbMonitorId.addMouseListener(new MouseListener() {
        @Override
        public void mouseDoubleClick(MouseEvent e) {
        }

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

        @Override
        public void mouseUp(MouseEvent e) {
        }
    });
    new Label(compositeKeyword, SWT.NONE);
    for (String str : LogSearchPeriodConstants.getPeriodStrList()) {
        cmbPeriod.add(str);
    }
    cmbPeriod.select(0);

    new Label(compositeKeyword, SWT.NONE);

    Label lblKeyword = new Label(compositeKeyword, SWT.NONE);
    GridData gd_lblKeyword = new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1);
    gd_lblKeyword.widthHint = 81;
    lblKeyword.setLayoutData(gd_lblKeyword);
    lblKeyword.setText(Messages.getString("view.hub.log.search.condition.keyword"));

    txtKeywords = new Text(compositeKeyword, SWT.BORDER);
    GridData gd_txtKeywords = new GridData(SWT.FILL, SWT.BOTTOM, true, false, 1, 1);
    gd_txtKeywords.widthHint = 436;
    txtKeywords.setLayoutData(gd_txtKeywords);

    // UI - ? AND/OR
    Composite compositeConditionAndOr = new Composite(compositeKeyword, SWT.NONE);
    GridLayout gl_compositeConditionAndOr = new GridLayout(2, false);
    gl_compositeConditionAndOr.verticalSpacing = 1;
    compositeConditionAndOr.setLayout(gl_compositeConditionAndOr);
    compositeConditionAndOr.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1));

    btnAnd = new Button(compositeConditionAndOr, SWT.RADIO);
    btnAnd.setText(Messages.getString("and"));
    btnAnd.setSelection(true);

    btnOr = new Button(compositeConditionAndOr, SWT.RADIO);
    btnOr.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
    btnOr.setText(Messages.getString("or"));

    Button btnSearchSimply = new Button(compositeKeyword, SWT.NONE);
    GridData gd_btnSearchSimply = new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1);
    gd_btnSearchSimply.widthHint = 80;
    btnSearchSimply.setLayoutData(gd_btnSearchSimply);
    btnSearchSimply.setSize(300, 30);
    btnSearchSimply.setText(Messages.getString("search"));
    btnSearchSimply.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // 
            StringQueryInfo query = makeNewQuery();
            StringQueryResult stringQueryResult = getQueryExecute(manager, query);
            updateResultComposite(query, stringQueryResult);
        }
    });

    // ?UI
    Composite resultComposite = new Composite(this, SWT.NONE);
    resultComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    resultComposite.setLayout(new GridLayout(2, false));
    TabFolder tabFolder = new TabFolder(resultComposite, SWT.NONE);
    GridData gd_tabFolder = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd_tabFolder.heightHint = 676;
    tabFolder.setLayoutData(gd_tabFolder);

    // Not working Start(WindowBuilder)
    TabItem tbtmTable = new TabItem(tabFolder, SWT.NONE);
    tbtmTable.setText(Messages.getString("view.hub.log.search.result.tab.list"));

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

    TableColumnLayout tcl_composite_1 = new TableColumnLayout();
    compositeTable.setLayout(tcl_composite_1);

    tableViewer = new TableViewer(compositeTable, SWT.FULL_SELECTION | SWT.MULTI);
    ColumnViewerToolTipSupport.enableFor(tableViewer);
    table = tableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);

    for (final ViewColumn column : ViewColumn.values()) {
        TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
        TableColumn tableColumn = tableViewerColumn.getColumn();
        tcl_composite_1.setColumnData(tableColumn, column.getPixelData());
        tableColumn.setText(column.getLabel());
        tableViewerColumn.setLabelProvider(column.getProvider());
        tableColumn.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                tableViewer.setSorter(new TableViewerSorter(tableViewer, column.getProvider()));
            }
        });
    }
    tableViewer.setContentProvider(new ArrayContentProvider());
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
        }
    });
    tableViewer.setSorter(new CommonTableViewerSorter(ViewColumn.time.ordinal()));

    TabItem tbtmSource = new TabItem(tabFolder, SWT.NONE);
    tbtmSource.setText(Messages.getString("view.hub.log.search.result.tab.original.message"));

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

    GridData gd_Source = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_Source.heightHint = 634;
    compositeSource.setLayoutData(gd_Source);

    browser = new Text(compositeSource, SWT.READ_ONLY | SWT.MULTI);
    browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    // Not working End(WindowBuilder)

    Composite compositePageNumber = new Composite(resultComposite, SWT.NONE);
    GridLayout gl_compositePageNumber = new GridLayout(6, false);
    gl_compositePageNumber.marginHeight = 0;
    compositePageNumber.setLayout(gl_compositePageNumber);
    GridData gd_pagerComposite = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    //      gd_pagerComposite.heightHint = 24;
    //      gd_pagerComposite.widthHint = 411;
    compositePageNumber.setLayoutData(gd_pagerComposite);

    lbltotal = new Label(compositePageNumber, SWT.RIGHT);
    GridData gd_lbltotal = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    lbltotal.setLayoutData(gd_lbltotal);
    lbltotal.setText(Messages.getString("view.hub.log.search.result.page.number",
            new Object[] { "0", "0", "0", "0.0" }));

    btnTop = new Button(compositePageNumber, SWT.NONE);
    btnTop.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    btnTop.setText("<<");
    btnTop.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            StringQueryInfo query = makeContinuousQuery(0, getDataCountPerPage(getTable()));
            StringQueryResult stringQueryResult = getQueryExecute(manager, query);
            updateResultComposite(query, stringQueryResult);
        }
    });
    btnTop.setEnabled(false);

    btnPerv = new Button(compositePageNumber, SWT.NONE);
    btnPerv.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    btnPerv.setText("<");
    btnPerv.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int offset = Math.max(0, dispOffset - getDataCountPerPage(getTable()));
            StringQueryInfo query = makeContinuousQuery(offset, getDataCountPerPage(getTable()));
            StringQueryResult stringQueryResult = getQueryExecute(manager, query);
            updateResultComposite(query, stringQueryResult);
        }
    });
    btnPerv.setEnabled(false);

    Composite composite = new Composite(compositePageNumber, SWT.NONE);
    GridData gd_composite = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
    gd_composite.widthHint = 133;
    composite.setLayoutData(gd_composite);
    GridData gd_compositePageNumber = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_compositePageNumber.widthHint = 76;
    composite.setLayoutData(gd_compositePageNumber);
    composite.setLayout(new GridLayout(1, false));
    lblPage = new Label(composite, SWT.CENTER);
    lblPage.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    lblPage.setText("0 / 0");

    btnNext = new Button(compositePageNumber, SWT.NONE);
    btnNext.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    btnNext.setText(">");
    btnNext.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int offset = dispOffset + dispSize;
            StringQueryInfo query = makeContinuousQuery(offset, getDataCountPerPage(getTable()));
            StringQueryResult stringQueryResult = getQueryExecute(manager, query);
            // ?????
            if (0 == stringQueryResult.getSize()) {
                return;
            }
            updateResultComposite(query, stringQueryResult);
        }
    });
    btnNext.setEnabled(false);

    btnEnd = new Button(compositePageNumber, SWT.NONE);
    btnEnd.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    btnEnd.setText(">>");
    btnEnd.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int dataCountPerPage = getDataCountPerPage(getTable());
            int pageCount = dataCount / dataCountPerPage;
            pageCount = (dataCount % dataCountPerPage) == 0 ? pageCount - 1 : pageCount;
            int offset = pageCount * dataCountPerPage;
            StringQueryInfo query = makeContinuousQuery(offset, getDataCountPerPage(getTable()));
            StringQueryResult stringQueryResult = getQueryExecute(manager, query);
            // ?????
            if (0 == stringQueryResult.getSize()) {
                return;
            }
            updateResultComposite(query, stringQueryResult);
        }
    });
    btnEnd.setEnabled(false);
}

From source file:com.codenvy.eclipse.ui.wizard.exporter.pages.ProjectWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    final Composite wizardContainer = new Composite(parent, SWT.NONE);
    wizardContainer.setLayout(new GridLayout(2, false));

    final Label projectsTableLabel = new Label(wizardContainer, SWT.NONE);
    projectsTableLabel.setText("Projects:");
    projectsTableLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    projectsTableViewer = newCheckList(wizardContainer,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    projectsTableViewer.setContentProvider(ArrayContentProvider.getInstance());

    final TableViewerColumn projectNameColumn = new TableViewerColumn(projectsTableViewer, SWT.NONE);
    projectNameColumn.getColumn().setWidth(450);
    projectNameColumn.getColumn().setText("Name");
    projectNameColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override/*from   w  ww .  jav  a  2 s.c om*/
        public String getText(Object element) {
            return element instanceof IProject ? ((IProject) element).getName() : super.getText(element);
        }
    });

    projectsTableViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    projectsTableViewer.addCheckStateListener(new ICheckStateListener() {
        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getChecked()) {
                selectedProjects.add((IProject) event.getElement());
            } else {
                selectedProjects.remove(event.getElement());
            }
            validatePage();
        }
    });

    projectsTableViewer.setInput(ResourcesPlugin.getWorkspace().getRoot().getProjects());
    projectsTableViewer.setCheckedElements(selectedProjects.toArray());

    final Composite projectTableButtonsContainer = new Composite(wizardContainer, SWT.NONE);
    projectTableButtonsContainer.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, true, true));
    projectTableButtonsContainer.setLayout(new GridLayout());

    final Button selectAll = new Button(projectTableButtonsContainer, SWT.NONE);
    selectAll.setText("Select All");
    selectAll.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    selectAll.addSelectionListener(new SelectionAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            projectsTableViewer.setAllChecked(true);
            selectedProjects.addAll(
                    (Collection<? extends IProject>) Arrays.asList(projectsTableViewer.getCheckedElements()));
            validatePage();
        }
    });

    final Button deselectAll = new Button(projectTableButtonsContainer, SWT.NONE);
    deselectAll.setText("Deselect All");
    deselectAll.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    deselectAll.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            projectsTableViewer.setAllChecked(false);
            selectedProjects.clear();
            validatePage();
        }
    });

    setControl(wizardContainer);
}

From source file:com.codenvy.eclipse.ui.wizard.importer.pages.ProjectWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    final Composite wizardContainer = new Composite(parent, SWT.NONE);
    wizardContainer.setLayout(new GridLayout(2, false));
    wizardContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final Composite workspaceSelectionContainer = new Composite(wizardContainer, SWT.NONE);
    workspaceSelectionContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    workspaceSelectionContainer.setLayout(new GridLayout(2, false));

    final Label workspaceLabel = new Label(workspaceSelectionContainer, SWT.NONE);
    workspaceLabel.setText("Workspace:");

    workspaceComboViewer = new ComboViewer(workspaceSelectionContainer, SWT.DROP_DOWN | SWT.READ_ONLY);
    workspaceComboViewer.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    workspaceComboViewer.setContentProvider(new ArrayContentProvider());
    workspaceComboViewer.setLabelProvider(new LabelProvider() {
        @Override//w  w  w  .  jav a 2 s. c o  m
        public String getText(Object element) {
            return element instanceof WorkspaceReference ? ((WorkspaceReference) element).name()
                    : super.getText(element);
        }
    });
    workspaceComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (!selection.isEmpty()) {
                loadWorkspaceProjects((WorkspaceReference) selection.getFirstElement());
            }
        }
    });

    final Label projectTableLabel = new Label(wizardContainer, SWT.NONE);
    projectTableLabel.setText("Projects:");
    projectTableLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    projectTableViewer = newCheckList(wizardContainer,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);

    final TableViewerColumn projectNameColumn = new TableViewerColumn(projectTableViewer, SWT.NONE);
    projectNameColumn.getColumn().setWidth(150);
    projectNameColumn.getColumn().setText("Name");
    projectNameColumn.setLabelProvider(new ColumnLabelProviderWithGreyElement() {
        @Override
        public String getText(Object element) {
            return element instanceof ProjectReference ? ((ProjectReference) element).name()
                    : super.getText(element);
        }
    });

    final TableViewerColumn projectTypeNameColumn = new TableViewerColumn(projectTableViewer, SWT.NONE);
    projectTypeNameColumn.getColumn().setWidth(150);
    projectTypeNameColumn.getColumn().setText("Type");
    projectTypeNameColumn.setLabelProvider(new ColumnLabelProviderWithGreyElement() {
        @Override
        public String getText(Object element) {
            return element instanceof ProjectReference ? ((ProjectReference) element).typeName()
                    : super.getText(element);
        }
    });

    final TableViewerColumn projectDescriptionColumn = new TableViewerColumn(projectTableViewer, SWT.NONE);
    projectDescriptionColumn.getColumn().setWidth(150);
    projectDescriptionColumn.getColumn().setText("Description");
    projectDescriptionColumn.setLabelProvider(new ColumnLabelProviderWithGreyElement() {
        @Override
        public String getText(Object element) {
            return element instanceof ProjectReference ? ((ProjectReference) element).description()
                    : super.getText(element);
        }
    });
    projectTableViewer.setContentProvider(ArrayContentProvider.getInstance());
    projectTableViewer.addCheckStateListener(new ICheckStateListener() {
        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            setCheckedProjects();
            validatePage();
        }
    });

    final Table projectTable = projectTableViewer.getTable();
    projectTable.getHorizontalBar().setEnabled(true);
    projectTable.setHeaderVisible(true);
    projectTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final Composite projectTableButtonsContainer = new Composite(wizardContainer, SWT.NONE);
    projectTableButtonsContainer.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, true));
    projectTableButtonsContainer.setLayout(new GridLayout());

    final Button selectAll = new Button(projectTableButtonsContainer, SWT.NONE);
    selectAll.setText("Select All");
    selectAll.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    selectAll.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            projectTableViewer.setAllChecked(true);

            setCheckedProjects();
            validatePage();
        }
    });

    final Button deselectAll = new Button(projectTableButtonsContainer, SWT.NONE);
    deselectAll.setText("Deselect All");
    deselectAll.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    deselectAll.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            projectTableViewer.setAllChecked(false);

            setCheckedProjects();
            validatePage();
        }
    });

    // TODO remove when https://bugs.eclipse.org/bugs/show_bug.cgi?id=245106 is fixed
    final WorkingSetDescriptor[] descriptors = WorkbenchPlugin.getDefault().getWorkingSetRegistry()
            .getWorkingSetDescriptors();
    final List<String> workingSetTypes = FluentIterable.from(Arrays.asList(descriptors))
            .transform(new Function<WorkingSetDescriptor, String>() {
                @Override
                public String apply(WorkingSetDescriptor descriptor) {
                    return descriptor.getId();
                }
            }).toList();

    workingSetGroup = new WorkingSetGroup(wizardContainer, null,
            workingSetTypes.toArray(new String[workingSetTypes.size()]));

    setControl(wizardContainer);
}

From source file:com.ecfeed.ui.dialogs.AddTestCaseDialog.java

License:Open Source License

private void createTestDataViewer(Composite container) {
    fTestDataViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION);
    Table table = fTestDataViewer.getTable();
    table.setLinesVisible(true);//from  w  ww .j a  va  2 s .c  om
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    TableViewerColumn parameterViewerColumn = new TableViewerColumn(fTestDataViewer, SWT.NONE);
    TableColumn parameterColumn = parameterViewerColumn.getColumn();
    parameterColumn.setWidth(200);
    parameterColumn.setText("Parameter");
    parameterViewerColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            return ((ChoiceNode) element).getParameter().toString();
        }

        @Override
        public Color getForeground(Object element) {
            return getColor(element);
        }
    });

    TableViewerColumn choiceViewerColumn = new TableViewerColumn(fTestDataViewer, SWT.NONE);
    TableColumn choiceColumn = choiceViewerColumn.getColumn();
    choiceColumn.setWidth(150);
    choiceColumn.setText("Choice");
    choiceViewerColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            ChoiceNode testValue = (ChoiceNode) element;
            MethodParameterNode parameter = fMethod.getMethodParameters().get(fTestData.indexOf(testValue));
            if (parameter.isExpected()) {
                return testValue.getValueString();
            }
            return testValue.toString();
        }

        @Override
        public Color getForeground(Object element) {
            return getColor(element);
        }
    });

    choiceViewerColumn.setEditingSupport(new TestDataValueEditingSupport(fMethod, fTestDataViewer, this));

    fTestDataViewer.setContentProvider(new ArrayContentProvider());
    fTestDataViewer.setInput(fTestData);
}

From source file:com.ecfeed.ui.dialogs.SelectCompatibleMethodDialog.java

License:Open Source License

/**
 * Create contents of the dialog./*ww  w  .j  a va 2  s  . c o m*/
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    setTitle(Messages.DIALOG_RENAME_METHOD_TITLE);
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(1, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    Text infoText = new Text(container, SWT.READ_ONLY | SWT.WRAP);
    infoText.setText(Messages.DIALOG_RENAME_METHOD_MESSAGE);
    infoText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    Composite tableComposite = new Composite(container, SWT.NONE);
    tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    TableColumnLayout tableCompositeLayout = new TableColumnLayout();
    tableComposite.setLayout(tableCompositeLayout);

    fMethodViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION);
    Table methodsTable = fMethodViewer.getTable();
    methodsTable.setHeaderVisible(true);
    methodsTable.setLinesVisible(true);

    TableViewerColumn methodViewerColumn = new TableViewerColumn(fMethodViewer, SWT.NONE);
    TableColumn methodColumn = methodViewerColumn.getColumn();
    tableCompositeLayout.setColumnData(methodColumn, new ColumnPixelData(150, true, true));
    methodColumn.setText("Method");
    fMethodViewer.setContentProvider(new ArrayContentProvider());
    fMethodViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((MethodNode) element).toString();
        }
    });
    fMethodViewer.setInput(fCompatibleMethods);
    fMethodViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) fMethodViewer.getSelection();
            fSelectedMethod = (MethodNode) selection.getFirstElement();
            fOkButton.setEnabled(true);
        }
    });
    fMethodViewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) fMethodViewer.getSelection();
            fSelectedMethod = (MethodNode) selection.getFirstElement();
            okPressed();
        }
    });

    return area;
}