Example usage for org.eclipse.jface.window ToolTip NO_RECREATE

List of usage examples for org.eclipse.jface.window ToolTip NO_RECREATE

Introduction

In this page you can find the example usage for org.eclipse.jface.window ToolTip NO_RECREATE.

Prototype

int NO_RECREATE

To view the source code for org.eclipse.jface.window ToolTip NO_RECREATE.

Click Source Link

Document

Don't recreate the tooltip as long the mouse doesn't leave the area triggering the tooltip creation

Usage

From source file:org.eclipse.mat.ui.internal.query.arguments.ArgumentsTable.java

License:Open Source License

public ArgumentsTable(Composite parent, int style, IQueryContext context, ArgumentSet argumentSet, Mode mode) {
    this.context = context;
    this.argumentSet = argumentSet;
    this.mode = mode;

    TableColumnLayout tableColumnLayout = new TableColumnLayout();
    parent.setLayout(tableColumnLayout);

    table = new Table(parent, style);
    Font parentFont = parent.getFont();
    table.setFont(parentFont);// w  w w.j  av a 2  s .c  o  m
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    AccessibleCompositeAdapter.access(table);

    TableColumn column = new TableColumn(table, SWT.NONE);
    column.setText(ARGUMENT);
    tableColumnLayout.setColumnData(column, new ColumnWeightData(0, 100));

    column = new TableColumn(table, SWT.NONE);
    column.setText(VALUE);
    tableColumnLayout.setColumnData(column, new ColumnWeightData(100, 100));

    boldFont = resourceManager.createFont(FontDescriptor.createFrom(parentFont).setStyle(SWT.BOLD));
    normalFont = resourceManager.createFont(FontDescriptor.createFrom(parentFont).setStyle(SWT.NORMAL));

    modeMap = new HashMap<ArgumentDescriptor, Mode>(argumentSet.getQueryDescriptor().getArguments().size());
    for (ArgumentDescriptor descriptor : argumentSet.getQueryDescriptor().getArguments()) {
        if (isHeapObject(descriptor))
            modeMap.put(descriptor, mode);
    }

    table.addListener(SWT.MeasureItem, new Listener() {
        public void handleEvent(Event event) {
            event.height = tableRowHeight;
        }
    });

    createTableContent();

    new DefaultToolTip(table, ToolTip.NO_RECREATE, false) {
        private ArgumentDescriptor getEntry(Event event) {
            TableItem item = table.getItem(new Point(event.x, event.y));
            if (item != null && item.getData() != null) {
                return ((ArgumentEditor) item.getData()).getDescriptor();
            }
            return null;
        }

        protected String getText(Event event) {
            ArgumentDescriptor entry = getEntry(event);
            if (entry != null) {
                return entry.getHelp();
            }
            return null;
        }

        protected boolean shouldCreateToolTip(Event event) {
            table.setToolTipText(""); //$NON-NLS-1$
            return getEntry(event) != null && super.shouldCreateToolTip(event);
        }

        protected Object getToolTipArea(Event event) {
            return getEntry(event);
        }
    }.activate();

}

From source file:org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaSeeAlsoAttributeEditor.java

License:Open Source License

private void createSeeAlsoTable(FormToolkit toolkit, final Composite seeAlsoComposite) {

    seeAlsoTable = toolkit.createTable(seeAlsoComposite, SWT.MULTI | SWT.FULL_SELECTION);
    seeAlsoTable.setLinesVisible(true);/*from   ww w .java 2 s  .c om*/
    seeAlsoTable.setHeaderVisible(true);
    seeAlsoTable.setLayout(new GridLayout());
    seeAlsoTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);

    for (int i = 0; i < seeAlsoColumns.length; i++) {
        TableColumn column = new TableColumn(seeAlsoTable, SWT.LEFT, i);
        column.setText(seeAlsoColumns[i]);
        column.setWidth(seeAlsoColumnWidths[i]);
        column.setMoveable(true);
    }

    seeAlsoViewer = new TableViewer(seeAlsoTable);
    seeAlsoViewer.setUseHashlookup(true);
    seeAlsoViewer.setColumnProperties(seeAlsoColumns);
    ColumnViewerToolTipSupport.enableFor(seeAlsoViewer, ToolTip.NO_RECREATE);

    seeAlsoViewer.setContentProvider(new ArrayContentProvider());
    seeAlsoViewer.addOpenListener(new IOpenListener() {
        public void open(OpenEvent event) {
            openseeAlso(event);
        }

        private void openseeAlso(OpenEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            for (String item : (List<String>) selection.toList()) {
                BrowserUtil.openUrl(item);
            }

        }
    });
    seeAlsoViewer.setLabelProvider(new ColumnLabelProvider() {

        public Image getColumnImage(Object element, int columnIndex) {
            String value = (String) element;
            if (columnIndex == 0) {
                if (value.contains("/r/#/c/") || value.contains("git.eclipse.org/r/")) { //$NON-NLS-1$ //$NON-NLS-2$
                    return CommonImages.getImage(BugzillaImages.GERRIT);
                } else if (value.contains("/commit/?id=")) { //$NON-NLS-1$
                    return CommonImages.getImage(BugzillaImages.GIT);
                } else {
                    return CommonImages.getImage(BugzillaImages.BUG);
                }
            }
            return null;
        }

        public String getColumnText(Object element, int columnIndex) {
            String value = (String) element;
            switch (columnIndex) {
            case 0:
                return null;
            case 1:
                return attrRemoveSeeAlso.getValues().contains(value)
                        ? Messages.BugzillaSeeAlsoAttributeEditor_Yes
                        : Messages.BugzillaSeeAlsoAttributeEditor_No;
            default:
                return value;
            }
        }

        @Override
        public void update(ViewerCell cell) {
            Object element = cell.getElement();
            cell.setText(getColumnText(element, cell.getColumnIndex()));
            Image image = getColumnImage(element, cell.getColumnIndex());
            cell.setImage(image);
            cell.setBackground(getBackground(element));
            cell.setForeground(getForeground(element));
            cell.setFont(getFont(element));
        }

    });
    seeAlsoViewer.setInput(getTaskAttribute().getValues().toArray());
    GC gc = new GC(seeAlsoComposite);
    int maxSize = 0;
    for (String string : getTaskAttribute().getValues()) {
        Point size = gc.textExtent(string);
        if (size.x > maxSize) {
            maxSize = size.x;
        }
    }
    if (maxSize == 0) {
        maxSize = 100;
    }
    seeAlsoTable.getColumn(2).setWidth(maxSize);
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {
            manager.add(openAction);
            manager.add(copyURLToClipAction);
            manager.add(toggelRemoveStateAction);
        }
    });
    Menu menu = menuManager.createContextMenu(seeAlsoTable);
    seeAlsoTable.setMenu(menu);
}

From source file:org.eclipse.mylyn.internal.github.ui.gist.GistAttachmentPart.java

License:Open Source License

