use of org.eclipse.swt.custom.TreeEditor in project tdi-studio-se by Talend.
the class UIManager method changeSchemasDetailView.
/**
*
* cLi Comment method "refreshSchemasDetailView".
*
* refresh schema details view by different provider.
*/
public void changeSchemasDetailView(final TreeViewer schemaDetailsViewer, boolean model) {
if (schemaDetailsViewer == null || schemaDetailsViewer.getTree().isDisposed()) {
return;
}
final Tree tree = schemaDetailsViewer.getTree();
// removed all columns
final TreeColumn[] columns = tree.getColumns();
for (TreeColumn col : columns) {
col.dispose();
}
if (columnTreeEditor != null) {
columnTreeEditor.dispose();
final Control editor = columnTreeEditor.getEditor();
if (editor != null && !editor.isDisposed()) {
editor.setVisible(false);
editor.dispose();
}
columnTreeEditor = null;
}
if (columnMouseListener != null) {
tree.removeMouseListener(columnMouseListener);
columnMouseListener = null;
}
SchemaDetailsProvider provider = null;
if (model) {
// is properties model
provider = new SchemaDetailsPropertiesProvider(this);
List<String> columnProperties = new ArrayList<String>();
List<CellEditor> cellEidors = new ArrayList<CellEditor>();
for (EPropertyName pName : EPropertyName.values()) {
columnProperties.add(pName.name());
TreeColumn pColumn = new TreeColumn(tree, SWT.NONE);
pColumn.setWidth(100);
pColumn.setText(pName.getName());
final CellEditor cellEditor;
switch(pName) {
case NAME:
case LENGTH:
case TAGLEVEL:
// case CARD:
case PATTERN:
cellEditor = new SchemaDetailsTextCellEditor(schemaDetailsViewer, pName);
break;
case KEY:
pColumn.setToolTipText("Only one column can be set as key.");
cellEditor = new SchemaDetailsCheckBoxCellEditor(tree);
break;
// break;
case TYPE:
cellEditor = new ComboBoxCellEditor(tree, MultiSchemasUtil.getTalendTypeLabel(), SWT.READ_ONLY);
break;
default:
cellEditor = null;
}
if (cellEditor != null) {
cellEidors.add(cellEditor);
}
}
schemaDetailsViewer.setColumnProperties(columnProperties.toArray(new String[0]));
schemaDetailsViewer.setCellEditors(cellEidors.toArray(new CellEditor[0]));
schemaDetailsViewer.setCellModifier(new SchemaDetailsPropertiesCellModifier(schemaDetailsViewer, this));
// set sorter
TreeColumn sorterColumn = tree.getColumn(0);
sorterColumn.addListener(SWT.Selection, new SchemaDetailsViewerSorterListener(schemaDetailsViewer));
tree.setSortColumn(sorterColumn);
tree.setSortDirection(SWT.UP);
schemaDetailsViewer.setSorter(new SchemaDetailsViewerSorter(schemaDetailsViewer, sorterColumn, tree.getSortDirection() == SWT.UP));
} else {
// is column model
provider = new SchemaDetailsColumnsProvider(this);
// first columm is fixed.
TreeColumn propertyColumn = new TreeColumn(tree, SWT.NONE);
propertyColumn.setWidth(80);
propertyColumn.setResizable(false);
//
columnTreeEditor = new TreeEditor(tree);
columnTreeEditor.horizontalAlignment = SWT.LEFT;
columnTreeEditor.grabHorizontal = true;
columnMouseListener = new SchemaDetailsColumnMouseAdapter(schemaDetailsViewer, columnTreeEditor, this);
tree.addMouseListener(columnMouseListener);
}
schemaDetailsViewer.setContentProvider(provider);
schemaDetailsViewer.setLabelProvider(provider);
//
}
use of org.eclipse.swt.custom.TreeEditor 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.swt.custom.TreeEditor 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.swt.custom.TreeEditor in project pentaho-kettle by pentaho.
the class RepositoryExplorerDialog method renameJob.
public void renameJob(TreeItem treeitem, String jobname, RepositoryDirectoryInterface repositorydir) {
final TreeItem ti = treeitem;
final String name = jobname;
final RepositoryDirectoryInterface repdir = repositorydir;
TreeEditor editor = new TreeEditor(wTree);
editor.setItem(ti);
final Text text = new Text(wTree, SWT.NONE);
props.setLook(text);
text.setText(name);
text.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent arg0) {
// Focus is lost: apply changes
String newname = text.getText();
if (renameJob(name, repdir, newname)) {
ti.setText(newname);
}
text.dispose();
}
});
text.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
// ESC --> Don't change tree item...
if (e.keyCode == SWT.ESC) {
text.dispose();
}
// ENTER --> Save changes...
if (e.character == SWT.CR) {
String newname = text.getText();
if (renameJob(name, repdir, newname)) {
ti.setText(newname);
}
text.dispose();
}
}
});
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
editor.grabVertical = true;
editor.minimumWidth = 50;
text.selectAll();
text.setFocus();
editor.layout();
editor.setEditor(text);
}
use of org.eclipse.swt.custom.TreeEditor in project pentaho-kettle by pentaho.
the class RepositoryExplorerDialog method renameDatabase.
public boolean renameDatabase() {
boolean retval = false;
final TreeItem ti = wTree.getSelection()[0];
if (ti.getItemCount() == 0) {
final String name = ti.getText();
TreeEditor editor = new TreeEditor(wTree);
editor.setItem(ti);
final Text text = new Text(wTree, SWT.NONE);
props.setLook(text);
text.setText(name);
text.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent arg0) {
// Focus is lost: apply changes
String newname = text.getText();
if (renameDatabase(name, newname)) {
ti.setText(newname);
}
text.dispose();
}
});
text.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
// ESC --> Don't change tree item...
if (e.keyCode == SWT.ESC) {
text.dispose();
}
// ENTER --> Save changes...
if (e.character == SWT.CR) {
if (ti.getText().equals(name)) {
// Only if the name wasn't changed already.
String newname = text.getText();
if (renameDatabase(name, newname)) {
ti.setText(newname);
}
text.dispose();
}
}
}
});
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
editor.grabVertical = true;
editor.minimumWidth = 50;
text.selectAll();
text.setFocus();
editor.layout();
editor.setEditor(text);
}
return retval;
}
Aggregations