Search in sources :

Example 1 with AlfrescoOutputException

use of org.talend.designer.alfrescooutput.util.AlfrescoOutputException in project tdi-studio-se by Talend.

the class AlfrescoOutputModelManager method addModel.

/**
     * Adds an Alfresco model definition file.
     * 
     * @param newModelFilePath
     * @throws AlfrescoOutputException if already added or error reading it
     */
public void addModel(String newModelFilePath) throws AlfrescoOutputException {
    if (this.availableModels.contains(newModelFilePath)) {
        //$NON-NLS-1$
        throw new AlfrescoOutputException(Messages.getString("AlfrescoOutputModelManager.alreadyAdded"));
    }
    this.availableModels.add(newModelFilePath);
    // parsing the model
    org.dom4j.Document modelDoc = null;
    try {
        modelDoc = new SAXReader().read(new File(newModelFilePath));
    } catch (DocumentException dex) {
        throw new AlfrescoOutputException(//$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("AlfrescoOutputModelManager.errorReadingModel") + " " + newModelFilePath, dex);
    }
    Element modelElt = modelDoc.getRootElement();
    //$NON-NLS-1$
    Element namespacesElt = modelElt.element("namespaces");
    if (namespacesElt != null) {
        //$NON-NLS-1$
        List<Element> namespaces = (List<Element>) namespacesElt.elements("namespace");
        HashMap<String, String> availablePrefixToNamespaceMapTmp = new HashMap<String, String>(3);
        for (Element namespace : namespaces) {
            //$NON-NLS-1$
            String namespacePrefix = namespace.attributeValue("prefix");
            if (this.availablePrefixToNamespaceMap.containsKey(namespacePrefix)) {
                throw new AlfrescoOutputException(//$NON-NLS-1$ //$NON-NLS-2$
                Messages.getString("AlfrescoOutputModelManager.prefixConflict") + " " + namespacePrefix + " " + //$NON-NLS-1$
                this.availablePrefixToNamespaceMap.get(namespacePrefix));
            }
            //$NON-NLS-1$
            String namespaceUri = namespace.attributeValue("uri");
            availablePrefixToNamespaceMapTmp.put(namespacePrefix, namespaceUri);
        }
        this.availablePrefixToNamespaceMap.putAll(availablePrefixToNamespaceMapTmp);
    }
    //$NON-NLS-1$
    Element typesElt = modelElt.element("types");
    if (typesElt != null) {
        //$NON-NLS-1$
        List<Element> types = (List<Element>) typesElt.elements("type");
        this.availableTypes.addAllAlfrescoModelElement(types);
    }
    //$NON-NLS-1$
    Element aspectsElt = modelElt.element("aspects");
    if (aspectsElt != null) {
        //$NON-NLS-1$
        List<Element> aspects = (List<Element>) aspectsElt.elements("aspect");
        this.availableAspects.addAllAlfrescoModelElement(aspects);
    }
}
Also used : HashMap(java.util.HashMap) SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) List(java.util.List) AlfrescoOutputException(org.talend.designer.alfrescooutput.util.AlfrescoOutputException) File(java.io.File)

Example 2 with AlfrescoOutputException

use of org.talend.designer.alfrescooutput.util.AlfrescoOutputException in project tdi-studio-se by Talend.

the class AlfrescoOutputManager method createUI.

/**
     * Checks the connections and creates the UI (a dialog actually)
     * 
     * @param parent
     * @return
     */
