use of com.archimatetool.model.IProperties in project archi by archimatetool.
the class CSVImporter method createPropertyFromRecord.
/**
* Create a Property from a given CSVRecord
*/
private void createPropertyFromRecord(CSVRecord csvRecord) throws CSVParseException {
// ID
String id = csvRecord.get(0);
if (!StringUtils.isSet(id)) {
throw new CSVParseException(Messages.CSVImporter_6);
} else {
checkIDForInvalidCharacters(id);
}
// Find referenced concept in newly created list
IProperties propertiesObject = newConcepts.get(id);
// Not found, check if it's referencing an existing element in the model
if (propertiesObject == null) {
EObject eObject = ArchimateModelUtils.getObjectByID(fModel, id);
if (eObject instanceof IProperties) {
propertiesObject = (IProperties) eObject;
}
}
// Not found, check if it's referencing the model
if (propertiesObject == null && id.equals(modelID)) {
propertiesObject = fModel;
}
// Not found at all
if (propertiesObject == null) {
throw new CSVParseException(Messages.CSVImporter_7 + id);
}
String key = normalise(csvRecord.get(1));
String value = normalise(csvRecord.get(2));
// Special properties for relationship attributes
if (INFLUENCE_STRENGTH.equals(key) && propertiesObject instanceof IInfluenceRelationship) {
storeUpdatedConceptFeature((IArchimateConcept) propertiesObject, IArchimatePackage.Literals.INFLUENCE_RELATIONSHIP__STRENGTH, value);
return;
} else if (ACCESS_TYPE.equals(key) && propertiesObject instanceof IAccessRelationship) {
int newvalue = ACCESS_TYPES.indexOf(value);
storeUpdatedConceptFeature((IArchimateConcept) propertiesObject, IArchimatePackage.Literals.ACCESS_RELATIONSHIP__ACCESS_TYPE, newvalue);
return;
}
// Is there already a property with this key?
IProperty property = getProperty(propertiesObject, key);
if (property != null) {
updatedProperties.put(property, value);
} else // No, create new one
{
property = IArchimateFactory.eINSTANCE.createProperty();
property.setKey(key);
property.setValue(value);
newProperties.put(property, propertiesObject);
}
}
use of com.archimatetool.model.IProperties 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 com.archimatetool.model.IProperties in project archi by archimatetool.
the class SearchFilter method matchesFilter.
/**
* Query whether element matches filter criteria when filtering on node/leaf elements
* @param element Any element, children will not be queried.
* @return
*/
public boolean matchesFilter(Object element) {
// EObject Type filter - do this first as the master filter
if (isObjectFiltered(element)) {
return false;
}
boolean textSearchResult = false;
boolean propertyKeyResult = false;
// Properties Key filter
if (isFilteringPropertyKeys() && element instanceof IProperties) {
for (IProperty property : ((IProperties) element).getProperties()) {
if (fPropertiesFilter.contains(property.getKey())) {
propertyKeyResult = true;
if (hasSearchText() && property.getValue().toLowerCase().contains(fSearchText.toLowerCase())) {
textSearchResult = true;
}
}
}
}
// If has search Text and no text found yet
if (hasSearchText()) {
// Name...
if (fFilterName && !textSearchResult && element instanceof INameable) {
String name = StringUtils.safeString(((INameable) element).getName());
if (name.toLowerCase().contains(fSearchText.toLowerCase())) {
textSearchResult = true;
}
}
// Then Documentation
if (fFilterDocumentation && !textSearchResult && element instanceof IDocumentable) {
String text = StringUtils.safeString(((IDocumentable) element).getDocumentation());
if (text.toLowerCase().contains(fSearchText.toLowerCase())) {
textSearchResult = true;
}
}
}
if ((hasSearchText())) {
return textSearchResult;
}
if (isFilteringPropertyKeys()) {
return propertyKeyResult;
}
return !isObjectFiltered(element);
}
Aggregations