private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) {
    attachmentsTable = toolkit.createTable(attachmentsComposite, SWT.MULTI | SWT.FULL_SELECTION);
    attachmentsTable.setLinesVisible(true);
    attachmentsTable.setHeaderVisible(true);
    attachmentsTable.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).hint(500, SWT.DEFAULT)
            .applyTo(attachmentsTable);/*from  ww w .  ja va  2  s . c o m*/
    attachmentsTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);

    for (int i = 0; i < attachmentsColumns.length; i++) {
        TableColumn column = new TableColumn(attachmentsTable, SWT.LEFT, i);
        column.setText(attachmentsColumns[i]);
        column.setWidth(attachmentsColumnWidths[i]);
        column.setMoveable(true);
        if (i == 0) {
            attachmentsTable.setSortColumn(column);
            attachmentsTable.setSortDirection(SWT.DOWN);
        }
    }
    // size column
    attachmentsTable.getColumn(1).setAlignment(SWT.RIGHT);

    TableViewer attachmentsViewer = new TableViewer(attachmentsTable);
    attachmentsViewer.setUseHashlookup(true);
    attachmentsViewer.setColumnProperties(attachmentsColumns);
    ColumnViewerToolTipSupport.enableFor(attachmentsViewer, ToolTip.NO_RECREATE);

    attachmentsViewer.setSorter(new GistAttachmentSorter());

    List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size());
    for (TaskAttribute attribute : attachments) {
        ITaskAttachment taskAttachment = new TaskAttachment(getModel().getTaskRepository(),
                getModel().getTask(), attribute);
        getTaskData().getAttributeMapper().updateTaskAttachment(taskAttachment, attribute);
        attachmentList.add(taskAttachment);
    }
    attachmentsViewer.setContentProvider(new ArrayContentProvider());
    attachmentsViewer.setLabelProvider(
            new AttachmentTableLabelProvider(getModel(), getTaskEditorPage().getAttributeEditorToolkit()) {

                public String getColumnText(Object element, int columnIndex) {
                    if (columnIndex > 0)
                        columnIndex++;
                    return super.getColumnText(element, columnIndex);
                }

                public Image getColumnImage(Object element, int columnIndex) {
                    if (columnIndex > 0)
                        columnIndex++;
                    return super.getColumnImage(element, columnIndex);
                }

            });
    attachmentsViewer.addOpenListener(new IOpenListener() {
        public void open(OpenEvent event) {
            openAttachments(event);
        }
    });
    attachmentsViewer.addSelectionChangedListener(getTaskEditorPage());
    attachmentsViewer.setInput(attachmentList.toArray());

    menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {
            TasksUiMenus.fillTaskAttachmentMenu(manager);
        }
    });
    getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer,
            true);
    Menu menu = menuManager.createContextMenu(attachmentsTable);
    attachmentsTable.setMenu(menu);

    new TableViewerSupport(attachmentsViewer, getStateFile());
}

From source file:org.eclipse.mylyn.internal.jira.ui.editor.WorkLogPart.java

License:Open Source License

private void createTable(FormToolkit toolkit, final Composite composite) {
    Table table = toolkit.createTable(composite, SWT.MULTI | SWT.FULL_SELECTION);
    table.setLinesVisible(true);/* w w w.  j a v  a  2  s .  c o  m*/
    table.setHeaderVisible(true);
    table.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).hint(500, SWT.DEFAULT)
            .applyTo(table);

    for (int i = 0; i < columns.length; i++) {
        TableColumn column = new TableColumn(table, SWT.LEFT, i);
        column.setText(columns[i]);
        column.setWidth(columnWidths[i]);
    }
    table.getColumn(2).setAlignment(SWT.RIGHT);

    TableViewer attachmentsViewer = new TableViewer(table);
    attachmentsViewer.setUseHashlookup(true);
    attachmentsViewer.setColumnProperties(columns);
    ColumnViewerToolTipSupport.enableFor(attachmentsViewer, ToolTip.NO_RECREATE);

    attachmentsViewer.setSorter(new ViewerSorter() {
        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            JiraWorkLog item1 = (JiraWorkLog) e1;
            JiraWorkLog item2 = (JiraWorkLog) e2;
            Date created1 = item1.getCreated();
            Date created2 = item2.getCreated();
            if (created1 != null && created2 != null) {
                return created1.compareTo(created2);
            } else if (created1 == null && created2 != null) {
                return -1;
            } else if (created1 != null && created2 == null) {
                return 1;
            } else {
                return 0;
            }
        }
    });

    List<JiraWorkLog> workLogList = new ArrayList<JiraWorkLog>(logEntries.size());
    for (TaskAttribute attribute : logEntries) {
        JiraWorkLog log = new WorkLogConverter().createFrom(attribute);
        workLogList.add(log);
    }
    attachmentsViewer.setContentProvider(new ArrayContentProvider());
    attachmentsViewer.setLabelProvider(new WorkLogTableLabelProvider(getJiraTimeFormat()));
    attachmentsViewer.addOpenListener(new IOpenListener() {
        public void open(OpenEvent event) {
            TasksUiUtil.openUrl(
                    JiraConnectorUi.getTaskWorkLogUrl(getModel().getTaskRepository(), getModel().getTask()));
        }
    });
    attachmentsViewer.addSelectionChangedListener(getTaskEditorPage());
    attachmentsViewer.setInput(workLogList);

    menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {
            // TODO provide popup menu
        }
    });
    getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer,
            false);
    Menu menu = menuManager.createContextMenu(table);
    table.setMenu(menu);
}

From source file:org.eclipse.mylyn.internal.tasks.ui.deprecated.AbstractRepositoryTaskEditor.java

License:Open Source License

