use of org.eclipse.jface.viewers.ViewerCell in project hale by halestudio.
the class MetadataActionProvider method setup.
/**
* Adds the action to the certain TreeViewer cell
*/
public void setup() {
final TreeEditor metaEditor = new TreeEditor(treeViewer.getTree());
metaEditor.horizontalAlignment = SWT.LEFT;
metaEditor.verticalAlignment = SWT.TOP;
treeViewer.getTree().addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
final ViewerCell cell = treeViewer.getCell(new Point(e.x, e.y));
// Selected cell changed?
if (cell == null || metaEditor.getItem() != cell.getItem() || metaEditor.getColumn() != cell.getColumnIndex()) {
// Clean up any previous editor control
Control oldmetaEditor = metaEditor.getEditor();
if (oldmetaEditor != null) {
oldmetaEditor.dispose();
metaEditor.setEditor(null, null, 0);
}
}
// No selected cell or selected cell didn't change.
if (cell == null || cell.getColumnIndex() == 0 || (metaEditor.getItem() == cell.getItem() && metaEditor.getColumn() == cell.getColumnIndex())) {
return;
}
// Initiate the extension-point
MetadataActionExtension mae = MetadataActionExtension.getInstance();
final Pair<Object, Object> data = retrieveMetadata(cell);
if (data == null) {
return;
}
// get all defined actions
final List<MetadataActionFactory> actionSources = mae.getMetadataActions(data.getFirst().toString());
if (actionSources == null || actionSources.isEmpty()) {
return;
}
// Tool-bar used to view and trigger the different possible
// actions
ToolBar tooli = new ToolBar(treeViewer.getTree(), SWT.NONE);
for (final MetadataActionFactory source : actionSources) {
ToolItem actionItem = new ToolItem(tooli, SWT.PUSH);
// get the Icon of the action
URL iconURL = source.getIconURL();
Image image = ImageDescriptor.createFromURL(iconURL).createImage();
actionItem.setImage(image);
actionItem.setToolTipText(source.getDisplayName());
actionItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
source.createExtensionObject().execute(data.getFirst(), data.getSecond());
} catch (Exception e1) {
_log.userError("error creating metadata action", e1);
}
}
});
}
metaEditor.setEditor(tooli, (TreeItem) cell.getItem(), cell.getColumnIndex());
tooli.pack();
}
});
}
use of org.eclipse.jface.viewers.ViewerCell in project hale by halestudio.
the class InstanceExplorer method createControls.
/**
* @see InstanceViewer#createControls(Composite, SchemaSpaceID)
*/
@Override
public void createControls(Composite parent, SchemaSpaceID schemaSpace) {
main = new Composite(parent, SWT.NONE);
main.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).create());
// selector composite
selectorComposite = new Composite(main, SWT.NONE);
selectorComposite.setLayoutData(GridDataFactory.swtDefaults().create());
selectorComposite.setLayout(GridLayoutFactory.fillDefaults().create());
// viewer composite
Composite viewerComposite = new Composite(main, SWT.NONE);
viewerComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
TreeColumnLayout layout = new TreeColumnLayout();
viewerComposite.setLayout(layout);
viewer = new TreeViewer(viewerComposite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
viewer.getTree().setLinesVisible(true);
// set content provider
viewer.setContentProvider(new InstanceContentProvider());
viewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS);
// TODO set label provider?
// add definition columns
TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.LEFT);
column.getColumn().setText("Definition");
column.setLabelProvider(new TreeColumnViewerLabelProvider(new PairLabelProvider(true, new DefinitionMetaLabelProvider(viewer, false, true))));
layout.setColumnData(column.getColumn(), new ColumnWeightData(1));
// add value column
column = new TreeViewerColumn(viewer, SWT.LEFT);
column.getColumn().setText("Value");
final InstanceValueLabelProvider instanceLabelProvider = new InstanceValueLabelProvider();
column.setLabelProvider(instanceLabelProvider);
// new PairLabelProvider(false, new LabelProvider())));
ColumnViewerToolTipSupport.enableFor(viewer);
layout.setColumnData(column.getColumn(), new ColumnWeightData(1));
MetadataActionProvider maep = new MetadataExploreActionProvider(viewer);
maep.setup();
// Add an editor for copying instance values
editor = new TreeEditor(viewer.getTree());
editor.horizontalAlignment = SWT.RIGHT;
viewer.getTree().addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
final ViewerCell cell = viewer.getCell(new Point(e.x, e.y));
// Selected cell changed?
if (cell == null || editor.getItem() != cell.getItem() || editor.getColumn() != cell.getColumnIndex()) {
// Clean up any previous editor control
Control oldEditor = editor.getEditor();
if (oldEditor != null) {
oldEditor.dispose();
editor.setEditor(null, null, 0);
}
}
// No valid selected cell
if (cell == null || cell.getColumnIndex() == 0) {
return;
}
// cell didn't change
if ((editor.getItem() == cell.getItem() && editor.getColumn() == cell.getColumnIndex())) {
return;
}
// determine instance value
Object value = ((Pair<?, ?>) cell.getViewerRow().getTreePath().getLastSegment()).getSecond();
if (value instanceof Instance) {
value = ((Instance) value).getValue();
}
// copy button
if (value != null) {
final String textValue = value.toString();
if (!textValue.isEmpty()) {
// empty string invalid for
// clipboard
Button button = new Button(viewer.getTree(), SWT.PUSH | SWT.FLAT);
button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
button.setToolTipText("Copy string value");
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// copy content to clipboard
Clipboard clipBoard = new Clipboard(Display.getCurrent());
clipBoard.setContents(new Object[] { textValue }, new Transfer[] { TextTransfer.getInstance() });
clipBoard.dispose();
}
});
// calculate editor size
Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
editor.minimumHeight = size.y;
editor.minimumWidth = size.x;
editor.setEditor(button, (TreeItem) cell.getItem(), cell.getColumnIndex());
}
}
}
});
update();
}
use of org.eclipse.jface.viewers.ViewerCell in project hale by halestudio.
the class AbstractFunctionParameterSection method createControls.
/**
* @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls(org.eclipse.swt.widgets.Composite,
* org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
*/
@Override
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
Composite compparent = getWidgetFactory().createComposite(parent);
compparent.setLayout(new FormLayout());
Composite composite = getWidgetFactory().createComposite(compparent);
TableColumnLayout columnLayout = new TableColumnLayout();
composite.setLayout(columnLayout);
FormData data = new FormData();
data.width = 100;
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, -0);
data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
data.bottom = new FormAttachment(100, -ITabbedPropertyConstants.VSPACE);
composite.setLayoutData(data);
tableViewer = new TableViewer(composite, SWT.FULL_SELECTION);
Table table = tableViewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
TableViewerColumn nameviewercol = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn namecol = nameviewercol.getColumn();
columnLayout.setColumnData(namecol, new ColumnWeightData(20));
namecol.setText("Name");
nameviewercol.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((FunctionParameter) cell.getElement()).getName());
}
});
TableViewerColumn lableviewercol = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn lablecol = lableviewercol.getColumn();
columnLayout.setColumnData(lablecol, new ColumnWeightData(20));
lablecol.setText("Label");
lableviewercol.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((FunctionParameter) cell.getElement()).getDisplayName());
}
});
TableViewerColumn occurenceviewercol = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn occurencecol = occurenceviewercol.getColumn();
columnLayout.setColumnData(occurencecol, new ColumnWeightData(10));
occurencecol.setText("Occurence");
occurenceviewercol.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
FunctionParameter cellparameter = ((FunctionParameter) cell.getElement());
cell.setText(String.valueOf(cellparameter.getMinOccurrence()) + ".." + (String.valueOf(cellparameter.getMaxOccurrence())));
}
});
TableViewerColumn descriptionviewercol = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn descriptioncol = descriptionviewercol.getColumn();
columnLayout.setColumnData(descriptioncol, new ColumnWeightData(40));
descriptioncol.setText("Description");
descriptionviewercol.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(String.valueOf(((FunctionParameter) cell.getElement()).getDescription()));
}
});
}
use of org.eclipse.jface.viewers.ViewerCell in project sling by apache.
the class MVPEditor method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
// now add the node type dropbox-combo
Composite header = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
layout.numColumns = 3;
header.setLayout(layout);
Label label = new Label(header, SWT.WRAP);
label.setText("Modify property " + property.getName() + ":");
GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
label.setLayoutData(data);
label.setFont(parent.getFont());
ToolBar buttonBar = new ToolBar(header, SWT.NONE);
ToolItem invisible = new ToolItem(buttonBar, SWT.NONE);
ToolItem plus = new ToolItem(buttonBar, SWT.NONE);
plus.setImage(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ADD).createImage());
plus.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
plus();
}
});
final ToolItem minus = new ToolItem(buttonBar, SWT.NONE);
minus.setImage(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE).createImage());
minus.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
minus();
}
});
minus.setEnabled(false);
Composite tableParent = new Composite(composite, SWT.NONE);
final GridData layoutData = new GridData(GridData.FILL_BOTH);
layoutData.heightHint = 150;
tableParent.setLayoutData(layoutData);
TableColumnLayout tableLayout = new TableColumnLayout();
tableParent.setLayout(tableLayout);
viewer = new TableViewer(tableParent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
viewer.getTable().setLinesVisible(true);
viewer.getTable().setHeaderVisible(true);
// accessing property here directly, instead of going via (JcrProperty)inputElement;
String[] rawLines = property.getValuesAsString();
// convert raw lines to Line objects for easier editing management
for (int i = 0; i < rawLines.length; i++) {
lines.add(new Line(rawLines[i]));
}
viewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return lines.toArray();
}
});
TableViewerColumn column0 = new TableViewerColumn(viewer, SWT.NONE);
column0.getColumn().setText("Type");
column0.getColumn().setResizable(true);
column0.getColumn().setWidth(100);
tableLayout.setColumnData(column0.getColumn(), new ColumnWeightData(20, 100));
column0.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
try {
cell.setText(property.getTypeAsString());
cell.setForeground(greyColor);
} catch (Exception e) {
cell.setText("n/a");
cell.setForeground(greyColor);
}
}
});
TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.NONE);
column1.getColumn().setText("Value");
column1.getColumn().setResizable(true);
column1.getColumn().setWidth(200);
tableLayout.setColumnData(column1.getColumn(), new ColumnWeightData(80, 200));
column1.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
Line line = (Line) cell.getElement();
cell.setText(line.getValue());
}
});
column1.setEditingSupport(new EditingSupport(viewer) {
@Override
protected void setValue(Object element, Object value) {
Line line = (Line) element;
line.setValue(String.valueOf(value));
// trigger a refresh:
viewer.setInput(property);
}
@Override
protected Object getValue(Object element) {
final Line line = (Line) element;
final String value = line.getValue();
System.out.println("Value=" + value);
return value;
}
@Override
protected CellEditor getCellEditor(Object element) {
return new TextCellEditor(viewer.getTable());
}
@Override
protected boolean canEdit(Object element) {
// all values are editable
return true;
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
final ISelection selection = event.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection iss = (IStructuredSelection) selection;
if (iss.isEmpty()) {
minus.setEnabled(false);
} else {
minus.setEnabled(true);
}
} else {
minus.setEnabled(false);
}
}
});
viewer.setInput(property);
return composite;
}
use of org.eclipse.jface.viewers.ViewerCell in project liferay-ide by liferay.
the class MigrationProblemPreferencePage method _createColumns.
private void _createColumns(final TableViewer problemsViewer) {
final String[] titles = { "Tickets", "Problem" };
final int[] bounds = { 65, 55 };
TableViewerColumn col = _createTableViewerColumn(titles[0], bounds[0], problemsViewer);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Problem p = (Problem) element;
return p.getTicket();
}
});
col = _createTableViewerColumn(titles[1], bounds[1], problemsViewer);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Problem p = (Problem) element;
return p.getTitle();
}
@Override
public void update(ViewerCell cell) {
super.update(cell);
Table table = problemsViewer.getTable();
table.getColumn(1).pack();
}
});
}
Aggregations