Search in sources :

Example 21 with IRepositoryService

use of org.talend.repository.model.IRepositoryService in project tesb-studio-se by Talend.

the class RouteResourceEditorUtil method isReadOnly.

public static boolean isReadOnly(IRepositoryNode node) {
    IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
    IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
    /*
		 * if user is readonly , then set enable as false
		 */
    if (repFactory.isUserReadOnlyOnCurrentProject()) {
        return true;
    }
    // if it's not in current project, then it's disable
    if (!ProjectManager.getInstance().isInCurrentMainProject(node)) {
        return true;
    }
    // if it's locked by others, then it's disable
    IRepositoryViewObject object = node.getObject();
    if (object == null) {
        return false;
    }
    Property property = object.getProperty();
    if (property == null) {
        return false;
    }
    Item item = property.getItem();
    if (item == null) {
        return false;
    }
    ERepositoryStatus status = repFactory.getStatus(item);
    if (ERepositoryStatus.LOCK_BY_OTHER.equals(status) || ERepositoryStatus.DELETED.equals(status)) {
        return true;
    }
    if (!isLatestVersion(property)) {
        return true;
    }
    return false;
}
Also used : RouteResourceItem(org.talend.camel.core.model.camelProperties.RouteResourceItem) Item(org.talend.core.model.properties.Item) ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IRepositoryService(org.talend.repository.model.IRepositoryService)

Example 22 with IRepositoryService

use of org.talend.repository.model.IRepositoryService in project tesb-studio-se by Talend.

the class OpenDefaultEditorAction method init.

//	private ISelection getSelectedObject() {
//		if (params == null) {
//			return getSelection();
//		}
//		else {
//			RepositoryNode repositoryNode = RepositoryNodeUtilities
//					.getRepositoryNode(params.getProperty("nodeId"), false); //$NON-NLS-1$
//			IRepositoryView viewPart = getViewPart();
//			if (repositoryNode != null && viewPart != null) {
//				RepositoryNodeUtilities.expandParentNode(viewPart,
//						repositoryNode);
//				return new StructuredSelection(repositoryNode);
//			}
//			return null;
//		}
//	}
/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.talend.repository.ui.actions.ITreeContextualAction#init(org.eclipse
	 * .jface.viewers.TreeViewer,
	 * org.eclipse.jface.viewers.IStructuredSelection)
	 */