protected void createAttachmentLayout(Composite composite) {
    // TODO: expand to show new attachments
    Section section = createSection(composite, getSectionLabel(SECTION_NAME.ATTACHMENTS_SECTION), false);
    section.setText(section.getText() + " (" + taskData.getAttachments().size() + ")");
    final Composite attachmentsComposite = toolkit.createComposite(section);
    attachmentsComposite.setLayout(new GridLayout(1, false));
    attachmentsComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    section.setClient(attachmentsComposite);

    if (taskData.getAttachments().size() > 0) {

        attachmentsTable = toolkit.createTable(attachmentsComposite,
                SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
        attachmentsTable.setLinesVisible(true);
        attachmentsTable.setHeaderVisible(true);
        attachmentsTable.setLayout(new GridLayout());
        GridData tableGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
        attachmentsTable.setLayoutData(tableGridData);

        for (int i = 0; i < attachmentsColumns.length; i++) {
            TableColumn column = new TableColumn(attachmentsTable, SWT.LEFT, i);
            column.setText(attachmentsColumns[i]);
            column.setWidth(attachmentsColumnWidths[i]);
        }//from   ww w  .  j  a  v  a2  s . c  om
        attachmentsTable.getColumn(3).setAlignment(SWT.RIGHT);

        attachmentsTableViewer = new TableViewer(attachmentsTable);
        attachmentsTableViewer.setUseHashlookup(true);
        attachmentsTableViewer.setColumnProperties(attachmentsColumns);
        ColumnViewerToolTipSupport.enableFor(attachmentsTableViewer, ToolTip.NO_RECREATE);

        final AbstractTaskDataHandler offlineHandler = connector.getLegacyTaskDataHandler();
        if (offlineHandler != null) {
            attachmentsTableViewer.setSorter(new ViewerSorter() {
                @Override
                public int compare(Viewer viewer, Object e1, Object e2) {
                    RepositoryAttachment attachment1 = (RepositoryAttachment) e1;
                    RepositoryAttachment attachment2 = (RepositoryAttachment) e2;
                    Date created1 = taskData.getAttributeFactory().getDateForAttributeType(
                            RepositoryTaskAttribute.ATTACHMENT_DATE, attachment1.getDateCreated());
                    Date created2 = taskData.getAttributeFactory().getDateForAttributeType(
                            RepositoryTaskAttribute.ATTACHMENT_DATE, attachment2.getDateCreated());
                    if (created1 != null && created2 != null) {
                        return created1.compareTo(created2);
                    } else if (created1 == null && created2 != null) {
                        return -1;
                    } else if (created1 != null && created2 == null) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });
        }

        attachmentsTableViewer
                .setContentProvider(new AttachmentsTableContentProvider(taskData.getAttachments()));

        attachmentsTableViewer.setLabelProvider(new AttachmentTableLabelProvider(this, new LabelProvider(),
                PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));

        attachmentsTableViewer.addDoubleClickListener(new IDoubleClickListener() {
            public void doubleClick(DoubleClickEvent event) {
                if (!event.getSelection().isEmpty()) {
                    StructuredSelection selection = (StructuredSelection) event.getSelection();
                    RepositoryAttachment attachment = (RepositoryAttachment) selection.getFirstElement();
                    TasksUiUtil.openUrl(attachment.getUrl());
                }
            }
        });

        attachmentsTableViewer.setInput(taskData);

        final Action openWithBrowserAction = new Action(LABEL_BROWSER) {
            @Override
            public void run() {
                RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer
                        .getSelection()).getFirstElement());
                if (attachment != null) {
                    TasksUiUtil.openUrl(attachment.getUrl());
                }
            }
        };

        final Action openWithDefaultAction = new Action(LABEL_DEFAULT_EDITOR) {
            @Override
            public void run() {
                // browser shortcut
                RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer
                        .getSelection()).getFirstElement());
                if (attachment == null) {
                    return;
                }

                if (attachment.getContentType().endsWith(CTYPE_HTML)) {
                    TasksUiUtil.openUrl(attachment.getUrl());
                    return;
                }

                IStorageEditorInput input = new RepositoryAttachmentEditorInput(repository, attachment);
                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                if (page == null) {
                    return;
                }
                IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry()
                        .getDefaultEditor(input.getName());
                try {
                    page.openEditor(input, desc.getId());
                } catch (PartInitException e) {
                    StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
                            "Unable to open editor for: " + attachment.getDescription(), e));
                }
            }
        };

        final Action openWithTextEditorAction = new Action(LABEL_TEXT_EDITOR) {
            @Override
            public void run() {
                RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer
                        .getSelection()).getFirstElement());
                IStorageEditorInput input = new RepositoryAttachmentEditorInput(repository, attachment);
                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                if (page == null) {
                    return;
                }

                try {
                    page.openEditor(input, "org.eclipse.ui.DefaultTextEditor");
                } catch (PartInitException e) {
                    StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
                            "Unable to open editor for: " + attachment.getDescription(), e));
                }
            }
        };

        final Action saveAction = new Action(LABEL_SAVE) {
            @Override
            public void run() {
                ITaskAttachment attachment = (ITaskAttachment) (((StructuredSelection) attachmentsTableViewer
                        .getSelection()).getFirstElement());
                /* Launch Browser */
                FileDialog fileChooser = new FileDialog(attachmentsTable.getShell(), SWT.SAVE);
                String fname = attachment.getFileName();
                // Default name if none is found
                if (fname.equals("")) {
                    String ctype = attachment.getContentType();
                    if (ctype.endsWith(CTYPE_HTML)) {
                        fname = ATTACHMENT_DEFAULT_NAME + ".html";
                    } else if (ctype.startsWith(CTYPE_TEXT)) {
                        fname = ATTACHMENT_DEFAULT_NAME + ".txt";
                    } else if (ctype.endsWith(CTYPE_OCTET_STREAM)) {
                        fname = ATTACHMENT_DEFAULT_NAME;
                    } else if (ctype.endsWith(CTYPE_ZIP)) {
                        fname = ATTACHMENT_DEFAULT_NAME + "." + CTYPE_ZIP;
                    } else {
                        fname = ATTACHMENT_DEFAULT_NAME + "." + ctype.substring(ctype.indexOf("/") + 1);
                    }
                }
                fileChooser.setFileName(fname);
                String filePath = fileChooser.open();
                // Check if the dialog was canceled or an error occurred
                if (filePath == null) {
                    return;
                }

                DownloadAttachmentJob job = new DownloadAttachmentJob(attachment, new File(filePath));
                job.setUser(true);
                job.schedule();
            }
        };

        final Action copyURLToClipAction = new Action(LABEL_COPY_URL_TO_CLIPBOARD) {
            @Override
            public void run() {
                RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer
                        .getSelection()).getFirstElement());
                Clipboard clip = new Clipboard(PlatformUI.getWorkbench().getDisplay());
                clip.setContents(new Object[] { attachment.getUrl() },
                        new Transfer[] { TextTransfer.getInstance() });
                clip.dispose();
            }
        };

        final Action copyToClipAction = new Action(LABEL_COPY_TO_CLIPBOARD) {
            @Override
            public void run() {
                RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer
                        .getSelection()).getFirstElement());
                CopyAttachmentToClipboardJob job = new CopyAttachmentToClipboardJob(attachment);
                job.setUser(true);
                job.schedule();
            }
        };

        final MenuManager popupMenu = new MenuManager();
        final Menu menu = popupMenu.createContextMenu(attachmentsTable);
        attachmentsTable.setMenu(menu);
        final MenuManager openMenu = new MenuManager("Open With");
        popupMenu.addMenuListener(new IMenuListener() {
            public void menuAboutToShow(IMenuManager manager) {
                popupMenu.removeAll();

                IStructuredSelection selection = (IStructuredSelection) attachmentsTableViewer.getSelection();
                if (selection.isEmpty()) {
                    return;
                }

                if (selection.size() == 1) {
                    RepositoryAttachment att = (RepositoryAttachment) ((StructuredSelection) selection)
                            .getFirstElement();

                    // reinitialize open menu
                    popupMenu.add(openMenu);
                    openMenu.removeAll();

                    IStorageEditorInput input = new RepositoryAttachmentEditorInput(repository, att);
                    IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry()
                            .getDefaultEditor(input.getName());
                    if (desc != null) {
                        openMenu.add(openWithDefaultAction);
                    }
                    openMenu.add(openWithBrowserAction);
                    openMenu.add(openWithTextEditorAction);

                    popupMenu.add(new Separator());
                    popupMenu.add(saveAction);

                    popupMenu.add(copyURLToClipAction);
                    if (att.getContentType().startsWith(CTYPE_TEXT) || att.getContentType().endsWith("xml")) {
                        popupMenu.add(copyToClipAction);
                    }
                }
                popupMenu.add(new Separator("actions"));

                // TODO: use workbench mechanism for this?
                ObjectActionContributorManager.getManager().contributeObjectActions(
                        AbstractRepositoryTaskEditor.this, popupMenu, attachmentsTableViewer);
            }
        });
    } else {
        Label label = toolkit.createLabel(attachmentsComposite, "No attachments");
        registerDropListener(label);
    }

    final Composite attachmentControlsComposite = toolkit.createComposite(attachmentsComposite);
    attachmentControlsComposite.setLayout(new GridLayout(2, false));
    attachmentControlsComposite.setLayoutData(new GridData(GridData.BEGINNING));

    Button attachFileButton = toolkit.createButton(attachmentControlsComposite, AttachAction.LABEL, SWT.PUSH);
    attachFileButton.setImage(WorkbenchImages.getImage(ISharedImages.IMG_OBJ_FILE));

    Button attachScreenshotButton = toolkit.createButton(attachmentControlsComposite,
            AttachScreenshotAction.LABEL, SWT.PUSH);
    attachScreenshotButton.setImage(CommonImages.getImage(CommonImages.IMAGE_CAPTURE));

    final ITask task = TasksUiInternal.getTaskList().getTask(repository.getRepositoryUrl(),
            taskData.getTaskId());
    if (task == null) {
        attachFileButton.setEnabled(false);
        attachScreenshotButton.setEnabled(false);
    }

    attachFileButton.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
            // ignore
        }

        public void widgetSelected(SelectionEvent e) {
            AbstractTaskEditorAction attachFileAction = new AttachAction();
            attachFileAction.selectionChanged(new StructuredSelection(task));
            attachFileAction.setEditor(parentEditor);
            attachFileAction.run();
        }
    });

    attachScreenshotButton.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
            // ignore
        }

        public void widgetSelected(SelectionEvent e) {
            AttachScreenshotAction attachScreenshotAction = new AttachScreenshotAction();
            attachScreenshotAction.selectionChanged(new StructuredSelection(task));
            attachScreenshotAction.setEditor(parentEditor);
            attachScreenshotAction.run();
        }
    });

    Button deleteAttachmentButton = null;
    if (supportsAttachmentDelete()) {
        deleteAttachmentButton = toolkit.createButton(attachmentControlsComposite, "Delete Attachment...",
                SWT.PUSH);

        deleteAttachmentButton.addSelectionListener(new SelectionListener() {
            public void widgetDefaultSelected(SelectionEvent e) {
                // ignore
            }

            public void widgetSelected(SelectionEvent e) {
                ITask task = TasksUiInternal.getTaskList().getTask(repository.getRepositoryUrl(),
                        taskData.getTaskId());
                if (task == null) {
                    // Should not happen
                    return;
                }
                if (AbstractRepositoryTaskEditor.this.isDirty
                        || task.getSynchronizationState().equals(SynchronizationState.OUTGOING)) {
                    MessageDialog.openInformation(attachmentsComposite.getShell(),
                            "Task not synchronized or dirty editor",
                            "Commit edits or synchronize task before deleting attachments.");
                    return;
                } else {
                    if (attachmentsTableViewer != null && attachmentsTableViewer.getSelection() != null
                            && ((StructuredSelection) attachmentsTableViewer.getSelection())
                                    .getFirstElement() != null) {
                        RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer
                                .getSelection()).getFirstElement());
                        deleteAttachment(attachment);
                        submitToRepository();
                    }
                }
            }
        });

    }
    registerDropListener(section);
    registerDropListener(attachmentsComposite);
    registerDropListener(attachFileButton);
    if (supportsAttachmentDelete()) {
        registerDropListener(deleteAttachmentButton);
    }
}

