use of org.eclipse.jface.layout.TableColumnLayout in project yamcs-studio by yamcs.
the class CommandStackView method createPartControl.
@Override
public void createPartControl(Composite parent) {
resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent);
level0Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level0s.png"));
level1Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level1s.png"));
level2Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level2s.png"));
level3Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level3s.png"));
level4Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level4s.png"));
level5Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level5s.png"));
var gl = new GridLayout();
gl.marginHeight = 0;
gl.marginWidth = 0;
gl.verticalSpacing = 1;
parent.setLayout(gl);
ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent);
errorBackgroundColor = resourceManager.createColor(new RGB(255, 221, 221));
bracketStyler = new Styler() {
@Override
public void applyStyles(TextStyle textStyle) {
textStyle.font = JFaceResources.getTextFont();
}
};
argNameStyler = new Styler() {
@Override
public void applyStyles(TextStyle textStyle) {
textStyle.font = JFaceResources.getTextFont();
textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);
}
};
numberStyler = new Styler() {
@Override
public void applyStyles(TextStyle textStyle) {
textStyle.font = JFaceResources.getTextFont();
textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
}
};
errorStyler = new Styler() {
@Override
public void applyStyles(TextStyle textStyle) {
textStyle.font = JFaceResources.getTextFont();
textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
textStyle.underline = true;
textStyle.underlineColor = Display.getDefault().getSystemColor(SWT.COLOR_RED);
textStyle.underlineStyle = SWT.UNDERLINE_ERROR;
}
};
issuedStyler = new Styler() {
@Override
public void applyStyles(TextStyle textStyle) {
textStyle.font = JFaceResources.getFontRegistry().getItalic(JFaceResources.TEXT_FONT);
textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
}
};
skippedStyler = new Styler() {
@Override
public void applyStyles(TextStyle textStyle) {
textStyle.font = JFaceResources.getFontRegistry().getItalic(JFaceResources.TEXT_FONT);
textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
textStyle.strikeout = true;
textStyle.strikeoutColor = textStyle.foreground;
}
};
var tableWrapper = new Composite(parent, SWT.NONE);
tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
var tcl = new TableColumnLayout();
tableWrapper.setLayout(tcl);
commandTableViewer = new CommandStackTableViewer(tableWrapper, tcl, this);
commandTableViewer.addDoubleClickListener(evt -> {
var sel = (IStructuredSelection) evt.getSelection();
if (sel.getFirstElement() != null) {
var cmd = (StackedCommand) sel.getFirstElement();
if (cmd.getStackedState() != StackedState.ISSUED && cmd.getStackedState() != StackedState.SKIPPED) {
var dialog = new EditStackedCommandDialog(parent.getShell(), cmd);
if (dialog.open() == Window.OK) {
refreshState();
}
}
}
});
var controls = new Composite(parent, SWT.NONE);
var gd = new GridData(GridData.FILL_HORIZONTAL);
gd.heightHint = 30;
controls.setLayoutData(gd);
gl = new GridLayout(2, false);
gl.marginHeight = 0;
gl.marginWidth = 0;
controls.setLayout(gl);
controls.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
bottomLeft = new Composite(controls, SWT.NONE);
gd = new GridData(GridData.FILL_BOTH);
gd.verticalAlignment = SWT.CENTER;
bottomLeft.setLayoutData(gd);
gl = new GridLayout(4, false);
gl.marginWidth = 0;
gl.marginHeight = 0;
bottomLeft.setLayout(gl);
clearanceLabel = new Label(bottomLeft, SWT.NONE);
clearanceLabel.setVisible(false);
clearanceImageLabel = new Label(bottomLeft, SWT.NONE);
clearanceImageLabel.setVisible(false);
clearanceSeparator = new Label(bottomLeft, SWT.SEPARATOR);
gd = new GridData();
gd.heightHint = 15;
clearanceSeparator.setLayoutData(gd);
clearanceSeparator.setVisible(false);
messageLabel = new Label(bottomLeft, SWT.NONE);
messageLabel.setText("");
messageLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
var bottomRight = new Composite(controls, SWT.NONE);
gd = new GridData(GridData.FILL_BOTH);
gd.verticalAlignment = SWT.CENTER;
gd.horizontalAlignment = SWT.RIGHT;
bottomRight.setLayoutData(gd);
gl = new GridLayout(4, false);
gl.marginHeight = 0;
gl.marginWidth = 0;
gl.horizontalSpacing = 0;
gl.verticalSpacing = 0;
bottomRight.setLayout(gl);
// Stack parameters (manual/auto stack)
var stackParameters = new Composite(bottomRight, SWT.NONE);
gl = new GridLayout(5, false);
gl.marginHeight = 0;
gl.marginWidth = 50;
gl.horizontalSpacing = 0;
gl.verticalSpacing = 0;
stackParameters.setLayout(gl);
// Group stackTypeGroup = new Group(stackParameters, SWT.NONE);
// stackTypeGroup.setLayout(new RowLayout(SWT.HORIZONTAL));
stackModeLabel = new Label(stackParameters, SWT.NONE);
stackModeLabel.setText("Stack mode: ");
advanceModeCombo = new Combo(stackParameters, SWT.DROP_DOWN | SWT.READ_ONLY);
var items = new String[] { "Manual", "Automatic" };
advanceModeCombo.setItems(items);
advanceModeCombo.select(0);
autoOptionsCombo = new Combo(stackParameters, SWT.DROP_DOWN | SWT.READ_ONLY);
var items2 = new String[] { "AFAP (no delay)", "Fixed Delay", "Stack Delay" };
autoOptionsCombo.setItems(items2);
autoOptionsCombo.select(0);
autoOptionsCombo.setVisible(false);
fixDelaySpinner = new Spinner(stackParameters, SWT.BORDER);
fixDelaySpinner.setMinimum(0);
fixDelaySpinner.setMaximum(Integer.MAX_VALUE);
fixDelaySpinner.setSelection(200);
fixDelaySpinner.setIncrement(1);
fixDelaySpinner.setPageIncrement(100);
fixDelaySpinner.setVisible(false);
fixDelaySpinner.addListener(SWT.Selection, evt -> {
var stack = CommandStack.getInstance();
stack.fixDelayMs = fixDelaySpinner.getSelection();
});
var labelUnit = new Label(stackParameters, SWT.NONE);
labelUnit.setText("ms");
labelUnit.setVisible(false);
advanceModeCombo.addListener(SWT.Selection, evt -> {
var stack = CommandStack.getInstance();
var index = advanceModeCombo.getSelectionIndex();
if (index == StackMode.MANUAL.index()) {
// Manual
stack.stackMode = StackMode.MANUAL;
autoOptionsCombo.setVisible(false);
fixDelaySpinner.setVisible(false);
labelUnit.setVisible(false);
commandTableViewer.hideDelayColumn();
} else {
// Automatic
stack.stackMode = StackMode.AUTOMATIC;
autoOptionsCombo.setVisible(true);
if (autoOptionsCombo.getSelectionIndex() == AutoMode.FIX_DELAY.index()) {
// fix delay
fixDelaySpinner.setVisible(true);
labelUnit.setVisible(true);
commandTableViewer.hideDelayColumn();
} else if (autoOptionsCombo.getSelectionIndex() == AutoMode.STACK_DELAYS.index()) {
// stack delays
fixDelaySpinner.setVisible(false);
labelUnit.setVisible(false);
commandTableViewer.showDelayColumn();
} else {
// afap
fixDelaySpinner.setVisible(false);
labelUnit.setVisible(false);
commandTableViewer.hideDelayColumn();
}
}
// disarm the stack
issueButton.setEnabled(false);
armButton.setSelection(false);
stack.disarmArmed();
refreshState();
});
autoOptionsCombo.addListener(SWT.Selection, evt -> {
var stack = CommandStack.getInstance();
if (stack.stackMode == StackMode.AUTOMATIC) {
if (autoOptionsCombo.getSelectionIndex() == AutoMode.FIX_DELAY.index()) {
// fix delay
fixDelaySpinner.setVisible(true);
labelUnit.setVisible(true);
commandTableViewer.hideDelayColumn();
} else if (autoOptionsCombo.getSelectionIndex() == AutoMode.STACK_DELAYS.index()) {
// stack delay
fixDelaySpinner.setVisible(false);
labelUnit.setVisible(false);
commandTableViewer.showDelayColumn();
} else if (autoOptionsCombo.getSelectionIndex() == AutoMode.AFAP.index()) {
// fix delay
fixDelaySpinner.setVisible(false);
labelUnit.setVisible(false);
commandTableViewer.hideDelayColumn();
}
} else {
// manual mode
fixDelaySpinner.setVisible(false);
labelUnit.setVisible(false);
commandTableViewer.hideDelayColumn();
}
if (autoOptionsCombo.getSelectionIndex() == AutoMode.FIX_DELAY.index()) {
stack.autoMode = AutoMode.FIX_DELAY;
} else if (autoOptionsCombo.getSelectionIndex() == AutoMode.STACK_DELAYS.index()) {
stack.autoMode = AutoMode.STACK_DELAYS;
} else {
stack.autoMode = AutoMode.AFAP;
}
});
armButton = new Button(bottomRight, SWT.TOGGLE);
armButton.setText("1. Arm");
armButton.setToolTipText("Arm the selected command");
armButton.setEnabled(false);
armButton.addListener(SWT.Selection, evt -> {
var stack = CommandStack.getInstance();
if (armButton.getSelection()) {
var commandService = getViewSite().getService(ICommandService.class);
var evaluationService = getViewSite().getService(IEvaluationService.class);
if (stack.stackMode == StackMode.AUTOMATIC) {
// automatic stack, arm all commands
var cmd = commandService.getCommand("org.yamcs.studio.commanding.stack.armAll");
try {
cmd.executeWithChecks(new ExecutionEvent(cmd, new HashMap<String, String>(), null, evaluationService.getCurrentState()));
} catch (Exception e) {
log.log(Level.SEVERE, "Could not execute command", e);
}
} else {
// manual stack, individual arm
var cmd = commandService.getCommand("org.yamcs.studio.commanding.stack.arm");
try {
cmd.executeWithChecks(new ExecutionEvent(cmd, new HashMap<String, String>(), null, evaluationService.getCurrentState()));
} catch (Exception e) {
log.log(Level.SEVERE, "Could not execute command", e);
}
}
} else {
if (stack.getActiveCommand() != null && stack.getActiveCommand().isArmed()) {
stack.getActiveCommand().setStackedState(StackedState.DISARMED);
clearArm();
refreshState();
}
}
});
issueButton = new Button(bottomRight, SWT.NONE);
issueButton.setText("2. Issue");
issueButton.setToolTipText("Issue the selected command");
issueButton.setEnabled(false);
issueButton.addListener(SWT.Selection, evt -> {
var stack = CommandStack.getInstance();
var commandService = getViewSite().getService(ICommandService.class);
var evaluationService = getViewSite().getService(IEvaluationService.class);
org.eclipse.core.commands.Command cmd = null;
if (stack.stackMode == StackMode.AUTOMATIC) {
// automatic stack - issue all commands
cmd = commandService.getCommand("org.yamcs.studio.commanding.stack.issueAll");
} else {
// manual stack - issue one command
cmd = commandService.getCommand("org.yamcs.studio.commanding.stack.issue");
}
try {
cmd.executeWithChecks(new ExecutionEvent(cmd, new HashMap<String, String>(), null, evaluationService.getCurrentState()));
} catch (Exception e) {
log.log(Level.SEVERE, "Could not execute command", e);
}
});
commandTableViewer.addSelectionChangedListener(evt -> {
var sel = (IStructuredSelection) evt.getSelection();
updateMessagePanel(sel);
var stack = CommandStack.getInstance();
armButton.setSelection(false);
stack.disarmArmed();
if (sel.isEmpty() || !stack.isValid() || !sel.getFirstElement().equals(stack.getActiveCommand())) {
armButton.setEnabled(false);
issueButton.setEnabled(false);
} else if (stack.hasRemaining() && YamcsPlugin.hasAnyObjectPrivilege("Command")) {
armButton.setEnabled(true);
}
refreshState();
});
getViewSite().setSelectionProvider(commandTableViewer);
// Set up connection state, and listen to changes
connectionStateProvider = RCPUtils.findSourceProvider(getViewSite(), ConnectionStateProvider.STATE_KEY_CONNECTED, ConnectionStateProvider.class);
connectionStateProvider.addSourceProviderListener(sourceProviderListener);
// Add the popup menu for pasting commands
addPopupMenu();
// Set initial state
refreshState();
YamcsPlugin.addListener(this);
}
use of org.eclipse.jface.layout.TableColumnLayout in project yamcs-studio by yamcs.
the class ConnectionsDialog method createServerPanel.
private Composite createServerPanel(Composite parent, ResourceManager resourceManager) {
var serverPanel = new Composite(parent, SWT.NONE);
var gd = new GridData(GridData.FILL_BOTH);
serverPanel.setLayoutData(gd);
var tcl = new TableColumnLayout();
serverPanel.setLayout(tcl);
var serverImage = resourceManager.createImage(getImageDescriptor(ConnectionsDialog.class, "icons/obj16/server.gif"));
connViewer = new TableViewer(serverPanel, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
connViewer.getTable().setHeaderVisible(true);
connViewer.getTable().setLinesVisible(true);
var urlColumn = new TableViewerColumn(connViewer, SWT.NONE);
urlColumn.getColumn().setText("Server URL");
urlColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
return serverImage;
}
@Override
public String getText(Object element) {
var conf = (YamcsConfiguration) element;
return conf.getURL();
}
});
tcl.setColumnData(urlColumn.getColumn(), new ColumnPixelData(200));
var instanceColumn = new TableViewerColumn(connViewer, SWT.NONE);
instanceColumn.getColumn().setText("Instance");
instanceColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var conf = (YamcsConfiguration) element;
return conf.getInstance();
}
});
tcl.setColumnData(instanceColumn.getColumn(), new ColumnPixelData(90));
var userColumn = new TableViewerColumn(connViewer, SWT.NONE);
userColumn.getColumn().setText("User");
userColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var conf = (YamcsConfiguration) element;
if (conf.getAuthType() != AuthType.KERBEROS) {
return conf.getUser();
} else {
return null;
}
}
});
tcl.setColumnData(userColumn.getColumn(), new ColumnPixelData(90));
var nameColumn = new TableViewerColumn(connViewer, SWT.NONE);
nameColumn.getColumn().setText("Comment");
nameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var conf = (YamcsConfiguration) element;
return conf.getComment();
}
});
tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(200));
IContentProvider contentProvider = (IStructuredContentProvider) inputElement -> connections.toArray();
connViewer.setContentProvider(contentProvider);
connViewer.setInput(contentProvider);
connViewer.addSelectionChangedListener(evt -> {
var sel = (IStructuredSelection) evt.getSelection();
if (sel.getFirstElement() != null) {
var conf = (YamcsConfiguration) sel.getFirstElement();
yamcsInstanceText.setText(forceString(conf.getInstance()));
yamcsURLText.setText(forceString(conf.getURL()));
// / caCertFileText.setText(forceString(conf.getCaCertFile()));
commentText.setText(forceString(conf.getComment()));
var authType = (conf.getAuthType() == null) ? AuthType.STANDARD : conf.getAuthType();
if (authType == AuthType.STANDARD) {
authTypeCombo.select(0);
yamcsUserText.setText(forceString(conf.getUser()));
} else if (authType == AuthType.KERBEROS) {
authTypeCombo.select(1);
yamcsUserText.setText("");
} else {
throw new IllegalArgumentException("Unexpected auth type " + authType);
}
updateState();
}
});
connViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
var c1 = (YamcsConfiguration) o1;
var c2 = (YamcsConfiguration) o2;
if (c1.getURL() != null && c2.getURL() != null) {
return c1.getURL().compareTo(c2.getURL());
} else {
return 0;
}
}
});
return serverPanel;
}
use of org.eclipse.jface.layout.TableColumnLayout in project tbd-studio-se by Talend.
the class HadoopContextConfConfigDialog method createTable.
private Composite createTable(Composite parent) {
Composite tableComposite = new Composite(parent, SWT.NONE);
tableComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
TableColumnLayout tableColumnLayout = new TableColumnLayout();
tableComposite.setLayout(tableColumnLayout);
viewer = new TableViewer(tableComposite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
viewer.setContentProvider(new ViewerContentProvider());
table = viewer.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableViewerColumn contextColumn = createTableViewerColumn(Messages.getString("HadoopContextConfConfigDialog.table.contextColumn"), // $NON-NLS-1$
0);
contextColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Map.Entry<String, String> entry = (Map.Entry<String, String>) element;
return entry.getKey();
}
});
tableColumnLayout.setColumnData(contextColumn.getColumn(), new ColumnWeightData(35, 80, true));
TableViewerColumn jarNameColumn = createTableViewerColumn(Messages.getString("HadoopContextConfConfigDialog.table.jarNameColumn"), // $NON-NLS-1$
1);
jarNameColumn.setEditingSupport(new JarNameEditingSupport(viewer));
jarNameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Map.Entry<String, String> entry = (Map.Entry<String, String>) element;
return entry.getValue();
}
});
tableColumnLayout.setColumnData(jarNameColumn.getColumn(), new ColumnWeightData(65, 120, true));
viewer.setInput(context2Jar);
return tableComposite;
}
use of org.eclipse.jface.layout.TableColumnLayout 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.layout.TableColumnLayout in project hale by halestudio.
the class ClassificationMappingParameterPage method createManualTabControl.
private Control createManualTabControl(Composite tabParent) {
// TODO load occurring value sources
Composite tabContent = new Composite(tabParent, SWT.NONE);
tabContent.setLayout(new GridLayout(1, true));
ToolBar toolBar = new ToolBar(tabContent, SWT.NONE);
toolBar.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
Composite tableContainer = new Composite(tabContent, SWT.NONE);
tableContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
TableColumnLayout layout = new TableColumnLayout();
tableContainer.setLayout(layout);
tableViewer = new TableViewer(tableContainer, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
tableViewer.getTable().setLinesVisible(true);
tableViewer.getTable().setHeaderVisible(true);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
TableViewerColumn sourceColumn = new TableViewerColumn(tableViewer, SWT.NONE);
sourceColumn.getColumn().setText("Source value");
layout.setColumnData(sourceColumn.getColumn(), new ColumnWeightData(1));
sourceColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
@SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) element;
return entry.getKey().getStringRepresentation();
}
});
TableViewerColumn targetColumn = new TableViewerColumn(tableViewer, SWT.NONE);
targetColumn.getColumn().setText("Target value");
layout.setColumnData(targetColumn.getColumn(), new ColumnWeightData(1));
targetColumn.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
@SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) cell.getElement();
if (entry.getValue() == null) {
StyledString styledString = new StyledString("(unmapped)", StyledString.DECORATIONS_STYLER);
cell.setText(styledString.getString());
cell.setStyleRanges(styledString.getStyleRanges());
} else {
cell.setText(entry.getValue().getStringRepresentation());
cell.setStyleRanges(null);
}
super.update(cell);
}
});
tableViewer.setInput(lookupTable.entrySet());
tableViewer.getTable().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
ViewerCell cell = tableViewer.getCell(new Point(e.x, e.y));
if (cell != null) {
@SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) cell.getElement();
Value oldValue;
Value newValue;
if (cell.getColumnIndex() == 0) {
oldValue = entry.getKey();
newValue = selectValue(sourceProperty, sourceEntity, "Edit source value", "Enter a new source value", oldValue.getStringRepresentation());
} else {
oldValue = entry.getValue();
String initialValue = oldValue == null ? null : oldValue.getStringRepresentation();
newValue = selectValue(targetProperty, targetEntity, "Edit target value", "Enter a target value", initialValue);
}
if (newValue == null)
return;
if (cell.getColumnIndex() == 0) {
if (!newValue.equals(oldValue) && lookupTable.containsKey(newValue)) {
showDuplicateSourceWarning(newValue.getStringRepresentation());
} else {
lookupTable.put(newValue, entry.getValue());
lookupTable.remove(oldValue);
tableViewer.refresh();
}
} else {
entry.setValue(newValue);
tableViewer.update(entry, null);
}
}
}
});
final ToolItem valueAdd = new ToolItem(toolBar, SWT.PUSH);
final ToolItem fillValues = new ToolItem(toolBar, SWT.PUSH);
new ToolItem(toolBar, SWT.SEPARATOR);
final ToolItem loadButton = new ToolItem(toolBar, SWT.PUSH);
saveButton = new ToolItem(toolBar, SWT.PUSH);
new ToolItem(toolBar, SWT.SEPARATOR);
final ToolItem valueRemove = new ToolItem(toolBar, SWT.PUSH);
removeAllButton = new ToolItem(toolBar, SWT.PUSH);
valueAdd.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_ADD));
valueAdd.setToolTipText("Add source value");
valueAdd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Value newSource = selectValue(sourceProperty, sourceEntity, "Add source value", "Enter a new source value", null);
if (newSource != null) {
if (lookupTable.containsKey(newSource))
showDuplicateSourceWarning(newSource.getStringRepresentation());
else {
lookupTable.put(newSource, null);
removeAllButton.setEnabled(true);
saveButton.setEnabled(true);
tableViewer.refresh();
}
}
}
});
loadButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_OPEN));
loadButton.setToolTipText("Load classification from file");
loadButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
LookupTableLoadWizard wizard = new LookupTableLoadWizard();
LookupLoadAdvisor advisor = new LookupLoadAdvisor();
wizard.setAdvisor(advisor, null);
Shell shell = Display.getCurrent().getActiveShell();
HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
dialog.open();
if (advisor.getLookupTable() != null) {
lookupTable.putAll(advisor.getLookupTable().getTable().asMap());
tableViewer.refresh();
removeAllButton.setEnabled(!lookupTable.isEmpty());
saveButton.setEnabled(!lookupTable.isEmpty());
}
}
});
fillValues.setImage(fillValuesIcon);
fillValues.setToolTipText("Attempt to fill source values with enumerations and occurring values.");
fillValues.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// first try enumeration
Enumeration<?> enumeration = sourceProperty.getPropertyType().getConstraint(Enumeration.class);
if (enumeration.getValues() != null) {
addSourceValuesIfNew(enumeration.getValues());
}
// then try occurring values
if (!ovs.updateOccurringValues(sourceEntity)) {
// values already there or not possible
addOccurringSourceValues(ovs.getOccurringValues(sourceEntity));
} else {
// job is running, listener will be notified
}
removeAllButton.setEnabled(!lookupTable.isEmpty());
saveButton.setEnabled(!lookupTable.isEmpty());
}
});
saveButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_SAVE));
saveButton.setToolTipText("Save classification to file");
saveButton.setEnabled(false);
saveButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
LookupTableExportWizard wizard = new LookupTableExportWizard();
LookupExportAdvisor advisor = new LookupExportAdvisor(new LookupTableInfoImpl(new LookupTableImpl(lookupTable), "current", "not set"));
wizard.setAdvisor(advisor, null);
Shell shell = Display.getCurrent().getActiveShell();
HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
dialog.open();
}
});
valueRemove.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_REMOVE));
valueRemove.setToolTipText("Remove classification entry");
valueRemove.setEnabled(false);
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
valueRemove.setEnabled(!event.getSelection().isEmpty());
saveButton.setEnabled(!event.getSelection().isEmpty());
}
});
valueRemove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (tableViewer.getSelection().isEmpty())
return;
Object element = ((IStructuredSelection) tableViewer.getSelection()).getFirstElement();
@SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) element;
lookupTable.remove(entry.getKey());
tableViewer.refresh();
removeAllButton.setEnabled(!lookupTable.isEmpty());
saveButton.setEnabled(!lookupTable.isEmpty());
}
});
removeAllButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_TRASH));
removeAllButton.setEnabled(false);
removeAllButton.setToolTipText("Remove complete classification");
removeAllButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
lookupTable.clear();
tableViewer.refresh();
removeAllButton.setEnabled(false);
saveButton.setEnabled(false);
}
});
Label desc = new Label(tabContent, SWT.NONE);
desc.setText("Double click on a table cell to change its value.");
return tabContent;
}
Aggregations