Search in sources :

Example 1 with IMultiPageTalendEditor

use of org.talend.designer.core.IMultiPageTalendEditor in project tdi-studio-se by Talend.

the class AbstractElementPropertySectionController method init.

/**
     * DOC yzhang Comment method "init".
     *
     * Configuration for necessay parameters from class DynamicTabbedPropertiesSection.
     */
public void init(IDynamicProperty dp) {
    this.dynamicProperty = dp;
    hashCurControls = dp.getHashCurControls();
    elem = dp.getElement();
    Object obj = dp.getPart();
    if (obj instanceof IMultiPageTalendEditor) {
        part = (IMultiPageTalendEditor) obj;
    } else {
    // throw new RuntimeException("Type IMultiPageTalendEditor is requried.");
    }
    section = dp.getSection();
    composite = dp.getComposite();
    editionControlHelper = new EditionControlHelper();
// elem.addPropertyChangeListener(this);
}
Also used : IMultiPageTalendEditor(org.talend.designer.core.IMultiPageTalendEditor) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 2 with IMultiPageTalendEditor

use of org.talend.designer.core.IMultiPageTalendEditor in project tdi-studio-se by Talend.

the class MavenVersionManagementProjectSettingPage method updateItemsVersion.

protected void updateItemsVersion() {
    List<ItemVersionObject> JobsOpenedInEditor = new ArrayList<ItemVersionObject>();
    List<ItemVersionObject> closedJobs = new ArrayList<ItemVersionObject>();
    boolean hasJobOpenedInEditor = false;
    StringBuilder builder = new StringBuilder();
    for (ItemVersionObject object : checkedObjects) {
        if (RepositoryManager.isOpenedItemInEditor(object.getRepositoryNode().getObject())) {
            hasJobOpenedInEditor = true;
            JobsOpenedInEditor.add(object);
            //$NON-NLS-1$
            builder.append(object.getRepositoryNode().getObject().getLabel() + ", ");
        } else {
            closedJobs.add(object);
        }
    }
    if (builder.length() > 0) {
        builder.delete(builder.length() - 2, builder.length());
    }
    if (hasJobOpenedInEditor) {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), //$NON-NLS-1$
        Messages.getString("VersionManagementDialog.WarningTitle2"), //$NON-NLS-1$
        Messages.getString("VersionManagementDialog.openedInEditorMessage", builder.toString()));
        IWorkbenchWindow workBench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (workBench != null) {
            IWorkbenchPage page = workBench.getActivePage();
            IEditorReference[] editorRefs = page.getEditorReferences();
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
                IDesignerCoreUIService service = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
                if (service != null) {
                    for (IEditorReference editorRef : editorRefs) {
                        IEditorPart editor = editorRef.getEditor(false);
                        if (editor instanceof IMultiPageTalendEditor) {
                            IProcess2 process = ((IMultiPageTalendEditor) editor).getProcess();
                            String version = null;
                            for (ItemVersionObject object : JobsOpenedInEditor) {
                                if (object.getItem().getProperty().getId().equals(process.getId())) {
                                    version = object.getNewVersion();
                                    break;
                                }
                            }
                            if (version != null) {
                                String jobDefaultVersion = MavenVersionUtils.getDefaultVersion(process.getProperty().getVersion());
                                if (version.equals(jobDefaultVersion)) {
                                    // if default, set null to remove key from property.
                                    version = null;
                                }
                                Command command = service.crateMavenDeploymentValueChangeCommand(process, MavenConstants.NAME_USER_VERSION, version);
                                if (process instanceof IGEFProcess) {
                                    service.executeCommand((IGEFProcess) process, command);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(final IProgressMonitor monitor) throws CoreException {
            RepositoryWorkUnit<Object> rwu = new //$NON-NLS-1$
            RepositoryWorkUnit<Object>(//$NON-NLS-1$
            project, //$NON-NLS-1$
            "Update items Maven version") {

                @Override
                protected void run() throws LoginException, PersistenceException {
                    //$NON-NLS-1$
                    monitor.beginTask("Update items Maven version", closedJobs.size());
                    for (ItemVersionObject object : closedJobs) {
                        final Item item = object.getItem();
                        Property itemProperty = item.getProperty();
                        MavenVersionUtils.setItemMavenVersion(itemProperty, object.getNewVersion());
                        monitor.subTask(itemProperty.getLabel());
                        FACTORY.save(project, itemProperty);
                        monitor.worked(1);
                    }
                    try {
                        FACTORY.saveProject(project);
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                }
            };
            rwu.setAvoidUnloadResources(true);
            rwu.executeRun();
            monitor.done();
        }
    };
    IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            try {
                ISchedulingRule schedulingRule = workspace.getRoot();
                // the update the project files need to be done in the workspace runnable to avoid all notification
                // of changes before the end of the modifications.
                workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
                ExceptionHandler.process(e);
            }
        }
    };
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(false, false, iRunnableWithProgress);
    } catch (InvocationTargetException | InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IMultiPageTalendEditor(org.talend.designer.core.IMultiPageTalendEditor) Item(org.talend.core.model.properties.Item) TableItem(org.eclipse.swt.widgets.TableItem) IEditorReference(org.eclipse.ui.IEditorReference) Property(org.talend.core.model.properties.Property) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) IEditorPart(org.eclipse.ui.IEditorPart) InvocationTargetException(java.lang.reflect.InvocationTargetException) IGEFProcess(org.talend.core.ui.process.IGEFProcess) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) Command(org.eclipse.gef.commands.Command) IWorkspace(org.eclipse.core.resources.IWorkspace) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ItemVersionObject(org.talend.repository.model.ItemVersionObject) ItemVersionObject(org.talend.repository.model.ItemVersionObject)

Example 3 with IMultiPageTalendEditor

use of org.talend.designer.core.IMultiPageTalendEditor in project tdi-studio-se by Talend.

the class OpenSQLBuilderDialogJob method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
     */
@Override
protected IStatus run(IProgressMonitor monitor) {
    loginProgress = new OpenSQLBuilderDialogProgress(connectionParameters, manager, composite);
    Object obj = controller.getDynamicProperty().getPart();
    Process p = null;
    if (obj instanceof IMultiPageTalendEditor) {
        p = (Process) ((IMultiPageTalendEditor) obj).getProcess();
    } else {
        //$NON-NLS-1$
        throw new RuntimeException(Messages.getString("OpenSQLBuilderDialogJob.typeRequried"));
    }
    final Process process = p;
    try {
        loginProgress.run(monitor);
        if (EDatabaseTypeName.ACCESS.getDisplayName().equals(connectionParameters.getDbType()) || connectionParameters.isStatus()) {
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    Shell parentShell = new Shell(composite.getShell().getDisplay());
                    if (elem instanceof Node) {
                        TextUtil.setDialogTitle(process.getName(), (String) //$NON-NLS-1$
                        ((Node) elem).getElementParameter("LABEL").getValue(), elem.getElementName());
                    } else {
                        TextUtil.setDialogTitle(process.getName(), null, null);
                    }
                    SQLBuilderDialog dial = new SQLBuilderDialog(parentShell);
                    UIUtils.addSqlBuilderDialog(process.getName(), dial);
                    dial.setConnParameters(connectionParameters);
                    if (Window.OK == dial.open()) {
                        if (!composite.isDisposed() && !connectionParameters.isNodeReadOnly()) {
                            if (EParameterFieldType.DBTABLE.equals(connectionParameters.getFieldType())) {
                            // final String selectDBTable = connectionParameters.getSelectDBTable();
                            // if (selectDBTable != null) {
                            // Command cmd = new PropertyChangeCommand(elem, propertyName, TalendTextUtils
                            // .addSQLQuotes(selectDBTable));
                            // commandStack.execute(cmd);
                            // }
                            } else {
                                String sql = connectionParameters.getQuery();
                                sql = QueryUtil.checkAndAddQuotes(sql);
                                PropertyChangeCommand cmd = new PropertyChangeCommand(elem, propertyName, sql);
                                cmd.setUpdate(true);
                                commandStack.execute(cmd);
                            }
                        }
                    }
                }
            });
        } else {
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    String pid = SqlBuilderPlugin.PLUGIN_ID;
                    //$NON-NLS-1$
                    String mainMsg = Messages.getString("ConnectionError.Message");
                    if (new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connectionParameters.getConnectionComment()).getCodeOfButton() == Dialog.OK) {
                        ConfigureConnParamDialog paramDialog = new ConfigureConnParamDialog(composite.getShell(), connectionParameters, process.getContextManager(), elem);
                        if (paramDialog.open() == Window.OK) {
                            controller.openSqlBuilderBuildIn(connectionParameters, propertyName);
                        }
                    }
                }
            });
        }
    } catch (InterruptedException ie) {
        loginProgress.cleanUp();
        //$NON-NLS-1$
        return new Status(IStatus.CANCEL, id, IStatus.CANCEL, "Progress.OpenSqlBuilderDialog.Cancelled", null);
    } catch (Exception e) {
        loginProgress.cleanUp();
        //$NON-NLS-1$
        return new Status(IStatus.ERROR, id, IStatus.CANCEL, "Progress.OpenSqlBuilderDialog.Error", e);
    }
    //$NON-NLS-1$
    return new Status(IStatus.OK, id, IStatus.OK, "tested ok ", null);
}
Also used : ErrorDialogWithDetailAreaAndContinueButton(org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Node(org.talend.designer.core.ui.editor.nodes.Node) Process(org.talend.designer.core.ui.editor.process.Process) IMultiPageTalendEditor(org.talend.designer.core.IMultiPageTalendEditor) Shell(org.eclipse.swt.widgets.Shell) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) ConfigureConnParamDialog(org.talend.designer.core.ui.editor.properties.ConfigureConnParamDialog) OpenSQLBuilderDialogProgress(org.talend.sqlbuilder.ui.progress.OpenSQLBuilderDialogProgress)

Aggregations

IMultiPageTalendEditor (org.talend.designer.core.IMultiPageTalendEditor)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)1 Command (org.eclipse.gef.commands.Command)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 Shell (org.eclipse.swt.widgets.Shell)1 TableItem (org.eclipse.swt.widgets.TableItem)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IEditorReference (org.eclipse.ui.IEditorReference)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 PersistenceException (org.talend.commons.exception.PersistenceException)1