From source file:org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorAttachmentPart.java

License:Open Source License

private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) {
    attachmentsTable = toolkit.createTable(attachmentsComposite, SWT.MULTI | SWT.FULL_SELECTION);
    attachmentsTable.setLinesVisible(true);
    attachmentsTable.setHeaderVisible(true);
    attachmentsTable.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).hint(500, SWT.DEFAULT)
            .applyTo(attachmentsTable);//  w w w .  ja  v a  2  s .c o m
    attachmentsTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);

    for (int i = 0; i < attachmentsColumns.length; i++) {
        TableColumn column = new TableColumn(attachmentsTable, SWT.LEFT, i);
        column.setText(attachmentsColumns[i]);
        column.setWidth(attachmentsColumnWidths[i]);
        column.setMoveable(true);
        if (i == 4) {
            attachmentsTable.setSortColumn(column);
            attachmentsTable.setSortDirection(SWT.DOWN);
        }
    }
    // size column
    attachmentsTable.getColumn(2).setAlignment(SWT.RIGHT);

    attachmentsViewer = new TableViewer(attachmentsTable);
    attachmentsViewer.setUseHashlookup(true);
    attachmentsViewer.setColumnProperties(attachmentsColumns);
    ColumnViewerToolTipSupport.enableFor(attachmentsViewer, ToolTip.NO_RECREATE);

    attachmentsViewer.setSorter(new AttachmentTableSorter());

    attachmentsViewer.setContentProvider(new ArrayContentProvider());
    attachmentsViewer.setLabelProvider(
            new AttachmentTableLabelProvider(getModel(), getTaskEditorPage().getAttributeEditorToolkit()));
    attachmentsViewer.addOpenListener(new IOpenListener() {
        public void open(OpenEvent event) {
            openAttachments(event);
        }
    });
    attachmentsViewer.addSelectionChangedListener(getTaskEditorPage());
    attachmentsViewer.setInput(attachmentList.toArray());

    menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {
            TasksUiMenus.fillTaskAttachmentMenu(manager);
        }
    });
    getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer,
            true);
    Menu menu = menuManager.createContextMenu(attachmentsTable);
    attachmentsTable.setMenu(menu);

    attachmentsViewer.addFilter(tableFilter);

    new TableViewerSupport(attachmentsViewer, getStateFile());
}

From source file:org.eclipse.mylyn.reviews.r4e.ui.internal.dialogs.CloneAnomalyInputDialog.java

License:Open Source License

/**
 * Configures the dialog form and creates form content. Clients should override this method.
 * //from  w  w  w  .j  a va2s . c o  m
 * @param mform
 *            the dialog form
 */
