use of org.eclipse.jface.viewers.IStructuredContentProvider 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.viewers.IStructuredContentProvider in project archi by archimatetool.
the class ExportToXMLPageMetadata method createControl.
@Override
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
container.setLayout(new GridLayout());
setControl(container);
Composite tableComp = new Composite(container, SWT.BORDER);
TableColumnLayout tableLayout = new TableColumnLayout();
tableComp.setLayout(tableLayout);
GridData gd = new GridData(GridData.FILL_BOTH);
// stop overstretch
gd.heightHint = 300;
tableComp.setLayoutData(gd);
fTableViewer = new TableViewer(tableComp, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
fTableViewer.getTable().setHeaderVisible(true);
fTableViewer.getTable().setLinesVisible(true);
fTableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
// Edit cell on double-click and Tab key traversal
TableViewerEditor.create(fTableViewer, new ColumnViewerEditorActivationStrategy(fTableViewer) {
@Override
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
return super.isEditorActivationEvent(event) || (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION);
}
}, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK | ColumnViewerEditor.KEYBOARD_ACTIVATION);
// Help ID on table
PlatformUI.getWorkbench().getHelpSystem().setHelp(container, HELP_ID);
// Content Provider
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 fNames.keySet().toArray();
}
});
// Columns
TableViewerColumn columnName = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
columnName.getColumn().setText(Messages.ExportToXMLPageMetadata_17);
tableLayout.setColumnData(columnName.getColumn(), new ColumnWeightData(20, true));
TableViewerColumn columnValue = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
columnValue.getColumn().setText(Messages.ExportToXMLPageMetadata_18);
tableLayout.setColumnData(columnValue.getColumn(), new ColumnWeightData(80, true));
columnValue.setEditingSupport(new ValueEditingSupport(fTableViewer));
fTableViewer.setLabelProvider(new LabelCellProvider());
for (int i = 0; i < dcNames.length; i++) {
IPreferenceStore store = XMLExchangePlugin.INSTANCE.getPreferenceStore();
String lastValue = store.getString(PREFS_LAST_VALUE + dcNames[i]);
fData.put(dcNames[i], lastValue);
}
fClearAllButton = new Button(container, SWT.PUSH);
fClearAllButton.setText(Messages.ExportToXMLPageMetadata_19);
fClearAllButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
for (Entry<String, String> entry : fData.entrySet()) {
// $NON-NLS-1$
entry.setValue("");
}
// $NON-NLS-1$
fTableViewer.setInput("");
}
});
// Table row bug on Yosemite https://bugs.eclipse.org/bugs/show_bug.cgi?id=446534
if (PlatformUtils.isMac() && System.getProperty("os.version").startsWith("10.10")) {
// $NON-NLS-1$ //$NON-NLS-2$
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
// $NON-NLS-1$
fTableViewer.setInput("");
}
});
} else {
// $NON-NLS-1$
fTableViewer.setInput("");
}
}
use of org.eclipse.jface.viewers.IStructuredContentProvider 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.viewers.IStructuredContentProvider 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.viewers.IStructuredContentProvider in project archi by archimatetool.
the class ViewpointSection method createControls.
@Override
protected void createControls(Composite parent) {
createLabel(parent, Messages.ViewpointSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
fComboViewer = new ComboViewer(new Combo(parent, SWT.READ_ONLY | SWT.BORDER));
fComboViewer.getCombo().setVisibleItemCount(12);
fComboViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
getWidgetFactory().adapt(fComboViewer.getControl(), true, true);
fComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (fIsRefreshing) {
// A Viewer will get a selectionChanged event when setting it
return;
}
IViewpoint viewPoint = (IViewpoint) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (viewPoint != null) {
CompoundCommand result = new CompoundCommand();
for (EObject diagramModel : getEObjects()) {
if (isAlive(diagramModel)) {
Command cmd = new EObjectFeatureCommand(Messages.ViewpointSection_1, diagramModel, IArchimatePackage.Literals.ARCHIMATE_DIAGRAM_MODEL__VIEWPOINT, viewPoint.getID());
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
}
});
fComboViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return ViewpointManager.INSTANCE.getAllViewpoints().toArray();
}
});
fComboViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ((IViewpoint) element).getName();
}
});
// $NON-NLS-1$
fComboViewer.setInput("");
// Help ID
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
Aggregations