Search in sources :

Example 16 with TreeObject

use of com.amalto.workbench.models.TreeObject in project tmdm-studio-se by Talend.

the class DataClusterComposite method getRealTreeParent.

private TreeParent getRealTreeParent() {
    TreeParent treeParent = null;
    TreeObject xObject = getXObject();
    if (xObject != null) {
        TreeParent serverRoot = xObject.getServerRoot();
        UserInfo user = serverRoot.getUser();
        String serverName = serverRoot.getName();
        String password = user.getPassword();
        String url = user.getServerUrl();
        String username = user.getUsername();
        final XtentisServerObjectsRetriever retriever = new XtentisServerObjectsRetriever(serverName, url, username, password);
        retriever.setRetriveWSObject(true);
        try {
            retriever.run(new NullProgressMonitor());
            // get the real server root as the treeParent
            treeParent = retriever.getServerRoot();
        } catch (InvocationTargetException e) {
            log.error(e.getMessage(), e);
        } catch (InterruptedException e) {
            log.error(e.getMessage(), e);
        }
    }
    return treeParent;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) XtentisServerObjectsRetriever(com.amalto.workbench.providers.XtentisServerObjectsRetriever) TreeParent(com.amalto.workbench.models.TreeParent) TreeObject(com.amalto.workbench.models.TreeObject) UserInfo(com.amalto.workbench.utils.UserInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 17 with TreeObject

use of com.amalto.workbench.models.TreeObject in project tmdm-studio-se by Talend.

the class DataClusterDialog method hookService.

private void hookService() {
    serverComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            refreshDataContainerCombo();
            MDMServerDef serverDef = getSelectedMdmServerDef();
            if (serverDef != oldServerDef) {
                oldServerDef = serverDef;
                clusterComposite.changeToServer(serverDef);
                changeWidgetColor(greyColor);
            }
            selectDefaultContainer();
        }
    });
    containerComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection ssel = (IStructuredSelection) containerComboViewer.getSelection();
            TreeObject dataContainer = (TreeObject) ssel.getFirstElement();
            boolean refreshed = clusterComposite.changeToDataContainer(dataContainer);
            if (refreshed) {
                changeWidgetColor(defaultColor);
            } else {
                changeWidgetColor(greyColor);
                containerComboViewer.setInput(dataContainers);
            }
            model = clusterComposite.getDataContainer();
        }
    });
    TableViewer resultsViewer = clusterComposite.getResultsViewer();
    resultsViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection structedSelection = (IStructuredSelection) event.getSelection();
            selected = (LineItem) structedSelection.getFirstElement();
            showInTextWidget(selected);
        }
    });
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TreeObject(com.amalto.workbench.models.TreeObject) LineItem(com.amalto.workbench.utils.LineItem) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer) MDMServerDef(com.amalto.workbench.utils.MDMServerDef)

Example 18 with TreeObject

use of com.amalto.workbench.models.TreeObject in project tmdm-studio-se by Talend.

the class DataClusterDialog method createFirstLine.

private Composite createFirstLine(Composite parent) {
    Composite firstLine = new Composite(parent, SWT.NONE);
    firstLine.setLayout(new GridLayout(4, false));
    Label serverLabel = new Label(firstLine, SWT.NONE);
    serverLabel.setText(Messages.DataClusterDialog_1);
    serverLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
    serverComboViewer = new ComboViewer(firstLine, SWT.DROP_DOWN | SWT.READ_ONLY);
    Combo combo = serverComboViewer.getCombo();
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    data.widthHint = 200;
    combo.setLayoutData(data);
    serverComboViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            MDMServerDef serverDef = (MDMServerDef) element;
            // $NON-NLS-1$ //$NON-NLS-2$;
            return serverDef.getName() + " (" + serverDef.getHost() + ")";
        }
    });
    serverComboViewer.setContentProvider(new ArrayContentProvider());
    serverComboViewer.setInput(getAllServerDefs());
    Label containerLabel = new Label(firstLine, SWT.NONE);
    containerLabel.setText(Messages.DataClusterDialog_2);
    containerLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
    containerComboViewer = new ComboViewer(firstLine, SWT.DROP_DOWN | SWT.READ_ONLY);
    Combo containerCombo = containerComboViewer.getCombo();
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    layoutData.widthHint = 200;
    containerCombo.setLayoutData(layoutData);
    containerComboViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            TreeObject treeObj = (TreeObject) element;
            return treeObj.getName();
        }
    });
    containerComboViewer.setContentProvider(new ArrayContentProvider());
    containerComboViewer.setInput(new TreeObject[0]);
    containerComboViewer.getCombo().setEnabled(false);
    return firstLine;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TreeObject(com.amalto.workbench.models.TreeObject) TreeObject(com.amalto.workbench.models.TreeObject) LabelProvider(org.eclipse.jface.viewers.LabelProvider) MDMServerDef(com.amalto.workbench.utils.MDMServerDef)

