List of usage examples for org.eclipse.jface.viewers ViewerCell setImage
public void setImage(Image image)
From source file:org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { ICachegrindElement element = ((ICachegrindElement) cell.getElement()); int index = cell.getColumnIndex(); if (index == 0) { if (element instanceof CachegrindFile) { // Try to use the CElementLabelProvider IAdaptable model = ((CachegrindFile) element).getModel(); if (model != null) { cell.setText(cLabelProvider.getText(model)); cell.setImage(cLabelProvider.getImage(model)); } else { // Fall back String name = ((CachegrindFile) element).getName(); cell.setText(name);// www .j a va 2s . co m cell.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE)); } } else if (element instanceof CachegrindFunction) { // Try to use the CElementLabelProvider IAdaptable model = ((CachegrindFunction) element).getModel(); if (model != null) { cell.setText(cLabelProvider.getText(model)); cell.setImage(cLabelProvider.getImage(model)); } else { // Fall back String name = ((CachegrindFunction) element).getName(); cell.setText(name); cell.setImage(FUNC_IMG); } } else if (element instanceof CachegrindLine) { cell.setText(NLS.bind(Messages.getString("CachegrindViewPart.line"), //$NON-NLS-1$ ((CachegrindLine) element).getLine())); cell.setImage(DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_INSTRUCTION_POINTER_TOP)); } else if (element instanceof CachegrindOutput) { cell.setText(NLS.bind(Messages.getString("CachegrindViewPart.Total_PID"), //$NON-NLS-1$ ((CachegrindOutput) element).getPid())); cell.setImage(DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_REGISTER)); } } else if (element instanceof CachegrindFunction) { cell.setText(df.format(((CachegrindFunction) element).getTotals()[index - 1])); } else if (element instanceof CachegrindLine) { cell.setText(df.format(((CachegrindLine) element).getValues()[index - 1])); } else if (element instanceof CachegrindOutput) { cell.setText(df.format(((CachegrindOutput) element).getSummary()[index - 1])); } }
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 . j a va2 s .c o m 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.GistAttachmentTableLabelProvider.java
License:Open Source License
@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));//from w w w . j a v a2 s . c o m }
From source file:org.eclipse.mylyn.reviews.r4e.ui.internal.annotation.control.R4EAnnotationInformationControl.java
License:Open Source License
/** * Method addAnnotationsInformation./* www .j a v a2 s . c o m*/ * * @see org.eclipse.mylyn.reviews.frame.ui.annotation.impl.ReviewAnnotationInformationControl#addAnnotationsInformation() */ @Override protected void addAnnotationsInformation() { fAnnotationTree = new TreeViewer(fComposite, SWT.MULTI | SWT.FULL_SELECTION | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL); fAnnotationTree.setContentProvider(new R4EAnnotationContentProvider()); fAnnotationTree.setSorter(new R4EAnnotationTypeSorter()); fAnnotationTree.setLabelProvider(new ReviewNavigatorLabelProvider() { @Override public void update(ViewerCell aCell) { final Object cellContents = aCell.getElement(); if (cellContents instanceof IReviewAnnotation) { aCell.setText(((IReviewAnnotation) cellContents).getText()); final Image image = getImage((Annotation) cellContents); if (null != image) { aCell.setImage(image); } } else if (cellContents instanceof R4EAnnotationText) { aCell.setText(((R4EAnnotationText) cellContents).getText()); } } private Image getImage(Annotation aAnnotation) { if (aAnnotation instanceof R4ECommentAnnotation) { return UIUtils .loadIcon(((R4ECommentAnnotation) aAnnotation).getSourceElement().getImageLocation()); } final AnnotationPreferenceLookup lookup = EditorsPlugin.getDefault() .getAnnotationPreferenceLookup(); if (lookup != null) { final AnnotationPreference preference = lookup.getAnnotationPreference(aAnnotation); if (preference != null) { final ImageRegistry registry = EditorsPlugin.getDefault().getImageRegistry(); final Image image = registry.get(aAnnotation.getType()); if (image != null) { return image; } } } return null; } }); fAnnotationTree.setInput(fInput); //Adjust toolbar commands based on selection fAnnotationTree.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent aEvent) { //Check and set files based on selected cloneable anomaly if (aEvent.getSelection() instanceof IStructuredSelection) { if (null != ((IStructuredSelection) aEvent.getSelection()).getFirstElement()) { Object selectedObject = ((IStructuredSelection) aEvent.getSelection()).getFirstElement(); while ((null != selectedObject) && !(selectedObject instanceof R4EAnnotation)) { selectedObject = ((R4EAnnotationText) selectedObject).getParent(); } if (null != selectedObject) { selectElementInNavigator((R4EAnnotation) selectedObject); } } } } private void selectElementInNavigator(R4EAnnotation aSelectedAnnotation) { final IR4EUIModelElement element = aSelectedAnnotation.getSourceElement(); if (null != element) { updateToolbar(element); //NOTE: For now, we changed to code so that we do not show the properties here // (we only select the element in the Review Navigator if possible). To show the properties, // the user can use the Show Properties command available in the annotation popup window. // the only drawback is that the element needs to be visible in the REview Navigator for // the properties to be displayed. This is a limitation for now. if (null != R4EUIModelController.getNavigatorView()) { final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage(); fPreSelectionActivePart = page.getActivePart(); R4EUIModelController.getNavigatorView().updateView(element, 0, false); } //Highlight selected annotation source in editor if (!fAutomaticSelection) { setHighlightText(aSelectedAnnotation); } fAutomaticSelection = false; } } /** * Method setHighlightText. * * @param aAnnotation * R4EAnnotation */ private void setHighlightText(R4EAnnotation aAnnotation) { //Set the highlight on the editor previously active if ((null != fPreSelectionActivePart) && fPreSelectionActivePart instanceof IEditorPart) { final IEditorInput input = ((IEditorPart) fPreSelectionActivePart).getEditorInput(); if (null != input) { if (input instanceof R4ECompareEditorInput) { UIUtils.selectElementInEditor((R4ECompareEditorInput) input); } else if (input instanceof R4EFileEditorInput || input instanceof R4EFileRevisionEditorInput) { final Position position = aAnnotation.getPosition(); if (null != position) { final int offset = position.getOffset(); final int length = position.getLength(); if (fPreSelectionActivePart instanceof ITextEditor) { ((ITextEditor) fPreSelectionActivePart).selectAndReveal(offset, length); final TextSelection selectedText = new TextSelection(offset, length); ((ITextEditor) fPreSelectionActivePart).getSelectionProvider() .setSelection(selectedText); } } } } } } }); fAnnotationTree.addTreeListener(new ITreeViewerListener() { public void treeExpanded(TreeExpansionEvent aEvent) { Display.getDefault().asyncExec(new Runnable() { public void run() { final Point size = computeSizeHint(); setSize(size.x, size.y); } }); } public void treeCollapsed(TreeExpansionEvent aEvent) { Display.getDefault().asyncExec(new Runnable() { public void run() { final Point size = computeSizeHint(); setSize(size.x, size.y); } }); } }); final GridData data = new GridData(GridData.FILL, GridData.FILL, true, true); fAnnotationTree.getTree().setLayoutData(data); //If there is only 1 element in this annotation, select it automatically if ((null != fInput) && (fInput.getAnnotations().size() == 1)) { fAutomaticSelection = true; final ISelection selection = new StructuredSelection(fInput.getAnnotations().get(0)); fAnnotationTree.setSelection(selection, true); fAnnotationTree.expandToLevel(2); } }
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 ava 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, 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 .j a v a 2s . c om*/ * @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.r4e.ui.internal.navigator.ReviewNavigatorLabelProvider.java
License:Open Source License
/** * Method update.// w w w . j av a2 s .c om * * @param cell * ViewerCell */ @Override public void update(ViewerCell cell) { cell.setText(((IR4EUIModelElement) cell.getElement()).getName()); cell.setImage(((IR4EUIModelElement) cell.getElement()) .getImage(((IR4EUIModelElement) cell.getElement()).getImageLocation())); }
From source file:org.eclipse.nebula.snippets.grid.viewer.GridViewerSnippet6.java
License:Open Source License
/** * @param args//from w w w. java 2 s .co m */ public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final ImageRegistry reg = new ImageRegistry(display); reg.put("ICON", ImageDescriptor.createFromFile(GridViewerSnippet6.class, "th_vertical.gif")); GridTableViewer v = new GridTableViewer(shell, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); v.getGrid().setLinesVisible(true); v.getGrid().setHeaderVisible(true); v.setContentProvider(new MyContentProvider()); v.getGrid().setRowHeaderVisible(true); v.setRowHeaderLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { cell.setImage(reg.get("ICON")); cell.setText(cell.getElement().toString()); } }); 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(); }
From source file:org.eclipse.oomph.setup.ui.IndexManagerDialog.java
License:Open Source License
@Override protected void createUI(Composite parent) { indexViewer = new TableViewer(parent, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); indexViewer.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); indexViewer.setContentProvider(new IStructuredContentProvider() { public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // Do nothing. }//from w w w. ja va2 s. c o m public void dispose() { // Do nothing. } public Object[] getElements(Object inputElement) { return indexChoices.entrySet().toArray(); } }); final ColumnViewerInformationControlToolTipSupport columnViewerInformationControlToolTipSupport = new ColumnViewerInformationControlToolTipSupport( indexViewer, new LocationListener() { public void changing(LocationEvent event) { } public void changed(LocationEvent event) { } }); class MyLabelProvider extends CellLabelProvider implements ILabelProvider { private final Color gray = indexViewer.getTable().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY); private final Font normalFont = indexViewer.getTable().getFont(); private final Font italicFont = ExtendedFontRegistry.INSTANCE.getFont(normalFont, IItemFontProvider.ITALIC_FONT); private final Font boldFont = ExtendedFontRegistry.INSTANCE.getFont(normalFont, IItemFontProvider.BOLD_FONT); public String getText(Object element) { return asMapEntry(element).getValue(); } public Image getImage(Object element) { return SetupUIPlugin.INSTANCE.getSWTImage("full/obj16/Index"); } @Override public String getToolTipText(Object element) { URI indexLocation = asMapEntry(element).getKey(); Map<URI, String> indexNames = indexManager.getIndexNames(true); StringBuilder result = new StringBuilder(); String nameLine = "<divs style='white-space:nowrap;'><b>name</b>: " + indexNames.get(indexLocation) + "</div>\n"; result.append(nameLine); String locationLine = "<div style='white-space:nowrap;'><b>location</b>: " + indexLocation + "</div>\n"; result.append(locationLine); String availabilityLine = "<div style='white-space:nowrap;'><b>availability</b>: " + (indexAvailability == null ? "Unknown" : indexAvailability.get(indexLocation) ? "Available" : "Unavailable") + "</div><br/><br/>\n"; result.append(availabilityLine); try { AbstractHoverInformationControlManager hoverInformationControlManager = ReflectUtil.getValue( "hoverInformationControlManager", columnViewerInformationControlToolTipSupport); int max = Math.max(nameLine.length(), locationLine.length()); hoverInformationControlManager.setSizeConstraints(max, 6, false, false); } catch (Throwable throwable) { // Ignore. } return result.toString(); } @Override public void update(ViewerCell cell) { Object element = cell.getElement(); cell.setImage(getImage(element)); URI indexLocation = asMapEntry(element).getKey(); if (!originalIndexChoices.containsKey(indexLocation)) { cell.setForeground(gray); } if (indexLocation.equals(originalIndexLocation)) { cell.setFont(boldFont); } else if (indexAvailability != null && !indexAvailability.get(indexLocation)) { cell.setFont(italicFont); } else { cell.setFont(normalFont); } cell.setText(getText(element) + " "); } } final ILabelProvider labelProvider = new MyLabelProvider(); indexViewer.setLabelProvider(labelProvider); final TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(indexViewer, new FocusCellOwnerDrawHighlighter(indexViewer)); indexViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { focusCellManager.getFocusCell(); updateEnablement(); } }); indexViewer.setInput(indexManager); TextCellEditor textCellEditor = new TextCellEditor(indexViewer.getTable(), SWT.BORDER); indexViewer.setCellEditors(new CellEditor[] { textCellEditor }); indexViewer.setColumnProperties(new String[] { "label" }); ColumnViewerEditorActivationStrategy editorActivationStrategy = new ColumnViewerEditorActivationStrategy( indexViewer) { @Override protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) { return event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.F2; } }; TableViewerEditor.create(indexViewer, focusCellManager, editorActivationStrategy, ColumnViewerEditor.KEYBOARD_ACTIVATION); indexViewer.setCellModifier(new ICellModifier() { public void modify(Object element, String property, Object value) { asMapEntry(((TableItem) element).getData()).setValue((String) value); indexViewer.refresh(true); } public Object getValue(Object element, String property) { return labelProvider.getText(element).trim(); } public boolean canModify(Object element, String property) { return true; } }); if (!indexChoices.isEmpty()) { indexViewer.setSelection(new StructuredSelection(indexChoices.entrySet().iterator().next())); } }
From source file:org.eclipse.papyrus.infra.gmfdiag.dnd.preferences.DropStrategyLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { Object element = cell.getElement(); if (element instanceof DropStrategy) { DropStrategy strategy = (DropStrategy) element; if (cell.getColumnIndex() == DropStrategyEditor.LABEL_COLUMN) { cell.setImage(strategy.getImage()); int foreground; if (DropStrategyManager.instance.isActive(strategy)) { foreground = SWT.COLOR_BLACK; } else { foreground = SWT.COLOR_GRAY; }/* ww w . j ava 2 s . c om*/ cell.setForeground(Display.getCurrent().getSystemColor(foreground)); cell.setText(strategy.getLabel()); } } }