use of com.archimatetool.model.IProperty in project archi by archimatetool.
the class UserPropertiesSection method getAllUniquePropertyValuesForKeyForModel.
/**
* @return All unique Property Values for an entire model (sorted)
*/
private String[] getAllUniquePropertyValuesForKeyForModel(String key) {
IArchimateModel model = getArchimateModel();
Set<String> set = new HashSet<String>();
for (Iterator<EObject> iter = model.eAllContents(); iter.hasNext(); ) {
EObject element = iter.next();
if (element instanceof IProperty) {
IProperty p = (IProperty) element;
if (p.getKey().equals(key)) {
String value = p.getValue();
if (StringUtils.isSetAfterTrim(value)) {
set.add(value);
}
}
}
}
String[] items = set.toArray(new String[set.size()]);
Arrays.sort(items, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return s1.compareToIgnoreCase(s2);
}
});
return items;
}
use of com.archimatetool.model.IProperty 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);
// Font
UIUtils.setFontFromPreferences(fTableViewer.getTable(), IPreferenceConstants.PROPERTIES_TABLE_FONT, true);
// Mac Silicon Item height
UIUtils.fixMacSiliconItemHeight(fTableViewer.getTable());
// Edit cell on double-click and add 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);
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 ColumnWeightData(3, false));
columnBlank.getColumn().setWidth(38);
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(77, true));
columnValue.setEditingSupport(new ValueEditingSupport(fTableViewer));
// 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 ((IProperties) inputElement).getProperties().toArray();
}
});
// Label Provider
fTableViewer.setLabelProvider(new LabelCellProvider());
// Enable tooltips
ColumnViewerToolTipSupport.enableFor(fTableViewer);
// Toolbar
ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.VERTICAL);
getWidgetFactory().adapt(toolBar);
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)) {
// complete any current editing
fTableViewer.applyEditorValue();
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((e) -> {
fActionRemoveProperty.setEnabled(!e.getSelection().isEmpty());
});
/*
* Table Double-click
*/
fTableViewer.getTable().addListener(SWT.MouseDoubleClick, (e) -> {
// Get Table item
Point pt = new Point(e.x, e.y);
TableItem item = fTableViewer.getTable().getItem(pt);
// Double-click into empty table creates new Property
if (item == null) {
fActionNewProperty.run();
} else // Double-clicked in column 0 with item
if (item.getData() instanceof IProperty) {
Rectangle rect = item.getBounds(0);
if (rect.contains(pt)) {
handleDoubleClick((IProperty) item.getData());
}
}
});
/*
* Edit table row on key press
*/
fTableViewer.getTable().addKeyListener(KeyListener.keyPressedAdapter(e -> {
if (e.keyCode == SWT.CR) {
Object selected = fTableViewer.getStructuredSelection().getFirstElement();
if (selected != null) {
fTableViewer.editElement(selected, 1);
}
}
}));
hookContextMenu();
}
use of com.archimatetool.model.IProperty in project archi by archimatetool.
the class UserPropertiesSection method getAllUniquePropertyKeysForModel.
/**
* @return All unique Property Keys for an entire model (sorted)
*/
private String[] getAllUniquePropertyKeysForModel() {
IArchimateModel model = getArchimateModel();
Set<String> set = new HashSet<String>();
for (Iterator<EObject> iter = model.eAllContents(); iter.hasNext(); ) {
EObject element = iter.next();
if (element instanceof IProperty) {
String key = ((IProperty) element).getKey();
if (StringUtils.isSetAfterTrim(key)) {
set.add(key);
}
}
}
String[] items = set.toArray(new String[set.size()]);
Arrays.sort(items, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return s1.compareToIgnoreCase(s2);
}
});
return items;
}
use of com.archimatetool.model.IProperty in project archi by archimatetool.
the class UserPropertiesSection method movePropertiesToIndex.
private void movePropertiesToIndex(List<IProperty> propertiesToMove, int index) {
EList<IProperty> properties = fPropertiesElement.getProperties();
// Sanity check
if (index < 0) {
index = 0;
}
if (index > properties.size()) {
index = properties.size();
}
CompoundCommand compoundCmd = new CompoundCommand(Messages.UserPropertiesSection_8);
for (IProperty property : propertiesToMove) {
int oldIndex = properties.indexOf(property);
if (index > oldIndex) {
index--;
}
if (index == oldIndex) {
break;
}
compoundCmd.add(new MovePropertyCommand(properties, property, index));
index++;
}
executeCommand(compoundCmd.unwrap());
}
use of com.archimatetool.model.IProperty in project archi by archimatetool.
the class UserPropertiesSection method doDropOperation.
@SuppressWarnings("unchecked")
private void doDropOperation(DropTargetEvent event) {
if (!LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)) {
return;
}
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection == null || selection.isEmpty()) {
return;
}
// Determine the index position of the drop
int index = getDropTargetPosition(event);
// Valid position?
List<?> list = ((IStructuredSelection) selection).toList();
for (Object o : list) {
IProperty property = (IProperty) o;
int movedIndex = fPropertiesElement.getProperties().indexOf(property);
if (movedIndex == index || (movedIndex + 1) == index) {
return;
}
}
movePropertiesToIndex((List<IProperty>) list, index);
}
Aggregations