@Override
protected void createFormContent(final IManagedForm mform) {

    final FormToolkit toolkit = mform.getToolkit();
    final ScrolledForm sform = mform.getForm();
    sform.setExpandVertical(true);
    final Composite composite = sform.getBody();
    final GridLayout layout = new GridLayout(4, false);
    composite.setLayout(layout);
    GridData textGridData = null;

    //Basic parameters section
    final Section basicSection = toolkit.createSection(composite, Section.DESCRIPTION
            | ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
    final GridData basicSectionGridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    basicSectionGridData.horizontalSpan = 4;
    basicSection.setLayoutData(basicSectionGridData);
    basicSection.setText(ANOMALY_LIST_HEADER_MSG);
    basicSection.addExpansionListener(new ExpansionAdapter() {
        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            getShell().setSize(getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT));
        }
    });

    final Composite basicSectionClient = toolkit.createComposite(basicSection);
    basicSectionClient.setLayout(layout);
    basicSection.setClient(basicSectionClient);

    //Cloneable Anomaly Table
    Set<R4EUIAnomalyBasic> anomalies = getCloneableAnomalies();

    int tableHeight = MAX_DISPLAYED_CLONEABLE_ANOMALIES;
    if (anomalies.size() < MAX_DISPLAYED_CLONEABLE_ANOMALIES) {
        tableHeight = anomalies.size();
    }
    textGridData = new GridData(GridData.FILL, GridData.FILL, true, true);

    fCloneableAnomalyViewer = new TableViewer(basicSectionClient,
            SWT.FULL_SELECTION | SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL);
    textGridData.heightHint = fCloneableAnomalyViewer.getTable().getItemHeight() * tableHeight;
    fCloneableAnomalyViewer.getControl().setLayoutData(textGridData);
    fCloneableAnomalyViewer.setContentProvider(ArrayContentProvider.getInstance());
    ColumnViewerToolTipSupport.enableFor(fCloneableAnomalyViewer, ToolTip.NO_RECREATE);
    fCloneableAnomalyViewer.setLabelProvider(new ReviewNavigatorLabelProvider() {
        @Override
        public String getText(Object element) {
            return ((R4EUIAnomalyBasic) element).getAnomaly().getTitle();
        }

        @Override
        public void update(ViewerCell cell) {
            cell.setText(((R4EUIAnomalyBasic) cell.getElement()).getAnomaly().getTitle());
            cell.setImage(((R4EUIAnomalyBasic) cell.getElement())
                    .getImage(((R4EUIAnomalyBasic) cell.getElement()).getImageLocation()));
        }
    });

    fCloneableAnomalyViewer.setInput(anomalies);

    fCloneableAnomalyViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            //Check and set files based on selected cloneable anomaly
            getButton(IDialogConstants.OK_ID).setEnabled(false);
            if (event.getSelection() instanceof IStructuredSelection) {
                if (null != ((IStructuredSelection) event.getSelection()).getFirstElement()) {
                    Object selectedObject = ((IStructuredSelection) event.getSelection()).getFirstElement();
                    if (selectedObject instanceof R4EUIAnomalyBasic) {
                        final R4EUIAnomalyBasic uiAnomaly = (R4EUIAnomalyBasic) selectedObject;
                        R4EAnomaly anomaly = uiAnomaly.getAnomaly();
                        if (null != anomaly) {
                            if (null != anomaly.getTitle()) {
                                fAnomalyTitleTextField.setText(anomaly.getTitle());
                            }
                            if (null != anomaly.getDescription()) {
                                fAnomalyDescriptionTextField.setText(anomaly.getDescription());
                            }
                            if (null != anomaly.getType()) {
                                fAnomalyClassTextField.setText(
                                        UIUtils.getClassStr(((R4ECommentType) anomaly.getType()).getType()));
                            }
                            if (null != anomaly.getRank()) {
                                fAnomalyRankTextField.setText(UIUtils.getRankStr(anomaly.getRank()));
                            }

                            if (null != anomaly.getRuleID()) {
                                //Only display the last segment of the rule id
                                String[] ar = anomaly.getRuleID().split(R4EUIConstants.SEPARATOR);
                                String rule = ar[ar.length - 1];

                                fRuleIdTextField.setText(rule);
                                //Set the path in the tooltip
                                fRuleIdTextField.setToolTipText(anomaly.getRuleID());
                            }
                        }
                        getButton(IDialogConstants.OK_ID).setEnabled(true);
                    }
                }
            }
        }
    });

    //Extra parameters section
    final Section extraSection = toolkit.createSection(composite, Section.DESCRIPTION
            | ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
    final GridData extraSectionGridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    extraSectionGridData.horizontalSpan = 4;
    extraSection.setLayoutData(extraSectionGridData);
    extraSection.setText(ANOMALY_DETAILS_HEADER_MSG);
    extraSection.addExpansionListener(new ExpansionAdapter() {
        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            getShell().setSize(getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT));
        }
    });

    final Composite extraSectionClient = toolkit.createComposite(extraSection);
    extraSectionClient.setLayout(layout);
    extraSection.setClient(extraSectionClient);
    toolkit.setBorderStyle(SWT.NULL);

    //Anomaly Title
    Label label = toolkit.createLabel(extraSectionClient, R4EUIConstants.ANOMALY_TITLE_LABEL_VALUE);
    label.setToolTipText(R4EUIConstants.ANOMALY_TITLE_TOOLTIP);
    label.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
    fAnomalyTitleTextField = toolkit.createText(extraSectionClient, "", SWT.SINGLE);
    textGridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    textGridData.horizontalSpan = 3;
    fAnomalyTitleTextField.setToolTipText(R4EUIConstants.ANOMALY_TITLE_TOOLTIP);
    fAnomalyTitleTextField.setLayoutData(textGridData);
    fAnomalyTitleTextField.setEditable(false);

    //Anomaly Description
    label = toolkit.createLabel(extraSectionClient, R4EUIConstants.ANOMALY_DESCRIPTION_LABEL_VALUE);
    label.setToolTipText(R4EUIConstants.ANOMALY_DESCRIPTION_TOOLTIP);
    label.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
    fAnomalyDescriptionTextField = toolkit.createText(extraSectionClient, "",
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    textGridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    textGridData.horizontalSpan = 3;
    textGridData.heightHint = fAnomalyTitleTextField.getLineHeight() * 7;
    fAnomalyDescriptionTextField.setToolTipText(R4EUIConstants.ANOMALY_DESCRIPTION_TOOLTIP);
    fAnomalyDescriptionTextField.setLayoutData(textGridData);
    fAnomalyDescriptionTextField.setEditable(false);

    //Anomaly Class
    label = toolkit.createLabel(extraSectionClient, R4EUIConstants.CLASS_LABEL);
    label.setToolTipText(R4EUIConstants.ANOMALY_CLASS_TOOLTIP);
    label.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));

    fAnomalyClassTextField = toolkit.createText(extraSectionClient, "", SWT.SINGLE);
    textGridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    textGridData.horizontalSpan = 3;
    fAnomalyClassTextField.setToolTipText(R4EUIConstants.ANOMALY_CLASS_TOOLTIP);
    fAnomalyClassTextField.setLayoutData(textGridData);
    fAnomalyClassTextField.setEditable(false);

    //Anomaly Rank    
    label = toolkit.createLabel(extraSectionClient, R4EUIConstants.RANK_LABEL);
    label.setToolTipText(R4EUIConstants.ANOMALY_RANK_TOOLTIP);
    label.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));

    fAnomalyRankTextField = toolkit.createText(extraSectionClient, "", SWT.SINGLE);
    textGridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    textGridData.horizontalSpan = 3;
    fAnomalyRankTextField.setToolTipText(R4EUIConstants.ANOMALY_CLASS_TOOLTIP);
    fAnomalyRankTextField.setLayoutData(textGridData);
    fAnomalyRankTextField.setEditable(false);

    //Rule ID
    label = toolkit.createLabel(extraSectionClient, R4EUIConstants.RULE_ID_LABEL);
    label.setToolTipText(R4EUIConstants.RULE_ID_TOOLTIP);
    label.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));

    fRuleIdTextField = toolkit.createText(extraSectionClient, "", SWT.SINGLE);
    textGridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    textGridData.horizontalSpan = 3;
    fRuleIdTextField.setToolTipText(R4EUIConstants.ANOMALY_CLASS_TOOLTIP);
    fRuleIdTextField.setLayoutData(textGridData);
    fRuleIdTextField.setEditable(false);

    toolkit.setBorderStyle(SWT.BORDER);

    //Assigned To
    label = toolkit.createLabel(extraSectionClient, R4EUIConstants.ASSIGNED_TO_LABEL);
    textGridData = new GridData(GridData.FILL, GridData.FILL, false, false);
    textGridData.horizontalSpan = 1;
    label.setLayoutData(textGridData);

    fAssignedToCombo = new CCombo(extraSectionClient, SWT.BORDER | SWT.READ_ONLY);
    final String[] participants = R4EUIModelController.getActiveReview().getParticipantIDs()
            .toArray(new String[R4EUIModelController.getActiveReview().getParticipantIDs().size()]);
    fAssignedToCombo.removeAll();
    fAssignedToCombo.add("");
    for (String participant : participants) {
        fAssignedToCombo.add(participant);
    }
    textGridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    textGridData.horizontalSpan = 3;
    fAssignedToCombo.setToolTipText(R4EUIConstants.ASSIGNED_TO_TOOLTIP);
    fAssignedToCombo.setLayoutData(textGridData);

    //Due Date
    label = toolkit.createLabel(extraSectionClient, R4EUIConstants.DUE_DATE_LABEL);
    textGridData = new GridData(GridData.FILL, GridData.FILL, false, false);
    textGridData.horizontalSpan = 1;
    label.setLayoutData(textGridData);

    final Composite dateComposite = toolkit.createComposite(extraSectionClient);
    textGridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    textGridData.horizontalSpan = 3;
    dateComposite.setToolTipText(R4EUIConstants.ANOMALY_DUE_DATE_TOOLTIP);
    dateComposite.setLayoutData(textGridData);
    dateComposite.setLayout(new GridLayout(2, false));

    fDateText = toolkit.createText(dateComposite, "", SWT.BORDER | SWT.READ_ONLY);
    fDateText.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    fDateText.setEditable(false);

    final Button calendarButton = toolkit.createButton(dateComposite, "...", SWT.NONE);
    calendarButton.setLayoutData(new GridData(GridData.FILL, GridData.FILL, false, false));
    calendarButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            final ICalendarDialog dialog = R4EUIDialogFactory.getInstance().getCalendarDialog();
            final int result = dialog.open();
            if (result == Window.OK) {
                final SimpleDateFormat dateFormat = new SimpleDateFormat(R4EUIConstants.SIMPLE_DATE_FORMAT);
                Date dialogDate = dialog.getDate();
                String dialogDateStr = dateFormat.format(dialogDate);
                Calendar cal = Calendar.getInstance();
                cal.setTime(new Date());
                cal.add(Calendar.DAY_OF_YEAR, -1);
                if (dialogDate.after(cal.getTime())) {
                    fDateText.setText(dialogDateStr);
                    fAnomalyDueDateValue = dialogDate;
                } else {
                    UIUtils.displayPastDateError(dialogDate, dialogDateStr);
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) { // $codepro.audit.disable emptyMethod
            // No implementation needed
        }
    });

}