public AlfrescoModelDialog createUI(Composite parent) {
    IConnection inConn = null;
    AbstractNode connector = this.alfrescoOutputComponent;
    for (IConnection conn : connector.getIncomingConnections()) {
        if ((conn.getLineStyle().equals(EConnectionType.FLOW_MAIN)) || (conn.getLineStyle().equals(EConnectionType.FLOW_REF))) {
            inConn = conn;
            break;
        }
    }
    if (inConn != null) {
        if (!inConn.getMetadataTable().sameMetadataAs(connector.getMetadataList().get(0))) {
            MessageBox messageBox = new MessageBox(parent.getShell(), SWT.APPLICATION_MODAL | SWT.OK);
            //$NON-NLS-1$
            messageBox.setText(Messages.getString("AlfrescoOutputManager.schemaError.title"));
            //$NON-NLS-1$
            messageBox.setMessage(Messages.getString("AlfrescoOutputManager.schemaError.msg"));
            if (messageBox.open() == SWT.OK) {
                ((Shell) parent).close();
                return null;
            }
        }
    }
    // first load the model :
    try {
        // NB. or when modelManager is created
        modelManager.load();
    } catch (AlfrescoOutputException aoex) {
        MessageDialog.openError(new Shell(Display.getCurrent(), SWT.APPLICATION_MODAL), Messages.getString("AlfrescoOutputManager.failedLoadModel"), //$NON-NLS-1$
        aoex.getMessage());
        modelManager.clear();
    }
    // then create and open the model dialog :
    AlfrescoModelDialog alfrescoModelDialog = new AlfrescoModelDialog(parent.getShell(), this);
    alfrescoModelDialog.open();
    // NB. this dialog is non-blocking ; model save is done in its okPressed()
    return alfrescoModelDialog;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) AbstractNode(org.talend.core.model.process.AbstractNode) AlfrescoModelDialog(org.talend.designer.alfrescooutput.ui.AlfrescoModelDialog) IConnection(org.talend.core.model.process.IConnection) AlfrescoOutputException(org.talend.designer.alfrescooutput.util.AlfrescoOutputException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 3 with AlfrescoOutputException

use of org.talend.designer.alfrescooutput.util.AlfrescoOutputException in project tdi-studio-se by Talend.

the class AlfrescoModelDialog method createDialogArea.

/*
     * (non-Javadoc) Method declared on Dialog.
     */
protected Control createDialogArea(Composite parent) {
    // create composite
    alfrescoModelComposite = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout(3, false);
    layout.marginWidth = 12;
    alfrescoModelComposite.setLayout(layout);
    Label typeLabel = new Label(alfrescoModelComposite, SWT.NULL);
    GridData typeLabelGridData = new GridData(GridData.FILL_BOTH);
    typeLabelGridData.horizontalSpan = 3;
    typeLabel.setLayoutData(typeLabelGridData);
    //$NON-NLS-1$
    typeLabel.setText(Messages.getString("AlfrescoModelDialog.type"));
    typeCombo = new Combo(alfrescoModelComposite, SWT.NULL);
    GridData typeComboGridData = new GridData(GridData.FILL_BOTH);
    typeComboGridData.horizontalSpan = 3;
    typeCombo.setLayoutData(typeComboGridData);
    typeComboViewer = new ComboViewer(typeCombo);
    typeComboViewer.setContentProvider(new AlfrescoModelContentProvider() {

        public void alfrescoModelElementAdded(Element alfrescoModelElement) {
            typeComboViewer.add(alfrescoModelElement);
        }

        public void alfrescoModelElementRemoved(Element alfrescoModelElement) {
            typeComboViewer.remove(alfrescoModelElement);
        }
    });
    typeComboViewer.setLabelProvider(new AlfrescoModelLabelProvider());
    typeComboViewer.setInput(modelManager.getAvailableTypes());
    typeCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            ISelection selection = typeComboViewer.getSelection();
            if (selection instanceof IStructuredSelection) {
                Object selected = ((IStructuredSelection) selection).getFirstElement();
                if (selected instanceof Element) {
                    Element newType = (Element) selected;
                    if (modelManager.getType() == null || !newType.attributeValue("name").equals(modelManager.getType().attributeValue("name"))) {
                        //$NON-NLS-1$ //$NON-NLS-2$
                        modelManager.setType(newType);
                        AlfrescoModelDialog.this.updateMetadata();
                    }
                } else if (modelManager.getType() != null) {
                    modelManager.setType(null);
                    AlfrescoModelDialog.this.updateMetadata();
                }
            }
        }
    });
    Label aspectsLabel = new Label(alfrescoModelComposite, SWT.NULL);
    //$NON-NLS-1$
    aspectsLabel.setText(Messages.getString("AlfrescoModelDialog.aspects"));
    // filler
    new Composite(alfrescoModelComposite, SWT.NULL);
    Label availableAspectsLabel = new Label(alfrescoModelComposite, SWT.NULL);
    //$NON-NLS-1$
    availableAspectsLabel.setText(Messages.getString("AlfrescoModelDialog.availableAspects"));
    // create table
    aspectsTable = createAlfrescoModelElementTable(alfrescoModelComposite, modelManager.getAspects());
    GridData aspectsTableGridData = new GridData(GridData.FILL_BOTH);
    // aspectsTableGridData.grabExcessVerticalSpace = true;
    // aspectsTableGridData.grabExcessHorizontalSpace = true;
    aspectsTableGridData.heightHint = 300;
    aspectsTable.setLayoutData(aspectsTableGridData);
    Composite aspectButtonsComposite = new Composite(alfrescoModelComposite, SWT.NULL);
    GridLayout aspectButtonsLayout = new GridLayout();
    aspectButtonsLayout.marginWidth = 12;
    aspectButtonsComposite.setLayout(aspectButtonsLayout);
    Button addAspectButton = new Button(aspectButtonsComposite, SWT.NULL);
    //$NON-NLS-1$
    addAspectButton.setText("+");
    addAspectButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            TableItem[] selectedItems = availableAspectsTable.getSelection();
            for (int i = 0; i < selectedItems.length; i++) {
                Object selectedData = selectedItems[i].getData();
                if (selectedData instanceof Element) {
                    Element alfrescoModelElement = (Element) selectedData;
                    modelManager.addAspect(alfrescoModelElement);
                }
            }
            AlfrescoModelDialog.this.updateMetadata();
        }
    });
    Button removeAspectButton = new Button(aspectButtonsComposite, SWT.NULL);
    //$NON-NLS-1$
    removeAspectButton.setText("-");
    removeAspectButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            TableItem[] selectedItems = aspectsTable.getSelection();
            for (int i = 0; i < selectedItems.length; i++) {
                Object selectedData = selectedItems[i].getData();
                if (selectedData instanceof Element) {
                    Element alfrescoModelElement = (Element) selectedData;
                    modelManager.removeAspect(alfrescoModelElement);
                }
            }
            AlfrescoModelDialog.this.updateMetadata();
        }
    });
    // create table
    availableAspectsTable = createAlfrescoModelElementTable(alfrescoModelComposite, modelManager.getAvailableAspects());
    // RowData availableAspectsTableRowData = new RowData();
    // availableAspectsTableRowData.height = 200;
    // availableAspectsTable.setLayoutData(availableAspectsTableRowData);
    GridData availableAspectsTableGridData = new GridData(GridData.FILL_BOTH);
    // availableAspectsTableGridData.grabExcessVerticalSpace = true;
    // availableAspectsTableGridData.grabExcessHorizontalSpace = true;
    availableAspectsTableGridData.heightHint = 300;
    availableAspectsTable.setLayoutData(availableAspectsTableGridData);
    Label availableModelsLabel = new Label(alfrescoModelComposite, SWT.NULL);
    GridData availableModelsLabelGridData = new GridData(GridData.FILL_BOTH);
    availableModelsLabelGridData.horizontalSpan = 3;
    availableModelsLabel.setLayoutData(availableModelsLabelGridData);
    //$NON-NLS-1$
    availableModelsLabel.setText("Available Models");
    availableModelsList = new org.eclipse.swt.widgets.List(alfrescoModelComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData availableModelsListGridData = new GridData(GridData.FILL_BOTH);
    // availableModelsListGridData.grabExcessVerticalSpace = true;
    // availableModelsListGridData.grabExcessHorizontalSpace = true;
    availableModelsListGridData.horizontalSpan = 3;
    availableModelsListGridData.heightHint = 200;
    availableModelsList.setLayoutData(availableModelsListGridData);
    // init
    availableModelsList.setItems(new String[0]);
    Button addAvailableModelButton = new Button(alfrescoModelComposite, SWT.NULL);
    //$NON-NLS-1$
    addAvailableModelButton.setText(Messages.getString("AlfrescoModelDialog.add"));
    addAvailableModelButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            // opens a dialog to select the model file
            // shell
            FileDialog dialog = new FileDialog(alfrescoModelComposite.getShell(), SWT.OPEN);
            dialog.setFileName(AlfrescoModelDialog.this.chosenModelFilePath);
            //$NON-NLS-1$ //$NON-NLS-2$
            dialog.setFilterExtensions(new String[] { "*.xml", "*.*" });
            AlfrescoModelDialog.this.chosenModelFilePath = dialog.open();
            if (AlfrescoModelDialog.this.chosenModelFilePath == null) {
                return;
            }
            try {
                modelManager.addModel(AlfrescoModelDialog.this.chosenModelFilePath);
            } catch (AlfrescoOutputException aoex) {
                MessageDialog.openError(new Shell(Display.getCurrent(), SWT.APPLICATION_MODAL), Messages.getString("AlfrescoModelDialog.addModelFailed"), //$NON-NLS-1$
                aoex.getMessage());
                return;
            }
            // let's refresh the list :
            availableModelsList.setItems(modelManager.getAvailableModels().toArray(new String[0]));
            AlfrescoModelDialog.this.updateMetadata();
        }
    });
    Button removeAvailableModelButton = new Button(alfrescoModelComposite, SWT.NULL);
    //$NON-NLS-1$
    removeAvailableModelButton.setText(Messages.getString("AlfrescoModelDialog.remove"));
    removeAvailableModelButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            String[] selectedItems = availableModelsList.getSelection();
            for (String selectedItem : selectedItems) {
                try {
                    modelManager.removeModel(selectedItem);
                } catch (AlfrescoOutputException aoex) {
                    MessageDialog.openError(new Shell(Display.getCurrent(), SWT.APPLICATION_MODAL), Messages.getString("AlfrescoModelDialog.removeModelFailed"), //$NON-NLS-1$
                    aoex.getMessage());
                    return;
                }
                // let's refresh the list :
                availableModelsList.setItems(modelManager.getAvailableModels().toArray(new String[0]));
            }
            AlfrescoModelDialog.this.updateMetadata();
        }
    });
    // complete init (all other views are in sync with the model) :
    // type
    Element type = modelManager.getType();
    if (type != null) {
        this.typeComboViewer.setSelection(new StructuredSelection(type));
    } else {
        this.typeComboViewer.setSelection(new StructuredSelection());
    }
    // available models
    availableModelsList.setItems(modelManager.getAvailableModels().toArray(new String[0]));
    // chosen model filepath
    if (!this.modelManager.getAvailableModels().isEmpty()) {
        this.chosenModelFilePath = this.modelManager.getAvailableModels().get(this.modelManager.getAvailableModels().size() - 1);
    }
    applyDialogFont(alfrescoModelComposite);
    return alfrescoModelComposite;
}
Also used : Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) Element(org.dom4j.Element) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Combo(org.eclipse.swt.widgets.Combo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) ISelection(org.eclipse.jface.viewers.ISelection) Composite(org.eclipse.swt.widgets.Composite) AlfrescoOutputException(org.talend.designer.alfrescooutput.util.AlfrescoOutputException) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) ModifyEvent(org.eclipse.swt.events.ModifyEvent) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 4 with AlfrescoOutputException

