/** @generated */ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { ForEachLoop newElement = ParallelJFactory.eINSTANCE.createForEachLoop(); Program owner = (Program) getElementToEdit(); owner.getElements().add(newElement); doConfigure(newElement, monitor, info); ((CreateElementRequest) getRequest()).setNewElement(newElement); return CommandResult.newOKCommandResult(newElement); }
/* * (non-Javadoc) * * @see * org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse * .emf.validation.IValidationContext) */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); if (eObject instanceof Procedure) { Procedure procedure = (Procedure) eObject; if (!StringTool.isEmpty(procedure.getName())) { int procedureCount = 0; int forEachLoopCount = 0; int whileLoopCount = 0; int handlerCount = 0; int pipelineCount = 0; EList<Procedure> procedures = null; List<Element> elements = new ArrayList<Element>(); Program program = null; // if target is pipelineProcedure i.e. Procedure from // Pipeline, then taking all internal sequence procedures for // checking if (procedure.eClass().getName().equals(PROCEDURE) && procedure.eContainer() instanceof Pipeline) { Pipeline pipeline = (Pipeline) procedure.eContainer(); procedures = pipeline.getProcedures(); program = (Program) pipeline.eContainer(); } if (program == null) { program = (Program) procedure.eContainer(); } // taking all elements form Program EList<Element> programElements = program.getElements(); // making consolidate list of sequence procedure from Pipeline // and procedures from Program if (procedures != null) { elements.addAll(procedures); } // if target is pipelineProcedure, then taking only Procedures // object from Program to compare if (procedure.eContainer() instanceof Pipeline && programElements != null) { for (Element element : programElements) { if (element.eClass().getName().equals(PROCEDURE)) { elements.add(element); } } } // else all else if (programElements != null) { elements.addAll(programElements); } // checking each element according it's type, for same name for (Element element : elements) { if (!StringTool.isEmpty(element.getName()) && procedure.getName().equals(element.getName())) { // for Procedure if (element.eClass().getName().equals(PROCEDURE) && procedure.eClass().getName().equals(PROCEDURE) && procedureCount < 2) { procedureCount++; // for ForEachLoop } else if (element.eClass().getName().equals(FOREACHLOOP) && procedure.eClass().getName().equals(FOREACHLOOP) && forEachLoopCount < 2) { forEachLoopCount++; // for WhileLoop } else if (element.eClass().getName().equals(WHILELOOP) && procedure.eClass().getName().equals(WHILELOOP) && whileLoopCount < 2) { whileLoopCount++; // for Handler } else if (element.eClass().getName().equals(HANDLER) && procedure.eClass().getName().equals(HANDLER) && handlerCount < 2) { handlerCount++; // for Pipeline } else if (element.eClass().getName().equals(PIPELINE) && procedure.eClass().getName().equals(PIPELINE) && pipelineCount < 2) { pipelineCount++; } } // if target object is Procedure from Program, then checking // with all sequence Procedures from Pipeline for same name // validation if (element.eClass().getName().equals(PIPELINE) && procedure.eClass().getName().equals(PROCEDURE)) { Pipeline pipeline = (Pipeline) element; EList<Procedure> pipelineProcs = pipeline.getProcedures(); for (Procedure pipelineProc : pipelineProcs) { if (!StringTool.isEmpty(pipelineProc.getName()) && procedure.getName().equals(pipelineProc.getName()) && procedureCount < 2) { procedureCount++; } } } } // if any of above having two objects with same name, then show // error message for respective one. if (procedureCount == 2 || forEachLoopCount == 2 || whileLoopCount == 2 || handlerCount == 2 || pipelineCount == 2) { return ctx.createFailureStatus(procedure.eClass().getName(), procedure.getName()); } } } return ctx.createSuccessStatus(); }