Example 19 with TreeObject

use of com.amalto.workbench.models.TreeObject in project tmdm-studio-se by Talend.

the class ImportItemsWizard method parses.

protected void parses(boolean importFromArchieve, String zipFilePath, IProgressMonitor monitor) {
    // init var for progressMonitor
    int total = 500, zipCount = 200, readCount = 100;
    int step = 1, interval = 1;
    // 
    monitor.beginTask(Messages.ImportItemsWizard_7, total);
    if (importFromArchieve) {
        checkUpExchangeImport(true);
        try {
            Util.unZipFile(zipFilePath, importFolder, zipCount, monitor);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    monitor.worked(zipCount);
    monitor.setTaskName(Messages.ImportItemsWizard_8);
    InputStreamReader reader = null;
    try {
        // $NON-NLS-1$//$NON-NLS-2$
        reader = new InputStreamReader(new FileInputStream(importFolder + "/exportitems.xml"), "UTF-8");
        final Exports exports = (Exports) Unmarshaller.unmarshal(Exports.class, reader);
        String[] orgSchemas = exports.getSchemas();
        int idx = 0;
        if (orgSchemas != null) {
            for (String orgSchema : orgSchemas) {
                String orgSchemaCpy = new String(orgSchema);
                for (Map.Entry<String, String> pair : ICoreConstants.rolesConvert.oldRoleToNewRoleMap.entrySet()) {
                    orgSchemaCpy = orgSchemaCpy.replaceAll(pair.getKey().toString(), pair.getValue().toString());
                }
                if (!orgSchemaCpy.equals(orgSchema)) {
                    orgSchemas[idx] = orgSchemaCpy;
                }
                idx++;
            }
        }
        try {
            LocalTreeObjectRepository.getInstance().makeUpDocWithImportCategory(orgSchemas, serverRoot);
        } catch (Exception e) {
        }
        // import autoincrement
        if (exports.getAutoIncrement() != null) {
            try {
                service.getAutoIncrement(new WSAutoIncrement(exports.getAutoIncrement()));
            } catch (Exception e) {
            }
        }
        // new server root
        final TreeParent reserverRoot = new TreeParent(serverRoot.getDisplayName(), null, TreeObject._SERVER_, serverRoot.getWsKey(), serverRoot.getWsObject());
        reserverRoot.setUser(serverRoot.getUser());
        // serverRoot=reserverRoot;
        TreeParent clusters = new TreeParent(EXtentisObjects.DataCluster.getDisplayName(), reserverRoot, TreeObject.DATA_CLUSTER, null, null);
        TreeParent models = new TreeParent(EXtentisObjects.DataMODEL.getDisplayName(), reserverRoot, TreeObject.DATA_MODEL, null, null);
        TreeParent menus = new TreeParent(EXtentisObjects.Menu.getDisplayName(), reserverRoot, TreeObject.MENU, null, null);
        TreeParent roles = new TreeParent(EXtentisObjects.Role.getDisplayName(), reserverRoot, TreeObject.ROLE, null, null);
        TreeParent eventManager = new TreeParent(EXtentisObjects.EventManagement.getDisplayName(), reserverRoot, TreeObject.EVENT_MANAGEMENT, null, null);
        TreeParent routingrules = new TreeParent(EXtentisObjects.RoutingRule.getDisplayName(), reserverRoot, TreeObject.ROUTING_RULE, null, null);
        TreeParent storeprocedures = new TreeParent(EXtentisObjects.StoredProcedure.getDisplayName(), reserverRoot, TreeObject.STORED_PROCEDURE, null, null);
        TreeParent transformers = new TreeParent(EXtentisObjects.Transformer.getDisplayName(), reserverRoot, TreeObject.TRANSFORMER, null, null);
        TreeParent pictures = new TreeParent(EXtentisObjects.PICTURESRESOURCE.getDisplayName(), reserverRoot, TreeObject.PICTURES_RESOURCE, null, null);
        // add by ymli
        TreeParent workflow = new TreeParent(EXtentisObjects.Workflow.getDisplayName(), reserverRoot, TreeObject.WORKFLOW, null, null);
        TreeParent views = new TreeParent(EXtentisObjects.View.getDisplayName(), reserverRoot, TreeObject.VIEW, null, null);
        reserverRoot.addChild(clusters);
        reserverRoot.addChild(models);
        reserverRoot.addChild(menus);
        reserverRoot.addChild(roles);
        reserverRoot.addChild(storeprocedures);
        eventManager.addChild(transformers);
        eventManager.addChild(routingrules);
        reserverRoot.addChild(eventManager);
        reserverRoot.addChild(pictures);
        reserverRoot.addChild(workflow);
        reserverRoot.addChild(views);
        monitor.worked(readCount);
        // caculate step and interval
        float val = (total - zipCount - readCount) / exports.getItems().length;
        if (val > 0) {
            interval = 1;
            step = Math.round(val);
        } else {
            step = 1;
            interval = Math.round(exports.getItems().length / (total - zipCount - readCount) + 0.5f);
        }
        // System.out.println("count:" + exports.getItems().length + "\tinterval:" + interval + "\tstep:" + step);
        monitor.setTaskName(Messages.ImportItemsWizard_9);
        // 
        int tmp = 1;
        for (TreeObject obj : exports.getItems()) {
            obj.setServerRoot(reserverRoot);
            switch(obj.getType()) {
                case TreeObject.DATA_CLUSTER:
                    clusters.addChild(obj);
                    break;
                case TreeObject.DATA_MODEL:
                    models.addChild(obj);
                    break;
                case TreeObject.MENU:
                    menus.addChild(obj);
                    break;
                case TreeObject.ROLE:
                    roles.addChild(obj);
                    break;
                case TreeObject.ROUTING_RULE:
                    routingrules.addChild(obj);
                    break;
                case TreeObject.STORED_PROCEDURE:
                    storeprocedures.addChild(obj);
                    break;
                case TreeObject.TRANSFORMER:
                    transformers.addChild(obj);
                    break;
                case TreeObject.PICTURES_RESOURCE:
                    pictures.addChild(obj);
                    break;
                case TreeObject.WORKFLOW_PROCESS:
                    workflow.addChild(obj);
                    break;
                case TreeObject.VIEW:
                    views.addChild(obj);
                    break;
                default:
                    if (obj.getItems() != null && obj.getItems().length > 0) {
                        for (int i = 0; i < obj.getItems().length; i++) {
                            if (obj.getItems()[i].split(Messages.ImportItemsWizard_10)[1] != null) {
                                dataClusterContent.put(obj.getItems()[i].split(Messages.ImportItemsWizard_11)[1], obj.getItems());
                            }
                        }
                    }
            }
            // update monitor
            if (interval == 1) {
                monitor.worked(step);
            } else {
                if (tmp >= interval) {
                    monitor.worked(step);
                    tmp = 1;
                } else {
                    tmp++;
                }
            }
        }
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                treeViewer.setRoot(reserverRoot);
                treeViewer.getViewer().setInput(null);
                treeViewer.setCheckItems(Arrays.asList(exports.getItems()));
                GridData gd = (GridData) treeViewer.getViewer().getControl().getLayoutData();
                gd.heightHint = 300;
                treeViewer.getViewer().getControl().getParent().layout(true);
                treeViewer.getViewer().getControl().getShell().layout(true);
                try {
                    Object[] checkNodes = treeViewer.getCheckNodes();
                    if (checkNodes != null) {
                        LocalTreeObjectRepository.getInstance().setOriginalXobjectsToImport((TreeObject[]) checkNodes);
                    }
                } catch (Exception e) {
                }
            }
        });
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    } finally {
        try {
            if (reader != null) {
                reader.close();
            }
        } catch (Exception e) {
        }
        monitor.done();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) WSAutoIncrement(com.amalto.workbench.webservices.WSAutoIncrement) TreeParent(com.amalto.workbench.models.TreeParent) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DocumentException(org.dom4j.DocumentException) FileInputStream(java.io.FileInputStream) GridData(org.eclipse.swt.layout.GridData) TreeObject(com.amalto.workbench.models.TreeObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 20 with TreeObject

use of com.amalto.workbench.models.TreeObject in project tmdm-studio-se by Talend.

the class ImportItemsWizard method closeOpenEditors.

private void closeOpenEditors() {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    int length = page.getEditors().length;
    String tabEndpointAddress = Messages.ImportItemsWizard_3;
    String unserName = null;
    int j = 0;
    for (int i = 0; i < length; i++) {
        IEditorPart part = page.getEditors()[i - j];
        if (part instanceof XObjectBrowser) {
            TreeObject obj = (TreeObject) ((XObjectBrowserInput) part.getEditorInput()).getModel();
            if (obj != null) {
                tabEndpointAddress = obj.getEndpointAddress();
                unserName = obj.getUsername();
            }
        } else if (part instanceof XObjectEditor) {
            TreeObject obj = (TreeObject) ((XObjectEditorInput) part.getEditorInput()).getModel();
            if (obj != null) {
                tabEndpointAddress = obj.getEndpointAddress();
                unserName = obj.getUsername();
            }
        }
        if (serverRoot != null) {
            if (serverRoot.getEndpointAddress().equals(tabEndpointAddress) && serverRoot.getUsername().equals(unserName)) {
                if (part.isDirty() && isSaveModifiedEditor(part.getTitle())) {
                    part.doSave(new NullProgressMonitor());
                }
                page.closeEditor(part, false);
                j++;
            }
        }
    }
}
Also used : XObjectBrowser(com.amalto.workbench.editors.XObjectBrowser) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) TreeObject(com.amalto.workbench.models.TreeObject) XObjectEditorInput(com.amalto.workbench.providers.XObjectEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) XObjectEditor(com.amalto.workbench.editors.XObjectEditor)

Aggregations

TreeObject (com.amalto.workbench.models.TreeObject)66 TreeParent (com.amalto.workbench.models.TreeParent)21 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 ArrayList (java.util.ArrayList)12 MDMServerObject (org.talend.mdm.repository.model.mdmserverobject.MDMServerObject)12 TMDMService (com.amalto.workbench.webservices.TMDMService)6 WSDataModel (com.amalto.workbench.webservices.WSDataModel)5 WSDataModelPK (com.amalto.workbench.webservices.WSDataModelPK)5 WSGetDataModel (com.amalto.workbench.webservices.WSGetDataModel)5 Document (org.dom4j.Document)5 Element (org.dom4j.Element)5 EObject (org.eclipse.emf.ecore.EObject)5 MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)5 WSDataClusterPK (com.amalto.workbench.webservices.WSDataClusterPK)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IAvailableModel (com.amalto.workbench.availablemodel.IAvailableModel)3 UserInfo (com.amalto.workbench.utils.UserInfo)3 WSDataCluster (com.amalto.workbench.webservices.WSDataCluster)3 WSDigest (com.amalto.workbench.webservices.WSDigest)3 WSDigestKey (com.amalto.workbench.webservices.WSDigestKey)3