use of org.talend.designer.alfrescooutput.util.AlfrescoOutputException in project tdi-studio-se by Talend.

the class AlfrescoOutputModelManager method removeModel.

/**
     * Removes an Alfresco model definition file.
     * 
     * @param oldModelFilePath
     * @throws AlfrescoOutputException
     */
public void removeModel(String oldModelFilePath) throws AlfrescoOutputException {
    if (!this.availableModels.remove(oldModelFilePath)) {
        //$NON-NLS-1$
        throw new AlfrescoOutputException(Messages.getString("AlfrescoOutputModelManager.notYetAdded"));
    }
    // parsing the model
    org.dom4j.Document modelDoc = null;
    try {
        modelDoc = new SAXReader().read(new File(oldModelFilePath));
    } catch (DocumentException dex) {
        throw new AlfrescoOutputException(//$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("AlfrescoOutputModelManager.errorReadingModel") + " " + oldModelFilePath, dex);
    }
    Element modelElt = modelDoc.getRootElement();
    //$NON-NLS-1$
    Element namespacesElt = modelElt.element("namespaces");
    if (namespacesElt != null) {
        //$NON-NLS-1$
        List<Element> namespaces = (List<Element>) namespacesElt.elements("namespace");
        for (Element namespace : namespaces) {
            //$NON-NLS-1$
            String namespacePrefix = namespace.attributeValue("prefix");
            this.availablePrefixToNamespaceMap.remove(namespacePrefix);
        }
    }
    //$NON-NLS-1$
    Element typesElt = modelElt.element("types");
    if (typesElt != null) {
        //$NON-NLS-1$
        List<Element> types = (List<Element>) typesElt.elements("type");
        this.availableTypes.removeAllAlfrescoModelElement(types);
    }
    //$NON-NLS-1$
    Element aspectsElt = modelElt.element("aspects");
    if (aspectsElt != null) {
        //$NON-NLS-1$
        List<Element> aspects = (List<Element>) aspectsElt.elements("aspect");
        this.availableAspects.removeAllAlfrescoModelElement(aspects);
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) List(java.util.List) AlfrescoOutputException(org.talend.designer.alfrescooutput.util.AlfrescoOutputException) File(java.io.File)

Aggregations

AlfrescoOutputException (org.talend.designer.alfrescooutput.util.AlfrescoOutputException)4 Element (org.dom4j.Element)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DocumentException (org.dom4j.DocumentException)2 SAXReader (org.dom4j.io.SAXReader)2 Shell (org.eclipse.swt.widgets.Shell)2 HashMap (java.util.HashMap)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1