From source file:org.eclipse.mylyn.reviews.r4e.ui.internal.dialogs.NewAnomalyInputDialog.java

License:Open Source License

/**
 * Configures the dialog form and creates form content. Clients should override this method.
 * //from   w w w. jav  a 2s .c  o  m
 * @param mform
 *            the dialog form
 */
@Override
protected void createFormContent(final IManagedForm mform) {

    final FormToolkit toolkit = mform.getToolkit();
    final ScrolledForm sform = mform.getForm();
    sform.setExpandVertical(true);
    final Composite composite = sform.getBody();
    final GridLayout layout = new GridLayout(4, false);
    composite.setLayout(layout);
    GridData textGridData = null;

    //Basic parameters section
    final Section basicSection = toolkit.createSection(composite, Section.DESCRIPTION
            | ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
    final GridData basicSectionGridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    basicSectionGridData.horizontalSpan = 4;
    basicSection.setLayoutData(basicSectionGridData);
    basicSection.setText(R4EUIConstants.BASIC_PARAMS_HEADER);
    basicSection.setDescription(BASIC_PARAMS_HEADER_MSG);
    basicSection.addExpansionListener(new ExpansionAdapter() {
        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            getShell().setSize(getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT));
        }
    });

    final Composite basicSectionClient = toolkit.createComposite(basicSection);
    basicSectionClient.setLayout(layout);
    basicSection.setClient(basicSectionClient);

    //Anomaly Title
    Label label = toolkit.createLabel(basicSectionClient, R4EUIConstants.ANOMALY_TITLE_LABEL_VALUE);
    label.setToolTipText(R4EUIConstants.ANOMALY_TITLE_TOOLTIP);
    label.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
    fAnomalyTitleInputTextField = toolkit.createText(basicSectionClient, "", SWT.SINGLE | SWT.BORDER);
    textGridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    textGridData.horizontalSpan = 3;
    fAnomalyTitleInputTextField.setToolTipText(R4EUIConstants.ANOMALY_TITLE_TOOLTIP);
    fAnomalyTitleInputTextField.setLayoutData(textGridData);
    fAnomalyTitleInputTextField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            // ignore
            if (fAnomalyTitleInputTextField.getText().length() > 0
                    && fAnomalyDescriptionInputTextField.getText().length() > 0) {
                getButton(IDialogConstants.OK_ID).setEnabled(true);
            } else {
                getButton(IDialogConstants.OK_ID).setEnabled(false);
            }
        }
    });

    //Anomaly Description
    label = toolkit.createLabel(basicSectionClient, R4EUIConstants.ANOMALY_DESCRIPTION_LABEL_VALUE);
    label.setToolTipText(R4EUIConstants.ANOMALY_DESCRIPTION_TOOLTIP);
    label.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
    fAnomalyDescriptionInputTextField = toolkit.createText(basicSectionClient, "",
            SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
    textGridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    textGridData.horizontalSpan = 3;
    textGridData.heightHint = fAnomalyTitleInputTextField.getLineHeight() * 7;
    fAnomalyDescriptionInputTextField.setToolTipText(R4EUIConstants.ANOMALY_DESCRIPTION_TOOLTIP);
    fAnomalyDescriptionInputTextField.setLayoutData(textGridData);
    fAnomalyDescriptionInputTextField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            // ignore
            if (fAnomalyTitleInputTextField.getText().length() > 0
                    && fAnomalyDescriptionInputTextField.getText().length() > 0) {
                getButton(IDialogConstants.OK_ID).setEnabled(true);
            } else {
                getButton(IDialogConstants.OK_ID).setEnabled(false);
            }
        }
    });

    //Extra parameters section
    final Section extraSection = toolkit.createSection(composite,
            Section.DESCRIPTION | ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE);
    final GridData extraSectionGridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    extraSectionGridData.horizontalSpan = 4;
    extraSection.setLayoutData(extraSectionGridData);
    extraSection.setText(R4EUIConstants.EXTRA_PARAMS_HEADER);
    extraSection.setDescription(EXTRA_PARAMS_HEADER_MSG);
    extraSection.addExpansionListener(new ExpansionAdapter() {
        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            getShell().setSize(getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT));
        }
    });

    final Composite extraSectionClient = toolkit.createComposite(extraSection);
    extraSectionClient.setLayout(layout);
    extraSection.setClient(extraSectionClient);

    //Anomaly Class
    label = toolkit.createLabel(extraSectionClient, R4EUIConstants.CLASS_LABEL);
    label.setToolTipText(R4EUIConstants.ANOMALY_CLASS_TOOLTIP);
    label.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));

    fAnomalyClass = new CCombo(extraSectionClient, SWT.BORDER | SWT.READ_ONLY);
    fAnomalyClass.setItems(UIUtils.getClasses());
    int count = UIUtils.getClasses().length;
    fAnomalyClass.setVisibleItemCount(count);
    textGridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    textGridData.horizontalSpan = 3;
    fAnomalyClass.setToolTipText(R4EUIConstants.ANOMALY_CLASS_TOOLTIP);
    fAnomalyClass.setLayoutData(textGridData);

    //Anomaly Rank    
    label = toolkit.createLabel(extraSectionClient, R4EUIConstants.RANK_LABEL);
    label.setToolTipText(R4EUIConstants.ANOMALY_RANK_TOOLTIP);
    label.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));

    fAnomalyRank = new CCombo(extraSectionClient, SWT.BORDER | SWT.READ_ONLY);
    fAnomalyRank.setItems(UIUtils.getRanks());
    textGridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    textGridData.horizontalSpan = 3;
    fAnomalyRank.setToolTipText(R4EUIConstants.ANOMALY_CLASS_TOOLTIP);
    fAnomalyRank.setLayoutData(textGridData);

    //Assigned To
    label = toolkit.createLabel(extraSectionClient, R4EUIConstants.ASSIGNED_TO_LABEL);
    textGridData = new GridData(GridData.FILL, GridData.FILL, false, false);
    textGridData.horizontalSpan = 1;
    label.setLayoutData(textGridData);

    fAssignedToCombo = new CCombo(extraSectionClient, SWT.BORDER | SWT.READ_ONLY);
    final String[] participants = R4EUIModelController.getActiveReview().getParticipantIDs()
            .toArray(new String[R4EUIModelController.getActiveReview().getParticipantIDs().size()]);
    fAssignedToCombo.removeAll();
    fAssignedToCombo.add("");
    for (String participant : participants) {
        fAssignedToCombo.add(participant);
    }
    textGridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    textGridData.horizontalSpan = 3;
    fAssignedToCombo.setToolTipText(R4EUIConstants.ASSIGNED_TO_TOOLTIP);
    fAssignedToCombo.setLayoutData(textGridData);

    //Due Date
    toolkit.setBorderStyle(SWT.NULL);
    label = toolkit.createLabel(extraSectionClient, R4EUIConstants.DUE_DATE_LABEL);
    textGridData = new GridData(SWT.FILL, SWT.CENTER, false, false);
    textGridData.horizontalSpan = 1;
    label.setLayoutData(textGridData);

    final Composite dateComposite = toolkit.createComposite(extraSectionClient);
    textGridData = new GridData(SWT.FILL, SWT.CENTER, true, true);
    textGridData.horizontalSpan = 3;
    dateComposite.setToolTipText(R4EUIConstants.ANOMALY_DUE_DATE_TOOLTIP);
    dateComposite.setLayoutData(textGridData);
    dateComposite.setLayout(new GridLayout(2, false));

    fDateText = toolkit.createText(dateComposite, "", SWT.READ_ONLY);
    fDateText.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    fDateText.setEditable(false);
    toolkit.setBorderStyle(SWT.BORDER);

    final Composite dateButtonComposite = toolkit.createComposite(dateComposite);
    textGridData = new GridData(SWT.FILL, SWT.CENTER, true, true);
    textGridData.horizontalSpan = 1;
    dateButtonComposite.setToolTipText(R4EUIConstants.ANOMALY_DUE_DATE_TOOLTIP);
    dateButtonComposite.setLayoutData(textGridData);
    dateButtonComposite.setLayout(new GridLayout(2, false));

    final Button calendarButton = toolkit.createButton(dateButtonComposite, R4EUIConstants.UPDATE_LABEL,
            SWT.NONE);
    calendarButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    calendarButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            final ICalendarDialog dialog = R4EUIDialogFactory.getInstance().getCalendarDialog();
            final int result = dialog.open();
            if (result == Window.OK) {
                final SimpleDateFormat dateFormat = new SimpleDateFormat(R4EUIConstants.SIMPLE_DATE_FORMAT);
                Date dialogDate = dialog.getDate();
                String dialogDateStr = dateFormat.format(dialogDate);
                Calendar cal = Calendar.getInstance();
                cal.setTime(new Date());
                cal.add(Calendar.DAY_OF_YEAR, -1);
                if (dialogDate.after(cal.getTime())) {
                    fDateText.setText(dialogDateStr);
                    fAnomalyDueDateValue = dialogDate;
                } else {
                    UIUtils.displayPastDateError(dialogDate, dialogDateStr);
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) { // $codepro.audit.disable emptyMethod
            // No implementation needed
        }
    });

    final Button clearButton = toolkit.createButton(dateButtonComposite, R4EUIConstants.CLEAR_LABEL, SWT.NONE);
    clearButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    clearButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            fDateText.setText("");
            fAnomalyDueDateValue = null;
        }

        public void widgetDefaultSelected(SelectionEvent e) { // $codepro.audit.disable emptyMethod
            // No implementation needed
        }
    });

    //Rule Tree
    label = toolkit.createLabel(extraSectionClient, ADD_RULE_DIALOG_VALUE);
    textGridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    textGridData.horizontalSpan = 4;
    label.setLayoutData(textGridData);

    fRuleTreeViewer = new TreeViewer(extraSectionClient,
            SWT.FULL_SELECTION | SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL);
    fRuleTreeViewer.setContentProvider(new ReviewNavigatorContentProvider());
    fRuleTreeViewer.getTree().setHeaderVisible(true);
    ColumnViewerToolTipSupport.enableFor(fRuleTreeViewer, ToolTip.NO_RECREATE);
    final TreeViewerColumn elementColumn = new TreeViewerColumn(fRuleTreeViewer, SWT.NONE);
    elementColumn.getColumn().setText("Rule Tree");
    elementColumn.getColumn().setWidth(DEFAULT_ELEMENT_COLUMN_WIDTH);
    elementColumn.setLabelProvider(new ReviewNavigatorLabelProvider() {
        @Override
        public String getToolTipText(Object element) {
            if (element instanceof R4EUIRule) {
                return ((R4EUIRule) element).getRule().getDescription();
            }
            return null;
        }

        @Override
        public void update(ViewerCell cell) {
            final IR4EUIModelElement element = (IR4EUIModelElement) cell.getElement();
            if (element instanceof R4EUIRuleSet && !element.isOpen()) {
                cell.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
            } else {
                cell.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK));
            }
            cell.setText(element.getName());
            cell.setImage(element.getImage(element.getImageLocation()));
        }
    });

    final TreeViewerColumn titleColumn = new TreeViewerColumn(fRuleTreeViewer, SWT.NONE);
    titleColumn.getColumn().setText(R4EUIConstants.TITLE_LABEL);
    titleColumn.getColumn().setWidth(DEFAULT_TREE_COLUMN_WIDTH);
    titleColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof R4EUIRule) {
                return ((R4EUIRule) element).getRule().getTitle();
            }
            return null;
        }

        @Override
        public String getToolTipText(Object element) {
            if (element instanceof R4EUIRule) {
                return ((R4EUIRule) element).getRule().getDescription();
            }
            return null;
        }

        @Override
        public Point getToolTipShift(Object object) {
            return new Point(R4EUIConstants.TOOLTIP_DISPLAY_OFFSET_X, R4EUIConstants.TOOLTIP_DISPLAY_OFFSET_Y);
        }

        @Override
        public int getToolTipDisplayDelayTime(Object object) {
            return R4EUIConstants.TOOLTIP_DISPLAY_DELAY;
        }

        @Override
        public int getToolTipTimeDisplayed(Object object) {
            return R4EUIConstants.TOOLTIP_DISPLAY_TIME;
        }

        @Override
        public void update(ViewerCell cell) {
            final Object element = cell.getElement();
            if (element instanceof R4EUIRule) {
                cell.setText(((R4EUIRule) element).getRule().getTitle());
            } else {
                cell.setText(null);
            }
        }
    });

    final TreeViewerColumn classColumn = new TreeViewerColumn(fRuleTreeViewer, SWT.NONE);
    classColumn.getColumn().setText(R4EUIConstants.CLASS_LABEL);
    classColumn.getColumn().setWidth(DEFAULT_TREE_COLUMN_WIDTH);
    classColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof R4EUIRule) {
                return UIUtils.getClassStr(((R4EUIRule) element).getRule().getClass_());
            }
            return null;
        }

        @Override
        public String getToolTipText(Object element) {
            if (element instanceof R4EUIRule) {
                return ((R4EUIRule) element).getRule().getDescription();
            }
            return null;
        }

        @Override
        public Point getToolTipShift(Object object) {
            return new Point(R4EUIConstants.TOOLTIP_DISPLAY_OFFSET_X, R4EUIConstants.TOOLTIP_DISPLAY_OFFSET_Y);
        }

        @Override
        public int getToolTipDisplayDelayTime(Object object) {
            return R4EUIConstants.TOOLTIP_DISPLAY_DELAY;
        }

        @Override
        public int getToolTipTimeDisplayed(Object object) {
            return R4EUIConstants.TOOLTIP_DISPLAY_TIME;
        }

        @Override
        public void update(ViewerCell cell) {
            final Object element = cell.getElement();
            if (element instanceof R4EUIRule) {
                cell.setText(UIUtils.getClassStr(((R4EUIRule) element).getRule().getClass_()));
            } else {
                cell.setText(null);
            }
        }
    });

    final TreeViewerColumn rankColumn = new TreeViewerColumn(fRuleTreeViewer, SWT.NONE);
    rankColumn.getColumn().setText(R4EUIConstants.RANK_LABEL);
    rankColumn.getColumn().setWidth(DEFAULT_TREE_COLUMN_WIDTH);
    rankColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof R4EUIRule) {
                return UIUtils.getRankStr(((R4EUIRule) element).getRule().getRank());
            }
            return null;
        }

        @Override
        public String getToolTipText(Object element) {
            if (element instanceof R4EUIRule) {
                return ((R4EUIRule) element).getRule().getDescription();
            }
            return null;
        }

        @Override
        public Point getToolTipShift(Object object) {
            return new Point(R4EUIConstants.TOOLTIP_DISPLAY_OFFSET_X, R4EUIConstants.TOOLTIP_DISPLAY_OFFSET_Y);
        }

        @Override
        public int getToolTipDisplayDelayTime(Object object) {
            return R4EUIConstants.TOOLTIP_DISPLAY_DELAY;
        }

        @Override
        public int getToolTipTimeDisplayed(Object object) {
            return R4EUIConstants.TOOLTIP_DISPLAY_TIME;
        }

        @Override
        public void update(ViewerCell cell) {
            final Object element = cell.getElement();
            if (element instanceof R4EUIRule) {
                cell.setText(UIUtils.getRankStr(((R4EUIRule) element).getRule().getRank()));
            } else {
                cell.setText(null);
            }
        }
    });

    fRuleTreeViewer.setInput(R4EUIModelController.getRootElement());

    fRuleTreeViewer.addFilter(new ViewerFilter() {
        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            //Only display rule sets that are included in the parent review group
            if (element instanceof R4EUIRuleSet || element instanceof R4EUIRuleArea
                    || element instanceof R4EUIRuleViolation || element instanceof R4EUIRule) {
                //Get parent RuleSet
                IR4EUIModelElement parentRuleSetElement = (IR4EUIModelElement) element;
                while (!(parentRuleSetElement instanceof R4EUIRuleSet)
                        && null != parentRuleSetElement.getParent()) {
                    if (!parentRuleSetElement.isEnabled()) {
                        return false;
                    }
                    parentRuleSetElement = parentRuleSetElement.getParent();
                }
                //If the current review group contains a reference to this Rule Set, display it
                if ((((R4EUIReviewGroup) R4EUIModelController.getActiveReview().getParent()).getRuleSets()
                        .contains(parentRuleSetElement))) {
                    if (!parentRuleSetElement.isOpen()) {
                        try {
                            ((R4EUIRuleSet) parentRuleSetElement).openReadOnly();
                            fOpenRuleSets.add((R4EUIRuleSet) parentRuleSetElement);
                        } catch (ResourceHandlingException e) {
                            R4EUIPlugin.Ftracer
                                    .traceError("Exception: " + e.toString() + " (" + e.getMessage() + ")");
                            R4EUIPlugin.getDefault().logError("Exception: " + e.toString(), e);
                        } catch (CompatibilityException e) {
                            R4EUIPlugin.Ftracer
                                    .traceError("Exception: " + e.toString() + " (" + e.getMessage() + ")");
                            R4EUIPlugin.getDefault().logError("Exception: " + e.toString(), e);
                        }
                    }
                    return true;
                }
            }
            return false;
        }
    });
    fRuleTreeViewer.expandAll();
    fRuleTreeViewer.refresh();

    textGridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    textGridData.horizontalSpan = 4;
    fRuleTreeViewer.getTree().setLayoutData(textGridData);
    fRuleTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            //Only Rules are selectable
            if (event.getSelection() instanceof IStructuredSelection) {
                if (null == ((IStructuredSelection) event.getSelection()).getFirstElement()) {
                    return;
                }
                if (((IStructuredSelection) event.getSelection()).getFirstElement() instanceof R4EUIRule) {
                    final R4EUIRule rule = (R4EUIRule) ((IStructuredSelection) event.getSelection())
                            .getFirstElement();
                    if (!rule.equals(fSelectedRule)) { //toggle selection
                        fAnomalyTitleInputTextField.setText(rule.getRule().getTitle());
                        fAnomalyDescriptionInputTextField.setText(rule.getRule().getDescription());
                        fAnomalyClass.select(rule.getRule().getClass_().getValue());
                        fAnomalyRank.select(rule.getRule().getRank().getValue());
                        fAnomalyClass.setEnabled(false);
                        fAnomalyRank.setEnabled(false);
                        fAnomalyTitleInputTextField.setEnabled(false);
                        fSelectedRule = rule;
                        fRuleId = buildRuleId();
                        return;
                    }
                }
            }
            fRuleTreeViewer.setSelection(null);
            fAnomalyClass.setEnabled(true);
            fAnomalyRank.setEnabled(true);
            fAnomalyTitleInputTextField.setEnabled(true);
            fSelectedRule = null;
        }
    });

    //Set default focus
    fAnomalyTitleInputTextField.setFocus();
}

