use of org.eclipse.jface.layout.TableColumnLayout in project archi by archimatetool.
the class DiagramFiguresPreferencePage method createTable.
private void createTable(Composite parent) {
fTableViewer = new TableViewer(parent, SWT.BORDER | SWT.FULL_SELECTION);
TableColumnLayout layout = (TableColumnLayout) parent.getLayout();
TableViewerColumn column = new TableViewerColumn(fTableViewer, SWT.NONE);
layout.setColumnData(column.getColumn(), new ColumnWeightData(100, false));
// Fix row height
// This is definitely needed on some Linux versions where the row height is stuck at 17 for some reason
fTableViewer.getTable().addListener(SWT.MeasureItem, new Listener() {
@Override
public void handleEvent(Event event) {
event.height = itemHeight;
}
});
fTableViewer.getTable().addListener(SWT.PaintItem, new Listener() {
int alpha = 100;
@Override
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
if (item == null) {
return;
}
event.gc.setAntialias(SWT.ON);
int row = fTableViewer.getTable().indexOf(item);
ImageChoice ic = fChoices.get(row);
Image image1 = ic.getImage(0);
int x = (itemWidth / 2) - (image1.getBounds().width / 2);
event.gc.setAlpha(ic.chosenType == 0 ? 255 : alpha);
event.gc.drawImage(image1, event.x + x, event.y + (itemHeight - image1.getBounds().height) / 2);
Image image2 = ic.getImage(1);
x = itemWidth + ((itemWidth / 2) - (image2.getBounds().width / 2));
event.gc.setAlpha(ic.chosenType == 1 ? 255 : alpha);
event.gc.drawImage(image2, event.x + x, event.y + (itemHeight - image2.getBounds().height) / 2);
// Highlight rectangle
int highlight_x = ic.chosenType == 0 ? 20 : itemWidth + 20;
event.gc.setForeground(hiliteColor);
event.gc.setAlpha(255);
event.gc.setLineWidth(2);
event.gc.drawRoundRectangle(event.x + highlight_x, event.y + 2, event.x + itemWidth - 39, itemHeight - 3, 15, 15);
}
});
fTableViewer.getTable().addListener(SWT.EraseItem, new Listener() {
@Override
public void handleEvent(Event event) {
// No selection highlighting
event.detail &= ~SWT.SELECTED;
event.detail &= ~SWT.HOT;
}
});
fTableViewer.getTable().addListener(SWT.MouseDown, new Listener() {
@Override
public void handleEvent(Event event) {
TableItem item = fTableViewer.getTable().getItem(new Point(event.x, event.y));
if (item == null) {
return;
}
int row = fTableViewer.getTable().indexOf(item);
ImageChoice ic = fChoices.get(row);
if (event.x < itemWidth) {
ic.chosenType = 0;
} else {
ic.chosenType = 1;
}
fTableViewer.refresh(ic);
}
});
fTableViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public Object[] getElements(Object inputElement) {
return ((List<?>) inputElement).toArray();
}
});
fTableViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return null;
}
});
}
use of org.eclipse.jface.layout.TableColumnLayout in project archi by archimatetool.
the class UsedInViewsSection method createTableControl.
private void createTableControl(Composite parent) {
createLabel(parent, Messages.UsedInViewsSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
// Table
Composite tableComp = createTableComposite(parent, SWT.NONE);
TableColumnLayout tableLayout = (TableColumnLayout) tableComp.getLayout();
fTableViewer = new TableViewer(tableComp, SWT.BORDER | SWT.FULL_SELECTION);
// Font
UIUtils.setFontFromPreferences(fTableViewer.getTable(), IPreferenceConstants.ANALYSIS_TABLE_FONT, true);
// Mac Silicon Item height
UIUtils.fixMacSiliconItemHeight(fTableViewer.getTable());
// Column
TableViewerColumn column = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
tableLayout.setColumnData(column.getColumn(), new ColumnWeightData(100, false));
// On Mac shows alternate table row colours
fTableViewer.getTable().setLinesVisible(true);
// Help ID
PlatformUI.getWorkbench().getHelpSystem().setHelp(fTableViewer.getTable(), HELP_ID);
fTableViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return DiagramModelUtils.findReferencedDiagramsForArchimateConcept((IArchimateConcept) inputElement).toArray();
}
});
fTableViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
IDiagramModel dm = (IDiagramModel) element;
// Display label according to ancestor folder's label expression, if present and preference is set
if (ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.USE_LABEL_EXPRESSIONS_IN_ANALYSIS_TABLE)) {
String expression = TextRenderer.getDefault().getFormatExpressionFromAncestorFolder(dm);
if (expression != null) {
String text = StringUtils.normaliseNewLineCharacters(TextRenderer.getDefault().renderWithExpression(dm, expression));
if (text != null) {
return text;
}
}
}
return dm.getName();
}
@Override
public Image getImage(Object element) {
return IArchiImages.ImageFactory.getImage(IArchiImages.ICON_DIAGRAM);
}
});
fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
if (!isAlive(fArchimateConcept)) {
return;
}
IDiagramModel diagramModel = (IDiagramModel) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (diagramModel != null) {
IDiagramModelEditor editor = EditorManager.openDiagramEditor(diagramModel, false);
if (editor != null) {
// Needs to be asyncExec to allow EditorPart to open if it is currently closed
getPart().getSite().getShell().getDisplay().asyncExec(() -> {
editor.selectObjects(new Object[] { fArchimateConcept });
});
}
}
}
});
fTableViewer.setComparator(new ViewerComparator());
}
use of org.eclipse.jface.layout.TableColumnLayout in project archi by archimatetool.
the class UsedInRelationshipsSection method createTableControl.
private void createTableControl(Composite parent) {
createLabel(parent, Messages.UsedInRelationshipsSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
// Table
Composite tableComp = createTableComposite(parent, SWT.NONE);
TableColumnLayout tableLayout = (TableColumnLayout) tableComp.getLayout();
fTableViewer = new TableViewer(tableComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
// Font
UIUtils.setFontFromPreferences(fTableViewer.getTable(), IPreferenceConstants.ANALYSIS_TABLE_FONT, true);
// Mac Silicon Item height
UIUtils.fixMacSiliconItemHeight(fTableViewer.getTable());
// Column
TableViewerColumn column = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
tableLayout.setColumnData(column.getColumn(), new ColumnWeightData(100, false));
// On Mac shows alternate table row colours
fTableViewer.getTable().setLinesVisible(true);
// Help ID
PlatformUI.getWorkbench().getHelpSystem().setHelp(fTableViewer.getTable(), HELP_ID);
fTableViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return ArchimateModelUtils.getAllRelationshipsForConcept((IArchimateConcept) inputElement).toArray();
}
});
fTableViewer.setLabelProvider(new UsedInRelationshipsTableLabelProvider());
fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
if (isAlive(fArchimateConcept)) {
Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
if (o instanceof IArchimateRelationship) {
IArchimateRelationship relation = (IArchimateRelationship) o;
ITreeModelView view = (ITreeModelView) ViewManager.findViewPart(ITreeModelView.ID);
if (view != null) {
view.getViewer().setSelection(new StructuredSelection(relation), true);
}
}
}
}
});
fTableViewer.setComparator(new ViewerComparator());
// DND
fTableViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new DragSourceListener() {
@Override
public void dragStart(DragSourceEvent event) {
// Drag started from the Table
LocalSelectionTransfer.getTransfer().setSelection(fTableViewer.getSelection());
event.doit = true;
}
@Override
public void dragSetData(DragSourceEvent event) {
// For consistency set the data to the selection even though
// the selection is provided by the LocalSelectionTransfer
// to the drop target adapter.
event.data = LocalSelectionTransfer.getTransfer().getSelection();
}
@Override
public void dragFinished(DragSourceEvent event) {
LocalSelectionTransfer.getTransfer().setSelection(null);
}
});
}
use of org.eclipse.jface.layout.TableColumnLayout in project archi by archimatetool.
the class TemplatesTableViewer method setColumns.
/**
* Set up the columns
*/
private void setColumns() {
Table table = getTable();
table.setHeaderVisible(false);
// Use layout from parent container
TableColumnLayout layout = (TableColumnLayout) getControl().getParent().getLayout();
TableViewerColumn column = new TableViewerColumn(this, SWT.NONE);
layout.setColumnData(column.getColumn(), new ColumnWeightData(100, false));
}
use of org.eclipse.jface.layout.TableColumnLayout in project archi by archimatetool.
the class NewModelFromTemplateWizardPage method createGroupsTableViewer.
/**
* Create a table
*/
protected TemplateGroupsTableViewer createGroupsTableViewer(Composite parent, String labelText, GridData gd) {
CLabel label = new CLabel(parent, SWT.NULL);
label.setText(labelText);
label.setImage(fTemplateManager.getMainImage());
Composite tableComp = new Composite(parent, SWT.NULL);
tableComp.setLayout(new TableColumnLayout());
tableComp.setLayoutData(gd);
final TemplateGroupsTableViewer tableViewer = new TemplateGroupsTableViewer(tableComp, SWT.NULL);
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
handleTableItemSelected(o);
deFocusTable(tableViewer);
}
});
return tableViewer;
}
Aggregations