public void init(TreeViewer viewer, IStructuredSelection selection) {
    boolean canWork = !selection.isEmpty() && selection.size() == 1;
    if (canWork) {
        Object o = selection.getFirstElement();
        RepositoryNode node = (RepositoryNode) o;
        switch(node.getType()) {
            case REPOSITORY_ELEMENT:
                if (node.getObjectType() != CamelRepositoryNodeType.repositoryRouteResourceType) {
                    canWork = false;
                } else {
                    IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
                    IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
                    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                    if (!factory.isUserReadOnlyOnCurrentProject() && repFactory.isPotentiallyEditable(node.getObject())) {
                        //$NON-NLS-1$
                        this.setText(Messages.getString("OpenDefaultEditorAction_title"));
                    } else {
                        //$NON-NLS-1$
                        this.setText(Messages.getString("OpenDefaultEditorAction_title_read"));
                    }
                }
                break;
            default:
                canWork = false;
        }
        RepositoryNode parent = node.getParent();
        if (canWork && parent != null && parent instanceof BinRepositoryNode) {
            canWork = false;
        }
        // job version is the latest verison or not.
        if (canWork) {
            canWork = isLastVersion(node);
        }
    }
    setEnabled(canWork);
    //$NON-NLS-1$
    this.setToolTipText(Messages.getString("OpenDefaultEditorAction_tooltip"));
    this.setImageDescriptor(RouteResourceActivator.createImageDesc(//$NON-NLS-1$
    "icons/edit-resource.png"));
}
Also used : BinRepositoryNode(org.talend.repository.model.BinRepositoryNode) BinRepositoryNode(org.talend.repository.model.BinRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IRepositoryService(org.talend.repository.model.IRepositoryService)

Example 23 with IRepositoryService

use of org.talend.repository.model.IRepositoryService in project tdi-studio-se by Talend.

the class UpgradeAttributestFilterRow method execute.

/*
     * (non-Javadoc)
     * 
     * @seeorg.talend.core.model.migration.AbstractJobMigrationTask#executeOnProcess(org.talend.core.model.properties.
     * ProcessItem)
     */
@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() == ECodeLanguage.PERL || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    } else {
        //$NON-NLS-1$
        String functionName = "FUNCTION";
        //$NON-NLS-1$
        String operatorName = "OPERATOR";
        String[][] replaceFuntions = new String[][] { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        { "S_VALUE_OF", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        { "N_VALUE_OF_FLOAT", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        { "N_VALUE_OF_INTEGER", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        { "ABS_VALUE_FLOAT", "Math.abs($source) $operator $target" }, //$NON-NLS-1$ //$NON-NLS-2$
        { "ABS_VALUE_INTEGER", "Math.abs($source) $operator $target" }, //$NON-NLS-1$ //$NON-NLS-2$
        { "LC", "$source == null? false : $source.toLowerCase().compareTo($target) $operator 0" }, //$NON-NLS-1$ //$NON-NLS-2$
        { "UC", "$source == null? false : $source.toUpperCase().compareTo($target) $operator 0" }, //$NON-NLS-1$ //$NON-NLS-2$
        { "LCFIRST", "$source == null? false : $source.toLowerCase().charAt(0).compareTo($target) $operator 0" }, //$NON-NLS-1$ //$NON-NLS-2$
        { "UCFIRST", "$source == null? false : $source.toUpperCase().charAt(0).compareTo($target) $operator 0" }, //$NON-NLS-1$ //$NON-NLS-2$
        { "LENGTH", "$source == null? false : $source.length() $operator $target" } };
        String[][] replaceOperator = new String[][] { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
        { "EQ", "==" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
        { "NE", "!=" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
        { "GT", ">" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
        { "LT", "<" }, { "GE", ">=" }, { "LE", "<=" }, { "MATCH", "==" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
        { "NMATCH", "!=" } };
        boolean isModified = false;
        NodeType tFilterRow = null;
        for (Object oNodeType : processType.getNode()) {
            NodeType nodeType = (NodeType) oNodeType;
            if (nodeType.getComponentName().equals("tFilterRow")) {
                //$NON-NLS-1$
                tFilterRow = nodeType;
                break;
            }
        }
        if (tFilterRow != null) {
            EList elementParameter = tFilterRow.getElementParameter();
            for (Object object : elementParameter) {
                ElementParameterTypeImpl parameter = (ElementParameterTypeImpl) object;
                if (parameter.getName().equals("CONDITIONS")) {
                    //$NON-NLS-1$
                    EList elementValue = parameter.getElementValue();
                    ElementValueTypeImpl lastFunctionForMatch = null;
                    for (Object object2 : elementValue) {
                        ElementValueTypeImpl tableElement = (ElementValueTypeImpl) object2;
                        if (tableElement.getElementRef().equals(functionName)) {
                            for (String[] element : replaceFuntions) {
                                if (element[0].equals(tableElement.getValue())) {
                                    tableElement.setValue(element[1]);
                                    lastFunctionForMatch = tableElement;
                                    isModified = true;
                                }
                            }
                        } else if (tableElement.getElementRef().equals(operatorName)) {
                            for (String[] element : replaceOperator) {
                                // list"
                                if ("MATCH".equals(tableElement.getValue()) || "NMATCH".equals(tableElement.getValue())) {
                                    //$NON-NLS-1$ //$NON-NLS-2$
                                    if (lastFunctionForMatch != null) {
                                        lastFunctionForMatch.setValue(//$NON-NLS-1$
                                        "$source == null? false : $source.matches($target) $operator true");
                                        isModified = true;
                                    }
                                }
                                if (element[0].equals(tableElement.getValue())) {
                                    tableElement.setValue(element[1]);
                                    isModified = true;
                                }
                            }
                        }
                    }
                } else if (parameter.getName().equals("LOGICAL_OP")) {
                    //$NON-NLS-1$
                    if (parameter.getValue().equals("AND")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        parameter.setValue("&&");
                        isModified = true;
                    } else if (parameter.getValue().equals("OR")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        parameter.setValue("||");
                        isModified = true;
                    }
                }
            }
        }
        if (isModified) {
            IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
            IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
            try {
                factory.save(item, true);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
        return ExecutionResult.SUCCESS_NO_ALERT;
    }
}
Also used : IRepositoryService(org.talend.repository.model.IRepositoryService) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) EList(org.eclipse.emf.common.util.EList) ElementValueTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ElementValueTypeImpl) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ElementParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ElementParameterTypeImpl)

Example 24 with IRepositoryService

use of org.talend.repository.model.IRepositoryService in project tesb-studio-se by Talend.

the class CreateRouteResourceAction method doRun.

@Override
protected void doRun() {
    IRepositoryNode node = null;
    NewRouteResourceWizard wizard = null;
    ISelection selection = getSelection();
    if (selection == null) {
        return;
    }
    Object obj = ((IStructuredSelection) selection).getFirstElement();
    node = (IRepositoryNode) obj;
    IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
    IPath path = service.getRepositoryPath(node);
    if (RepositoryConstants.isSystemFolder(path.toString())) {
        // Not allowed to create in system folder.
        return;
    }
    wizard = new NewRouteResourceWizard(path);
    WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
    int open = dlg.open();
    if (open == Window.OK) {
        RouteResourceItem item = wizard.getItem();
        IWorkbenchPage page = getActivePage();
        RouteResourceEditorUtil.openEditor(page, null, item);
    }
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) IPath(org.eclipse.core.runtime.IPath) RouteResourceItem(org.talend.camel.core.model.camelProperties.RouteResourceItem) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) NewRouteResourceWizard(org.talend.designer.camel.resource.ui.wizards.NewRouteResourceWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IRepositoryService(org.talend.repository.model.IRepositoryService)

Example 25 with IRepositoryService

use of org.talend.repository.model.IRepositoryService in project tesb-studio-se by Talend.

the class CreateCamelProcess method doRun.

@Override
protected void doRun() {
    final CamelNewProcessWizard processWizard;
    if (isToolbar()) {
        processWizard = new CamelNewProcessWizard(null);
    } else {
        ISelection selection = getSelection();
        if (selection == null) {
            return;
        }
        Object obj = ((IStructuredSelection) selection).getFirstElement();
        IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
        IPath path = service.getRepositoryPath((IRepositoryNode) obj);
        if (RepositoryConstants.isSystemFolder(path.toString())) {
            // Not allowed to create in system folder.
            return;
        }
        processWizard = new CamelNewProcessWizard(path);
    }
    WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), processWizard);
    if (dlg.open() == Window.OK) {
        if (processWizard.getProcess() == null) {
            return;
        }
        try {
            openEditor(processWizard.getProcess());
        } catch (PartInitException e) {
            ExceptionHandler.process(e);
        } catch (PersistenceException e) {
            MessageBoxExceptionHandler.process(e);
        }
    }
}
Also used : CamelNewProcessWizard(org.talend.camel.designer.ui.wizards.CamelNewProcessWizard) IPath(org.eclipse.core.runtime.IPath) ISelection(org.eclipse.jface.viewers.ISelection) PersistenceException(org.talend.commons.exception.PersistenceException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IRepositoryService(org.talend.repository.model.IRepositoryService)

Aggregations

IRepositoryService (org.talend.repository.model.IRepositoryService)27 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)21 PersistenceException (org.talend.commons.exception.PersistenceException)19 Item (org.talend.core.model.properties.Item)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)9 PartInitException (org.eclipse.ui.PartInitException)8 CoreException (org.eclipse.core.runtime.CoreException)7 Property (org.talend.core.model.properties.Property)7 LoginException (org.talend.commons.exception.LoginException)6 ProcessItem (org.talend.core.model.properties.ProcessItem)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IPath (org.eclipse.core.runtime.IPath)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 ERepositoryStatus (org.talend.commons.runtime.model.repository.ERepositoryStatus)5 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)5 IFile (org.eclipse.core.resources.IFile)4 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 IProject (org.eclipse.core.resources.IProject)3