From source file:org.eclipse.mylyn.reviews.ui.spi.editor.ReviewSetContentSection.java

License:Open Source License

public void createItemSetTable() {
    if (viewer == null && !set.getItems().isEmpty()) {

        boolean fixedViewerSize = set.getItems().size() > MAXIMUM_ITEMS_SHOWN;
        int heightHint = fixedViewerSize ? 300 : SWT.DEFAULT;
        int style = SWT.SINGLE | SWT.BORDER | SWT.VIRTUAL;
        if (fixedViewerSize) {
            style |= SWT.V_SCROLL;/*from  w w w .j a v a2 s . com*/
        } else {
            style |= SWT.NO_SCROLL;
        }
        viewer = new TableViewer(tableContainer, style);
        GridDataFactory.fillDefaults().span(2, 1).grab(true, true).hint(500, heightHint)
                .applyTo(viewer.getControl());
        viewer.setContentProvider(new IStructuredContentProvider() {

            public void dispose() {
                // ignore
            }

            public Object[] getElements(Object inputElement) {
                return getReviewItems(inputElement).toArray();
            }

            private List<IFileItem> getReviewItems(Object inputElement) {
                if (inputElement instanceof IReviewItemSet) {
                    return ((IReviewItemSet) inputElement).getItems();
                }
                return Collections.emptyList();
            }

            public void inputChanged(final Viewer viewer, Object oldInput, Object newInput) {
            }
        });
        ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.NO_RECREATE);

        final DelegatingStyledCellLabelProvider styledLabelProvider = new DelegatingStyledCellLabelProvider(
                new ReviewsLabelProvider.Simple()) {
            @Override
            public String getToolTipText(Object element) {
                //For some reason tooltips are not delegated..
                return ReviewsLabelProvider.ITEMS_COLUMN.getToolTipText(element);
            };
        };
        viewer.setLabelProvider(styledLabelProvider);
        viewer.addOpenListener(new IOpenListener() {
            public void open(OpenEvent event) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                IFileItem item = (IFileItem) selection.getFirstElement();
                if (item != null) {
                    getParentSection().getUiFactoryProvider()
                            .getOpenFileFactory(ReviewSetContentSection.this.getParentSection(), set, item)
                            .execute();
                }
            }
        });
        EditorUtil.addScrollListener(viewer.getTable());
        viewer.setInput(set);
        getParentSection().getTaskEditorPage().reflow();
    }
}

From source file:org.eclipse.nebula.snippets.grid.viewer.GridViewerSnippet5.java

License:Open Source License

/**
 * @param args/*  ww  w .  ja  v a  2s .  c  o m*/
 */
public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    GridTableViewer v = new GridTableViewer(shell, SWT.FULL_SELECTION);
    v.getGrid().setLinesVisible(true);
    v.getGrid().setHeaderVisible(true);
    v.setContentProvider(new MyContentProvider());
    ColumnViewerToolTipSupport.enableFor(v, ToolTip.NO_RECREATE);

    CellLabelProvider labelProvider = new CellLabelProvider() {

        public String getToolTipText(Object element) {
            return "Tooltip (" + element + ")";
        }

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

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

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

        public void update(ViewerCell cell) {
            cell.setText(cell.getElement().toString());

        }
    };

    GridViewerColumn column = new GridViewerColumn(v, SWT.NONE);
    column.setLabelProvider(labelProvider);
    column.getColumn().setText("Column 1");
    column.getColumn().setWidth(100);

    v.setInput("");

    shell.setSize(200, 200);
    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }

    display.dispose();
}