List of usage examples for org.eclipse.jface.viewers ViewerCell getElement
public Object getElement()
From source file:de.tobject.findbugs.properties.ManagePathsWidget.java
License:Open Source License
public CheckboxTableViewer createViewer(String title, String linkText, boolean withCheckBox) { GridLayout layout = new GridLayout(2, false); layout.marginHeight = 0;//from www . jav a 2 s.c om layout.marginWidth = 0; this.setLayout(layout); this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); Label titleLabel = new Label(this, SWT.NULL); titleLabel.setText(title); titleLabel.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, true, false, 2, 1)); if (linkText != null) { Link details = new Link(this, SWT.NULL); details.setText(linkText); details.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, true, false, 2, 1)); details.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { Program.launch(e.text); } public void widgetDefaultSelected(SelectionEvent e) { // noop } }); } int style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL; if (withCheckBox) { style |= SWT.CHECK; } Table table = new Table(this, style); CheckboxTableViewer viewer1 = new CheckboxTableViewer(table); viewer1.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2)); final PathElementLabelProvider labelProvider = new PathElementLabelProvider(); viewer1.setLabelProvider(labelProvider); this.viewer = viewer1; viewer1.getControl().addMouseTrackListener(new MouseTrackAdapter() { @Override public void mouseHover(MouseEvent e) { String tooltip = ""; ViewerCell cell = viewer.getCell(new Point(e.x, e.y)); if (cell != null) { tooltip = labelProvider.getToolTip(cell.getElement()); } viewer.getControl().setToolTipText(tooltip); } @Override public void mouseExit(MouseEvent e) { viewer.getControl().setToolTipText(""); } }); return viewer1; }
From source file:de.topicmapslab.onotoa.wordlisteditor.editor.WordListEditor.java
License:Open Source License
/** * Creates the table viewer and columns. * /*w ww .jav a2 s.com*/ * @param table * the table which will be used by the wrapper */ private void initTable(final Table table) { TableColumnLayout layout = (TableColumnLayout) table.getParent().getLayout(); table.setLinesVisible(true); table.setHeaderVisible(true); table.setMenu(new Menu(table)); table.addKeyListener(new KeyAdapter() { /** * {@inheritDoc} */ @Override public void keyPressed(KeyEvent e) { if ((e.keyCode == (int) 'c') && ((e.stateMask & SWT.CTRL) != 0)) { Clipboard clipboard = new Clipboard(e.widget.getDisplay()); StringBuilder builder = new StringBuilder(); String lineSeparator = System.getProperty("line.separator"); IStructuredSelection sel = (IStructuredSelection) viewer.getSelection(); Iterator<?> it = sel.iterator(); while (it.hasNext()) { Word w = (Word) it.next(); builder.append("\""); builder.append(w.getWord()); builder.append("\""); builder.append(";"); builder.append(w.getType().getName()); if (it.hasNext()) { builder.append(lineSeparator); } } clipboard.setContents(new Object[] { builder.toString() }, new Transfer[] { TextTransfer.getInstance() }); clipboard.dispose(); } } }); viewer = new CheckboxTableViewer(table); viewer.setContentProvider(ArrayContentProvider.getInstance()); viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { removeButton.setEnabled(viewer.getCheckedElements().length != 0); } }); ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) { protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) { return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR) || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC; } }; TableViewerEditor.create(viewer, null, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION); // word column TableViewerColumn tvc = new TableViewerColumn(viewer, SWT.NONE); layout.setColumnData(tvc.getColumn(), new ColumnWeightData(1)); tvc.getColumn().setText("Word"); tvc.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { cell.setText(((Word) cell.getElement()).getWord()); } }); tvc.setEditingSupport(new EditingSupport(viewer) { @Override protected void setValue(Object element, Object value) { WordListContainer wlc = (WordListContainer) viewer.getInput(); Word w = (Word) element; if (w.getWord().equals(value)) return; if (wlc.containsWord((String) value)) { MessageDialog.openInformation(table.getShell(), "Word already entered", "The word <" + value + "> was already entered"); return; } AbstractCommand cmd = null; cmd = new ModifyWordCommand(w, (String) value); commandStack.execute(cmd); viewer.refresh(element); } @Override protected Object getValue(Object element) { Word w = (Word) element; return w.getWord(); } @Override protected CellEditor getCellEditor(Object element) { return new TextCellEditor(table); } @Override protected boolean canEdit(Object element) { return true; } }); // create column sorter new AbstractColumnViewerSorter(viewer, tvc) { @Override public String getText(Object element) { return ((Word) element).getWord(); } }; // type column tvc = new TableViewerColumn(viewer, SWT.NONE); tvc.getColumn().setText("Type"); layout.setColumnData(tvc.getColumn(), new ColumnWeightData(1)); tvc.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { String name = ((Word) cell.getElement()).getType().getName(); cell.setText(name); cell.setImage(ImageProvider.getImageOfKindOfTopic(KindOfTopicType.getByName(name))); } }); tvc.setEditingSupport(new EditingSupport(viewer) { final String[] ITEMS = { KindOfTopicType.TOPIC_TYPE.getName(), KindOfTopicType.OCCURRENCE_TYPE.getName(), KindOfTopicType.NAME_TYPE.getName(), KindOfTopicType.ROLE_TYPE.getName(), KindOfTopicType.ASSOCIATION_TYPE.getName(), KindOfTopicType.NO_TYPE.getName() }; @Override protected void setValue(Object element, Object value) { int val = (Integer) value; // jump from scope to no type index if (val == 5) val = 6; KindOfTopicType type = KindOfTopicType.get(val); WordListContainer wlc = (WordListContainer) viewer.getInput(); Word w = (Word) element; AbstractCommand cmd = null; if (wlc.contains(w)) { cmd = new ModifyWordTypeCommand((Word) element, type); commandStack.execute(cmd); viewer.refresh(element); } else { cmd = new AddWordCommand(wlc, w.getWord(), type); commandStack.execute(cmd); viewer.refresh(); } } @Override protected Object getValue(Object element) { int val = ((Word) element).getType().getValue(); // switching from scope to no type if (val == 6) val = 5; return val; } @Override protected CellEditor getCellEditor(Object element) { ComboBoxCellEditor comboBoxCellEditor = new ComboBoxCellEditor(table, ITEMS, SWT.READ_ONLY); return comboBoxCellEditor; } @Override protected boolean canEdit(Object element) { return true; } }); // create column sorter new AbstractColumnViewerSorter(viewer, tvc) { @Override public String getText(Object element) { if (((WordListContainer) viewer.getInput()).contains(element)) return ((Word) element).getType().getName(); // hack so hopefully the new element is always the last else return "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzZ"; } }; tvc = new TableViewerColumn(viewer, SWT.NONE); layout.setColumnData(tvc.getColumn(), new ColumnWeightData(2)); tvc.getColumn().setText("Comment"); tvc.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { String tmp = ((Word) cell.getElement()).getComment(); if (tmp == null) tmp = ""; cell.setText(tmp); } }); tvc.setEditingSupport(new EditingSupport(viewer) { @Override protected void setValue(Object element, Object value) { AbstractCommand cmd = null; cmd = new ModifyWordCommentCommand((Word) element, (String) value); commandStack.execute(cmd); viewer.refresh(element); } @Override protected Object getValue(Object element) { String tmp = ((Word) element).getComment(); if (tmp == null) return ""; return tmp; } @Override protected CellEditor getCellEditor(Object element) { return new TextCellEditor(table); } @Override protected boolean canEdit(Object element) { return true; } }); }
From source file:de.uni_hildesheim.sse.qmApp.dialogs.statistics.StatisticsLabelProvider.java
License:Apache License
@Override public void update(ViewerCell cell) { Object element = cell.getElement(); if (element instanceof StatisticsItem) { StatisticsItem item = (StatisticsItem) element; if (column == 1) { cell.setText(item.getValue()); } else {//from w w w.j av a 2 s .c o m cell.setText(item.getLabel()); } } }
From source file:de.walware.docmlet.tex.ui.TexLabelProvider.java
License:Open Source License
@Override public void update(final ViewerCell cell) { final Object cellElement = cell.getElement(); if (cellElement instanceof IModelElement) { final IModelElement element = (IModelElement) cellElement; cell.setImage(getImage(element)); final StyledString styledText = getStyledText(element); cell.setText(styledText.getString()); cell.setStyleRanges(styledText.getStyleRanges()); super.update(cell); } else {/* w w w. ja v a2s. c om*/ cell.setImage(null); cell.setText(cellElement.toString()); cell.setStyleRanges(null); super.update(cell); } }
From source file:de.walware.ecommons.ui.viewers.DecoratingStyledCellLabelProvider.java
License:Open Source License
private boolean waitForPendingDecoration(final ViewerCell cell) { if (this.decorator == null) { return false; }/*w w w.ja v a2 s . c om*/ final Object element = cell.getElement(); final String oldText = cell.getText(); boolean isDecorationPending = false; if (this.decorator instanceof LabelDecorator) { isDecorationPending = !((LabelDecorator) this.decorator) .prepareDecoration(getElementToDecorate(element), oldText, getDecorationContext()); } else if (this.decorator instanceof IDelayedLabelDecorator) { isDecorationPending = !((IDelayedLabelDecorator) this.decorator) .prepareDecoration(getElementToDecorate(element), oldText); } if (isDecorationPending && oldText.length() == 0) { // item is empty: is shown for the first time: don't wait return false; } return isDecorationPending; }
From source file:de.walware.eutils.autonature.internal.AutoNaturePreferencePage.java
License:Open Source License
@Override protected Control createContents(final Composite parent) { final Composite composite = new Composite(parent, SWT.NONE); {/*from w ww. j a v a 2 s. c o m*/ final GridLayout gd = new GridLayout(); gd.marginWidth = 0; gd.marginHeight = 0; gd.numColumns = 1; composite.setLayout(gd); } { this.enableButton = new Button(composite, SWT.CHECK); this.enableButton.setText("Enable automatic project &configuration for:"); this.enableButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); } { final Composite tableComposite = new Composite(composite, SWT.NONE); this.entryViewer = new CheckboxTableViewer( new Table(tableComposite, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION)); final Table table = this.entryViewer.getTable(); final GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); Dialog.applyDialogFont(tableComposite); gd.heightHint = table.getHeaderHeight() + table.getItemHeight() * 10; tableComposite.setLayoutData(gd); final TableColumnLayout tableLayout = new TableColumnLayout(); tableComposite.setLayout(tableLayout); this.entryViewer.setContentProvider(new ArrayContentProvider()); this.entryViewer.setComparator(new AutoConfigComparator()); this.entryViewer.getTable().setHeaderVisible(true); { final TableViewerColumn column = new TableViewerColumn(this.entryViewer, SWT.LEFT); tableLayout.setColumnData(column.getColumn(), new ColumnWeightData(5, true)); column.getColumn().setText("Content Type"); column.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final AutoConfig config = (AutoConfig) cell.getElement(); cell.setText(config.getLabel()); } }); } { final TableViewerColumn column = new TableViewerColumn(this.entryViewer, SWT.LEFT); tableLayout.setColumnData(column.getColumn(), new ColumnWeightData(5, true)); column.getColumn().setText("Project Configuration"); column.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final AutoConfig config = (AutoConfig) cell.getElement(); final List<Task> tasks = config.getTasks(); if (tasks.size() == 1) { cell.setText(tasks.get(0).getLabel()); } else { final StringBuilder sb = new StringBuilder(); sb.append(tasks.get(0).getLabel()); for (int i = 1; i < tasks.size(); i++) { sb.append(", "); sb.append(tasks.get(i).getLabel()); } cell.setText(sb.toString()); } } }); } } Dialog.applyDialogFont(composite); loadConfigs(); loadPrefs(); return composite; }
From source file:de.walware.statet.nico.internal.ui.preferences.ResourceMappingPreferencePage.java
License:Open Source License
protected Composite createTable(final Composite parent) { final TableComposite composite = new ViewerUtil.TableComposite(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); fListViewer = composite.viewer;/*from w w w . ja v a 2 s . com*/ composite.table.setHeaderVisible(true); composite.table.setLinesVisible(true); { final TableViewerColumn column = new TableViewerColumn(composite.viewer, SWT.NONE); composite.layout.setColumnData(column.getColumn(), new ColumnWeightData(1)); column.getColumn().setText("Local"); column.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final IResourceMapping mapping = (IResourceMapping) cell.getElement(); final IFileStore fileStore = mapping.getFileStore(); cell.setText((fileStore != null) ? fileStore.toString() : "<invalid>"); } }); } { final TableViewerColumn column = new TableViewerColumn(composite.viewer, SWT.NONE); composite.layout.setColumnData(column.getColumn(), new ColumnWeightData(1)); column.getColumn().setText("Host"); column.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final IResourceMapping mapping = (IResourceMapping) cell.getElement(); cell.setText(mapping.getHost()); } }); } { final TableViewerColumn column = new TableViewerColumn(composite.viewer, SWT.NONE); composite.layout.setColumnData(column.getColumn(), new ColumnWeightData(1)); column.getColumn().setText("Remote"); column.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final IResourceMapping mapping = (IResourceMapping) cell.getElement(); final IPath path = mapping.getRemotePath(); cell.setText((path != null) ? path.toString() : "<invalid>"); } }); } composite.viewer.setContentProvider(new ArrayContentProvider()); composite.viewer.setComparator(new ComparatorViewerComparator(ResourceMappingManager.DEFAULT_COMPARATOR)); return composite; }
From source file:de.walware.statet.r.internal.console.ui.launching.RConsoleOptionsTab.java
License:Open Source License
private Composite createTrackingOptions(final Composite parent) { final Group group = new Group(parent, SWT.NONE); group.setText("History / Transcript / Tracking:"); group.setLayout(LayoutUtil.createGroupGrid(2)); final ViewerUtil.CheckboxTableComposite trackingTable; {/*w w w . ja v a2 s . c o m*/ trackingTable = new ViewerUtil.CheckboxTableComposite(group, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION); final GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.heightHint = LayoutUtil.hintHeight(trackingTable.table, 5); trackingTable.setLayoutData(gd); fTrackingTable = trackingTable.viewer; } { final TableViewerColumn column = trackingTable.addColumn("Name", SWT.LEFT, new ColumnWeightData(100)); column.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final TrackingConfiguration config = (TrackingConfiguration) cell.getElement(); cell.setText(config.getName()); } }); } fTrackingButtons = new ButtonGroup<TrackingConfiguration>(group) { @Override protected TrackingConfiguration edit1(TrackingConfiguration item, final boolean newItem, final Object parent) { TrackingConfigurationDialog dialog; if (!newItem && item != null && item.getId().equals(HistoryTrackingConfiguration.HISTORY_TRACKING_ID)) { item = new HistoryTrackingConfiguration(item.getId(), (HistoryTrackingConfiguration) item); dialog = new TrackingConfigurationDialog(RConsoleOptionsTab.this.getShell(), item, false) { @Override protected TrackingConfigurationComposite createConfigComposite(final Composite parent) { return new RHistoryConfigurationComposite(parent); } }; } else { if (newItem) { final String id = CUSTOM_TRACKING_ID_PREFIX + (fTrackingMaxCustomId + 1); if (item == null) { item = new TrackingConfiguration(id); } else { item = new TrackingConfiguration(id, item); } } else { item = new TrackingConfiguration(item.getId(), item); } dialog = new TrackingConfigurationDialog(RConsoleOptionsTab.this.getShell(), item, newItem) { @Override protected TrackingConfigurationComposite createConfigComposite(final Composite parent) { return new RTrackingConfigurationComposite(parent); } }; } if (dialog.open() == Dialog.OK) { if (newItem) { fTrackingMaxCustomId++; } return item; } return null; } }; fTrackingButtons.addAddButton(null); fTrackingButtons.addDeleteButton(null); fTrackingButtons.addEditButton(null); fTrackingButtons.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); ViewerUtil.scheduleStandardSelection(fTrackingTable); return group; }
From source file:de.walware.statet.r.internal.console.ui.launching.RRemoteConsoleSelectionDialog.java
License:Open Source License
@Override protected Control createDialogArea(final Composite parent) { // page group final Composite area = (Composite) super.createDialogArea(parent); createMessageArea(area);/*from w ww . ja v a 2s.c o m*/ final IDialogSettings dialogSettings = getDialogSettings(); { final Composite composite = new Composite(area, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); composite.setLayout(LayoutUtil.applyCompositeDefaults(new GridLayout(), 3)); final Label label = new Label(composite, SWT.NONE); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); label.setText(RConsoleMessages.RRemoteConsoleSelectionDialog_Hostname_label); fHostAddressControl = new Combo(composite, SWT.DROP_DOWN); final GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); gd.widthHint = LayoutUtil.hintWidth(fHostAddressControl, 50); fHostAddressControl.setLayoutData(gd); final String[] history = dialogSettings.getArray(SETTINGS_HOST_HISTORY_KEY); if (history != null) { fHistoryAddress.addAll(Arrays.asList(history)); } fHostAddressControl.addSelectionListener(new SelectionAdapter() { @Override public void widgetDefaultSelected(final SelectionEvent e) { update(); } }); final Button goButton = new Button(composite, SWT.PUSH); goButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); goButton.setText(RConsoleMessages.RRemoteConsoleSelectionDialog_Update_label); goButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { update(); } }); } { final TreeComposite composite = new TreeComposite(area, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION); final GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.heightHint = LayoutUtil.hintHeight(composite.tree, 10); composite.setLayoutData(gd); fRServerViewer = composite.viewer; composite.tree.setHeaderVisible(true); ColumnViewerToolTipSupport.enableFor(composite.viewer); { final TreeViewerColumn column = new TreeViewerColumn(fRServerViewer, SWT.NONE); column.getColumn().setText(RConsoleMessages.RRemoteConsoleSelectionDialog_Table_UserOrEngine_label); composite.layout.setColumnData(column.getColumn(), new ColumnWeightData(1)); column.setLabelProvider(new RemoteRLabelProvider() { @Override public void update(final ViewerCell cell) { final Object element = cell.getElement(); String text = null; Image image = null; if (element instanceof String) { text = (String) element; image = SharedUIResources.getImages().get(SharedUIResources.OBJ_USER_IMAGE_ID); } else if (element instanceof RemoteR) { text = getText((RemoteR) element); } cell.setText(text); cell.setImage(image); } @Override public String getText(final RemoteR r) { return r.info.getName(); } }); } { final TreeViewerColumn column = new TreeViewerColumn(fRServerViewer, SWT.NONE); column.getColumn().setText(RConsoleMessages.RRemoteConsoleSelectionDialog_Table_Host_label); composite.layout.setColumnData(column.getColumn(), new ColumnWeightData(1)); column.setLabelProvider(new RemoteRLabelProvider() { @Override public String getText(final RemoteR r) { return r.hostName; } }); } fRServerViewer.setContentProvider(new RemoteRContentProvider()); fRServerViewer.getTree().addSelectionListener(new SelectionListener() { @Override public void widgetSelected(final SelectionEvent e) { updateState(); } @Override public void widgetDefaultSelected(final SelectionEvent e) { updateState(); if (getOkButton().isEnabled()) { buttonPressed(IDialogConstants.OK_ID); } } }); } Dialog.applyDialogFont(area); updateInput(); if (fRServerList != null) { updateStatus(new Status(IStatus.OK, RConsoleUIPlugin.PLUGIN_ID, RConsoleMessages.RRemoteConsoleSelectionDialog_info_ListRestored_message)); } return area; }
From source file:de.walware.statet.r.internal.debug.ui.preferences.REnvLocalConfigDialog.java
License:Open Source License
@Override protected Control createDialogArea(final Composite parent) { final Composite area = new Composite(parent, SWT.NONE); area.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); area.setLayout(LayoutUtil.createDialogGrid(2)); { // Name:/* w w w . java 2 s. c o m*/ final Label label = new Label(area, SWT.LEFT); label.setText(Messages.REnv_Detail_Name_label + ':'); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); fNameControl = new Text(area, SWT.BORDER); final GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); gd.widthHint = LayoutUtil.hintWidth(fNameControl, 60); fNameControl.setLayoutData(gd); fNameControl.setEditable(fConfigModel.isEditable()); } if (fConfigModel.isEditable()) { // Location: final Label label = new Label(area, SWT.LEFT); label.setText(Messages.REnv_Detail_Location_label + ':'); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); fRHomeControl = new RHomeComposite(area); fRHomeControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); } LayoutUtil.addSmallFiller(area, false); { // Architecture / Bits: final Label label = new Label(area, SWT.LEFT); label.setText(Messages.REnv_Detail_Arch_label + ':'); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); final Composite composite = new Composite(area, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); composite.setLayout(LayoutUtil.createCompositeGrid(3)); { fRArchControl = new Combo(composite, SWT.DROP_DOWN); final GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false); gd.widthHint = LayoutUtil.hintWidth(fRArchControl, 8); fRArchControl.setLayoutData(gd); fRArchControl.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { final int selectionIdx; if (!fRArchControl.getListVisible() && (selectionIdx = fRArchControl.getSelectionIndex()) >= 0) { final String item = fRArchControl.getItem(selectionIdx); } } }); fRArchControl.setEnabled(fConfigModel.isEditable()); } if (fConfigModel.isEditable()) { fLoadButton = new Button(composite, SWT.PUSH); fLoadButton.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, false, 2, 1)); fLoadButton.setText(Messages.REnv_Detail_DetectSettings_label); fLoadButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { detectSettings(); } }); } else { LayoutUtil.addGDDummy(composite, true, 2); } } { // Libraries: final Label label = new Label(area, SWT.LEFT); label.setText(Messages.REnv_Detail_Libraries_label + ":"); //$NON-NLS-1$ label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); final Composite composite = new Composite(area, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); composite.setLayout(LayoutUtil.createCompositeGrid(2)); final TreeComposite treeComposite = new ViewerUtil.TreeComposite(composite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION); fRLibrariesViewer = treeComposite.viewer; final GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.widthHint = LayoutUtil.hintWidth(fNameControl, 80); gd.heightHint = LayoutUtil.hintHeight(treeComposite.tree, 10); treeComposite.setLayoutData(gd); treeComposite.viewer.setContentProvider(new ITreeContentProvider() { @Override public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { } @Override public void dispose() { } @Override public Object[] getElements(final Object inputElement) { return fConfigModel.getRLibraryGroups().toArray(); } @Override public Object getParent(final Object element) { if (element instanceof RLibraryContainer) { return ((RLibraryContainer) element).parent; } return null; } @Override public boolean hasChildren(final Object element) { if (element instanceof IRLibraryGroup.WorkingCopy) { return !((IRLibraryGroup.WorkingCopy) element).getLibraries().isEmpty(); } return false; } @Override public Object[] getChildren(final Object parentElement) { if (parentElement instanceof IRLibraryGroup.WorkingCopy) { final IRLibraryGroup.WorkingCopy group = (IRLibraryGroup.WorkingCopy) parentElement; final List<? extends IRLibraryLocation.WorkingCopy> libs = group.getLibraries(); final RLibraryContainer[] array = new RLibraryContainer[libs.size()]; for (int i = 0; i < libs.size(); i++) { array[i] = new RLibraryContainer(group, libs.get(i)); } return array; } return null; } }); final TreeViewerColumn column = treeComposite.addColumn(SWT.LEFT, new ColumnWeightData(100)); column.setLabelProvider(new REnvLabelProvider() { @Override public void update(final ViewerCell cell) { final Object element = cell.getElement(); if (element instanceof RLibraryContainer) { final IRLibraryLocation lib = ((RLibraryContainer) element).library; cell.setImage(RUI.getImage(RUI.IMG_OBJ_LIBRARY_LOCATION)); if (lib.getSource() != IRLibraryLocation.USER && lib.getLabel() != null) { cell.setText(lib.getLabel()); } else { cell.setText(lib.getDirectoryPath()); } finishUpdate(cell); return; } super.update(cell); } }); column.setEditingSupport(new EditingSupport(treeComposite.viewer) { @Override protected boolean canEdit(final Object element) { if (element instanceof RLibraryContainer) { final RLibraryContainer container = ((RLibraryContainer) element); return (container.library.getSource() == IRLibraryLocation.USER); } return false; } @Override protected void setValue(final Object element, final Object value) { final RLibraryContainer container = (RLibraryContainer) element; container.library.setDirectoryPath((String) value); getViewer().refresh(container, true); getDataBinding().updateStatus(); } @Override protected Object getValue(final Object element) { final RLibraryContainer container = (RLibraryContainer) element; return container.library.getDirectoryPath(); } @Override protected CellEditor getCellEditor(final Object element) { return new ExtensibleTextCellEditor(treeComposite.tree) { @Override protected Control createCustomControl(final Composite parent) { final ResourceInputComposite chooseResourceComposite = new ResourceInputComposite( parent, ResourceInputComposite.STYLE_TEXT, ResourceInputComposite.MODE_DIRECTORY | ResourceInputComposite.MODE_OPEN, Messages.REnv_Detail_LibraryLocation_label) { @Override protected void beforeMenuAction() { getFocusGroup().discontinueTracking(); } @Override protected void afterMenuAction() { getFocusGroup().continueTracking(); } }; chooseResourceComposite.setShowInsertVariable(true, DialogUtil.DEFAULT_NON_ITERACTIVE_FILTERS, null); fText = (Text) chooseResourceComposite.getTextControl(); return chooseResourceComposite; } }; } }); treeComposite.viewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS); treeComposite.viewer.setInput(fConfigModel); ViewerUtil.installDefaultEditBehaviour(treeComposite.viewer); ViewerUtil.scheduleStandardSelection(treeComposite.viewer); fRLibrariesButtons = new ButtonGroup<IRLibraryLocation.WorkingCopy>(composite) { @Override protected IRLibraryLocation.WorkingCopy edit1(final IRLibraryLocation.WorkingCopy item, final boolean newItem, final Object parent) { if (newItem) { return ((IRLibraryGroup.WorkingCopy) parent).newLibrary(""); //$NON-NLS-1$ } return item; } @Override public void updateState() { super.updateState(); if (getDataAdapter().isDirty()) { getDataBinding().updateStatus(); } } }; fRLibrariesButtons.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true)); fRLibrariesButtons.addAddButton(null); fRLibrariesButtons.addDeleteButton(null); // fRLibrariesButtons.addSeparator(); // fRLibrariesButtons.addUpButton(); // fRLibrariesButtons.addDownButton(); final DataAdapter<IRLibraryLocation.WorkingCopy> adapter = new DataAdapter.ListAdapter<IRLibraryLocation.WorkingCopy>( (ITreeContentProvider) fRLibrariesViewer.getContentProvider(), null, null) { private IRLibraryGroup.WorkingCopy getGroup(final Object element) { if (element instanceof IRLibraryGroup.WorkingCopy) { return (IRLibraryGroup.WorkingCopy) element; } else { return ((RLibraryContainer) element).parent; } } @Override public IRLibraryLocation.WorkingCopy getModelItem(final Object element) { if (element instanceof RLibraryContainer) { return ((RLibraryContainer) element).library; } return (IRLibraryLocation.WorkingCopy) element; } @Override public Object getViewerElement(final IRLibraryLocation.WorkingCopy item, final Object parent) { return new RLibraryContainer((IRLibraryGroup.WorkingCopy.WorkingCopy) parent, item); } @Override public boolean isAddAllowed(final Object element) { return !getGroup(element).getId().equals(IRLibraryGroup.R_DEFAULT); } @Override public boolean isModifyAllowed(final Object element) { return (element instanceof RLibraryContainer && ((RLibraryContainer) element).library.getSource() == IRLibraryLocation.USER); } @Override public Object getAddParent(final Object element) { return getGroup(element); } @Override public List<? super IRLibraryLocation.WorkingCopy> getContainerFor(final Object element) { if (element instanceof IRLibraryGroup.WorkingCopy) { return ((IRLibraryGroup.WorkingCopy) element).getLibraries(); } else { return ((RLibraryContainer) element).parent.getLibraries(); } } }; fRLibrariesButtons.connectTo(fRLibrariesViewer, adapter); } if (fConfigModel.isEditable()) { final Composite group = createInstallDirGroup(area); if (group != null) { group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); } } LayoutUtil.addSmallFiller(area, true); applyDialogFont(area); return area; }