Search in sources :

Example 1 with IProperties

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);
    }
}
Also used : IInfluenceRelationship(com.archimatetool.model.IInfluenceRelationship) IProperty(com.archimatetool.model.IProperty) EObject(org.eclipse.emf.ecore.EObject) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IProperties(com.archimatetool.model.IProperties) IAccessRelationship(com.archimatetool.model.IAccessRelationship) CSVParseException(com.archimatetool.csv.CSVParseException)

Example 2 with IProperties

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();
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) IMenuListener(org.eclipse.jface.action.IMenuListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) Listener(org.eclipse.swt.widgets.Listener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) TableItem(org.eclipse.swt.widgets.TableItem) TableViewer(org.eclipse.jface.viewers.TableViewer) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IProperties(com.archimatetool.model.IProperties) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ToolBarManager(org.eclipse.jface.action.ToolBarManager) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) UpdatingTableColumnLayout(com.archimatetool.editor.ui.components.UpdatingTableColumnLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IProperty(com.archimatetool.model.IProperty) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) Point(org.eclipse.swt.graphics.Point) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ToolBar(org.eclipse.swt.widgets.ToolBar) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) TableViewer(org.eclipse.jface.viewers.TableViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer)

Example 3 with IProperties

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);
}
Also used : IDocumentable(com.archimatetool.model.IDocumentable) IProperty(com.archimatetool.model.IProperty) INameable(com.archimatetool.model.INameable) IProperties(com.archimatetool.model.IProperties)

Aggregations

IProperties (com.archimatetool.model.IProperties)3 IProperty (com.archimatetool.model.IProperty)3 EObject (org.eclipse.emf.ecore.EObject)2 CSVParseException (com.archimatetool.csv.CSVParseException)1 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)1 EObjectNonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand)1 UpdatingTableColumnLayout (com.archimatetool.editor.ui.components.UpdatingTableColumnLayout)1 IAccessRelationship (com.archimatetool.model.IAccessRelationship)1 IArchimateConcept (com.archimatetool.model.IArchimateConcept)1 IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)1 IDocumentable (com.archimatetool.model.IDocumentable)1 IInfluenceRelationship (com.archimatetool.model.IInfluenceRelationship)1 INameable (com.archimatetool.model.INameable)1 Command (org.eclipse.gef.commands.Command)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1 Action (org.eclipse.jface.action.Action)1 IAction (org.eclipse.jface.action.IAction)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1 ToolBarManager (org.eclipse.jface.action.ToolBarManager)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1