use of org.eclipse.jface.viewers.ISelectionChangedListener in project archi by archimatetool.
the class UserPropertiesSection method createTableControl.
private void createTableControl(Composite parent) {
// Table Composite
Composite tableComp = createTableComposite(parent, SWT.NULL);
TableColumnLayout tableLayout = (TableColumnLayout) tableComp.getLayout();
// Table Viewer
fTableViewer = new TableViewer(tableComp, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
fTableViewer.getTable().setHeaderVisible(true);
fTableViewer.getTable().setLinesVisible(true);
addDragSupport();
addDropSupport();
// Help ID on table
PlatformUI.getWorkbench().getHelpSystem().setHelp(fTableViewer.getTable(), HELP_ID);
// Columns
TableViewerColumn columnBlank = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
tableLayout.setColumnData(columnBlank.getColumn(), new ColumnPixelData(24, false));
TableViewerColumn columnKey = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
columnKey.getColumn().setText(Messages.UserPropertiesSection_0);
tableLayout.setColumnData(columnKey.getColumn(), new ColumnWeightData(20, true));
columnKey.setEditingSupport(new KeyEditingSupport(fTableViewer));
// Click on Key Table Header
columnKey.getColumn().addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
sortKeys();
}
});
TableViewerColumn columnValue = new TableViewerColumn(fTableViewer, SWT.NONE, 2);
columnValue.getColumn().setText(Messages.UserPropertiesSection_1);
tableLayout.setColumnData(columnValue.getColumn(), new ColumnWeightData(80, true));
columnValue.setEditingSupport(new ValueEditingSupport(fTableViewer));
// Content Provider
fTableViewer.setContentProvider(new IStructuredContentProvider() {
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public void dispose() {
}
public Object[] getElements(Object inputElement) {
return ((IProperties) inputElement).getProperties().toArray();
}
});
// Label Provider
fTableViewer.setLabelProvider(new LabelCellProvider());
// Toolbar
ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.VERTICAL);
GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).applyTo(toolBar);
ToolBarManager toolBarmanager = new ToolBarManager(toolBar);
// New Property
fActionNewProperty = new Action(Messages.UserPropertiesSection_2) {
@Override
public void run() {
if (isAlive(fPropertiesElement)) {
int index = -1;
IProperty selected = (IProperty) ((IStructuredSelection) fTableViewer.getSelection()).getFirstElement();
if (selected != null) {
index = fPropertiesElement.getProperties().indexOf(selected) + 1;
}
IProperty property = IArchimateFactory.eINSTANCE.createProperty();
executeCommand(new NewPropertyCommand(fPropertiesElement.getProperties(), property, index));
fTableViewer.editElement(property, 1);
}
}
@Override
public String getToolTipText() {
return getText();
}
@Override
public ImageDescriptor getImageDescriptor() {
return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_PLUS);
}
};
// New Multiple Properties
fActionNewMultipleProperty = new Action(Messages.UserPropertiesSection_3) {
@Override
public void run() {
if (isAlive(fPropertiesElement)) {
MultipleAddDialog dialog = new MultipleAddDialog(fPage.getSite().getShell());
if (dialog.open() == Window.OK) {
executeCommand(dialog.getCommand());
}
}
}
@Override
public String getToolTipText() {
return getText();
}
@Override
public ImageDescriptor getImageDescriptor() {
return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_MUTIPLE);
}
};
// Remove Property
fActionRemoveProperty = new Action(Messages.UserPropertiesSection_4) {
@Override
public void run() {
if (isAlive(fPropertiesElement)) {
CompoundCommand compoundCmd = new EObjectNonNotifyingCompoundCommand(fPropertiesElement) {
@Override
public String getLabel() {
return getCommands().size() > 1 ? Messages.UserPropertiesSection_5 : Messages.UserPropertiesSection_6;
}
};
for (Object o : ((IStructuredSelection) fTableViewer.getSelection()).toList()) {
Command cmd = new RemovePropertyCommand(fPropertiesElement.getProperties(), (IProperty) o);
compoundCmd.add(cmd);
}
executeCommand(compoundCmd);
}
}
@Override
public String getToolTipText() {
return getText();
}
@Override
public ImageDescriptor getImageDescriptor() {
return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_SMALL_X);
}
};
fActionRemoveProperty.setEnabled(false);
// Manage
fActionShowKeyEditor = new Action(Messages.UserPropertiesSection_7) {
@Override
public void run() {
if (isAlive(fPropertiesElement)) {
UserPropertiesManagerDialog dialog = new UserPropertiesManagerDialog(fPage.getSite().getShell(), getArchimateModel());
dialog.open();
}
}
@Override
public String getToolTipText() {
return getText();
}
@Override
public ImageDescriptor getImageDescriptor() {
return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_COG);
}
};
toolBarmanager.add(fActionNewProperty);
toolBarmanager.add(fActionNewMultipleProperty);
toolBarmanager.add(fActionRemoveProperty);
toolBarmanager.add(fActionShowKeyEditor);
toolBarmanager.update(true);
/*
* Selection Listener
*/
fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
fActionRemoveProperty.setEnabled(!event.getSelection().isEmpty());
}
});
/*
* Table Double-click on cell
*/
fTableViewer.getTable().addListener(SWT.MouseDoubleClick, new Listener() {
@Override
public void handleEvent(Event event) {
// Get Table item
TableItem item = fTableViewer.getTable().getItem(new Point(event.x, event.y));
// Double-click into empty table creates new Property
if (item == null) {
fActionNewProperty.run();
} else // Handle selected item property double-clicked
{
if (item.getData() instanceof IProperty) {
handleDoubleClick((IProperty) item.getData());
}
}
}
});
hookContextMenu();
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project archi by archimatetool.
the class TreeModelView method doCreatePartControl.
@Override
public void doCreatePartControl(Composite parent) {
fParentComposite = parent;
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 0;
parent.setLayout(layout);
fTreeViewer = new TreeModelViewer(parent, SWT.NULL);
fTreeViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
fTreeViewer.setInput(IEditorModelManager.INSTANCE);
/*
* Listen to Double-click and press Return Action
*/
fTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
handleOpenAction();
}
});
// Tree selection listener
fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
// Update actions
updateActions();
}
});
// Register selections
getSite().setSelectionProvider(getViewer());
// Add Selection Sync
TreeSelectionSynchroniser.INSTANCE.setTreeModelView(this);
// Register us as a UIRequest Listener
UIRequestManager.INSTANCE.addListener(this);
// Search Filter
fSearchFilter = new SearchFilter(fTreeViewer);
fTreeViewer.addFilter(fSearchFilter);
makeActions();
hookContextMenu();
registerGlobalActions();
makeLocalToolBar();
// Drag support
new TreeModelViewerDragDropHandler(fTreeViewer);
// Expand tree elements
TreeStateHelper.INSTANCE.restoreExpandedTreeElements(fTreeViewer);
// This will update previous Undo/Redo text if Tree was closed before
updateActions();
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project xtext-eclipse by eclipse.
the class XtextEObjectSearchDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite container) {
Composite parent = (Composite) super.createDialogArea(container);
if (enableStyledLabels && labelProvider instanceof IStyledLabelProvider) {
final Table table = getTableViewer().getTable();
final IStyledLabelProvider styledLabelProvider = (IStyledLabelProvider) labelProvider;
TableOwnerDrawSupport.install(table);
Listener listener = new Listener() {
@Override
public void handleEvent(Event event) {
handleSetData(event);
}
protected void handleSetData(Event event) {
TableItem item = (TableItem) event.item;
IEObjectDescription description = (IEObjectDescription) item.getData();
if (description != null) {
StyledString styledString = styledLabelProvider.getStyledText(description);
String displayString = styledString.toString();
StyleRange[] styleRanges = styledString.getStyleRanges();
item.setText(displayString);
TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges);
}
}
};
table.addListener(SWT.SetData, listener);
}
messageLabel = new Label(parent, SWT.NONE);
setDefaultGridData(messageLabel);
EObjectDescriptionContentProvider contentProvider = new EObjectDescriptionContentProvider();
getTableViewer().setContentProvider(contentProvider);
getTableViewer().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
if (!structuredSelection.isEmpty()) {
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IEObjectDescription) {
IEObjectDescription eObjectDescription = (IEObjectDescription) firstElement;
URI resourceURI = eObjectDescription.getEObjectURI().trimFragment();
if (resourceURI.isPlatform()) {
messageLabel.setText(resourceURI.toPlatformString(true));
} else if (resourceURI.isFile()) {
messageLabel.setText(resourceURI.toFileString());
} else {
messageLabel.setText(resourceURI.toString());
}
return;
}
}
}
// $NON-NLS-1$
messageLabel.setText("");
}
});
applyFilter();
return parent;
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project cubrid-manager by CUBRID.
the class ShardKeysPanel method initial.
private void initial() {
insertKeyItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
addNewKey();
}
});
deletekeyItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
keyListTable.forceFocus();
deleteKey();
}
});
keyListTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@SuppressWarnings("unchecked")
public void selectionChanged(SelectionChangedEvent arg0) {
int selectedItemCount = keyListTable.getSelectionCount();
if (selectedItemCount > 0) {
deletekeyItem.setEnabled(true);
} else {
deletekeyItem.setEnabled(false);
}
if (selectedItemCount == 1) {
String keyName = ((Map<String, String>) keyListTable.getSelection()[0].getData()).get("0");
keyInfoGroup.setText("Key Info: " + keyName);
insertKeyInfoItem.setEnabled(true);
saveShardKey();
currentShardKey = module.getShardKeysFile().getKey(keyName);
initKeyInfoList();
keyInfoTableViewer.refresh();
setKeyInfoColor();
} else {
insertKeyInfoItem.setEnabled(false);
}
}
});
setKeyListColor();
linkEditorForKeyListTable();
insertKeyInfoItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
addNewKeyInfo();
}
});
deletekeyInfoItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
keyInfoTable.forceFocus();
deleteKeyInfo();
}
});
keyInfoTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent arg0) {
int selectedItemCount = keyInfoTable.getSelectionCount();
if (selectedItemCount > 0) {
deletekeyInfoItem.setEnabled(true);
} else {
deletekeyInfoItem.setEnabled(false);
}
}
});
setKeyInfoColor();
linkEditorForKeyInfoTable();
}
use of org.eclipse.jface.viewers.ISelectionChangedListener 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;
}
Aggregations