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);
}
}
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;
}
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;
}
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);
}
}
Aggregations