Search in sources :

Example 66 with Path

use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.

the class HasBundlesDirDerivedValueService method compute.

@Override
protected String compute() {
    String retval = "false";
    Value<Path> workspaceLocationValue = _op().getWorkspaceLocation();
    Path path = workspaceLocationValue.content();
    if (path != null) {
        if (LiferayWorkspaceUtil.isValidWorkspaceLocation(path.toPortableString())) {
            retval = LiferayWorkspaceUtil.hasBundlesDir(path.toPortableString()) ? "true" : "false";
        }
    }
    return retval;
}
Also used : Path(org.eclipse.sapphire.modeling.Path)

Example 67 with Path

use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.

the class ImportWorkspaceBuildTypeDerivedValueService method compute.

@Override
protected String compute() {
    String retVal = null;
    if (_op().getWorkspaceLocation() != null) {
        Value<Path> workspaceLocation = _op().getWorkspaceLocation();
        Path path = workspaceLocation.content();
        if ((path != null) && !path.isEmpty()) {
            String location = path.toOSString();
            retVal = LiferayWorkspaceUtil.getWorkspaceType(location);
        }
    }
    return retVal;
}
Also used : Path(org.eclipse.sapphire.modeling.Path)

Example 68 with Path

use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.

the class ConvertedProjectLocationValidationService method compute.

@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    Value<Path> convertedProjectLocation = _op().getConvertedProjectLocation();
    final Path currentProjectLocation = convertedProjectLocation.content(true);
    if (currentProjectLocation != null) {
        final String currentPath = currentProjectLocation.toPortableString();
        if (!org.eclipse.core.runtime.Path.EMPTY.isValidPath(currentPath)) {
            retval = Status.createErrorStatus("\"" + currentPath + "\" is not a valid path.");
        } else {
            IPath osPath = org.eclipse.core.runtime.Path.fromOSString(currentPath);
            if (!osPath.toFile().isAbsolute()) {
                retval = Status.createErrorStatus("\"" + currentPath + "\" is not an absolute path.");
            } else {
                if (!osPath.toFile().exists()) {
                    if (!_canCreate(osPath.toFile())) {
                        retval = Status.createErrorStatus("Cannot create project content at \"" + currentPath + "\"");
                    }
                }
            }
        }
    } else {
        retval = Status.createErrorStatus("Converted Project Location must be specified.");
    }
    return retval;
}
Also used : Status(org.eclipse.sapphire.modeling.Status) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) IPath(org.eclipse.core.runtime.IPath)

Example 69 with Path

use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.

the class ImportSDKProjectsCheckboxCustomPart method getInitItemsList.

@Override
protected List<ProjectCheckboxElement> getInitItemsList() {
    List<ProjectCheckboxElement> checkboxElementList = new ArrayList<>();
    Value<Path> sdkLocationPath = _op().getSdkLocation();
    Path sdkLocation = sdkLocationPath.content();
    if ((sdkLocation == null) || !sdkLocation.toFile().exists()) {
        return checkboxElementList;
    }
    final ProjectRecord[] projectRecords = _updateProjectsList(PathBridge.create(sdkLocation).toPortableString());
    if (projectRecords == null) {
        return checkboxElementList;
    }
    String context = null;
    for (ProjectRecord projectRecord : projectRecords) {
        final String projectLocation = projectRecord.getProjectLocation().toPortableString();
        context = projectRecord.getProjectName() + " (" + projectLocation + ")";
        ProjectCheckboxElement checkboxElement = new ProjectCheckboxElement(projectRecord.getProjectName(), context, projectRecord.getProjectLocation().toPortableString());
        if (!projectRecord.hasConflicts()) {
            checkboxElementList.add(checkboxElement);
        }
    }
    _sortProjectCheckboxElement(checkboxElementList);
    return checkboxElementList;
}
Also used : Path(org.eclipse.sapphire.modeling.Path) ArrayList(java.util.ArrayList) ProjectRecord(com.liferay.ide.project.core.ProjectRecord)

Example 70 with Path

use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.

the class NewWorkflowDefinitionOpMethods method execute.

public static Status execute(NewWorkflowDefinitionOp op, ProgressMonitor monitor) {
    try {
        ReferenceValue<String, IProject> referProject = op.getProject();
        IProject project = referProject.target();
        Value<Path> opFolder = op.getFolder();
        Path projectPath = opFolder.content();
        IContainer folder = null;
        if (projectPath != null) {
            folder = project.getFolder(projectPath.toPortableString());
        } else {
            folder = project;
        }
        if (!folder.exists()) {
            folder = folder.getParent();
        }
        Value<String> opName = op.getName();
        String name = opName.content();
        String lowerCaseName = name.toLowerCase();
        String[] segments = lowerCaseName.split("\\s+");
        StringBuilder newName = new StringBuilder();
        for (String segment : segments) {
            StringBuilder segNewName = newName.append(segment);
            segNewName.append('-');
        }
        String fileNameBase = newName.toString() + "definition";
        String extension = ".xml";
        String fileName = fileNameBase + extension;
        IPath proRelativePath = folder.getProjectRelativePath();
        IFile newDefinitionFile = project.getFile(proRelativePath.append(fileName));
        int count = 1;
        while (newDefinitionFile.exists()) {
            fileName = fileNameBase + " (" + count + ")" + extension;
            newDefinitionFile = project.getFile(proRelativePath.append(fileName));
            count++;
        }
        newDefinitionFile.create(new ByteArrayInputStream("".getBytes()), true, null);
        Value<ScriptLanguageType> scLanguageType = op.getDefaultScriptLanguage();
        newDefinitionFile.setPersistentProperty(KaleoCore.DEFAULT_SCRIPT_LANGUAGE_KEY, scLanguageType.text(true));
        Value<TemplateLanguageType> deTemplateLanguage = op.getDefaultTemplateLanguage();
        newDefinitionFile.setPersistentProperty(KaleoCore.DEFAULT_TEMPLATE_LANGUAGE_KEY, deTemplateLanguage.text(true));
        RootXmlResource rootXmlResource = new RootXmlResource(new XmlResourceStore(new WorkspaceFileResourceStore(newDefinitionFile)));
        WorkflowDefinition workflowDefinition = WorkflowDefinition.TYPE.instantiate(rootXmlResource);
        workflowDefinition.setName(name);
        workflowDefinition.setVersion("1");
        Value<String> initStateName = op.getInitialStateName();
        String initialStateName = initStateName.content(true);
        ElementList<State> workflowState = workflowDefinition.getStates();
        State state = workflowState.insert();
        state.setName(initialStateName);
        state.setInitial(true);
        Value<String> initTaskName = op.getInitialTaskName();
        String initialTaskName = initTaskName.content(true);
        ElementList<Task> workflowTask = workflowDefinition.getTasks();
        Task task = workflowTask.insert();
        task.setName(initialTaskName);
        KaleoModelUtil.changeTaskAssignments(task, op);
        ElementList<Transition> transitions = state.getTransitions();
        Transition transition = transitions.insert();
        transition.setName(initialTaskName);
        transition.setTarget(initialTaskName);
        Value<String> opFinalName = op.getFinalStateName();
        String finalStateName = opFinalName.content(true);
        ElementList<State> states = workflowDefinition.getStates();
        State finalState = states.insert();
        finalState.setName(finalStateName);
        finalState.setEnd(true);
        ElementList<Action> actions = finalState.getActions();
        Action finalAction = actions.insert();
        finalAction.setName("approve");
        finalAction.setExecutionType(ExecutionType.ON_ENTRY);
        finalAction.setScriptLanguage(ScriptLanguageType.JAVASCRIPT);
        String updateStatus = "Packages.com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil.updateStatus";
        String workflowConstants = "(Packages.com.liferay.portal.kernel.workflow.WorkflowConstants.";
        String toStatus = "toStatus(\"approved\"), workflowContext);";
        finalAction.setScript(updateStatus + workflowConstants + toStatus);
        ElementList<Transition> taskTransitions = task.getTransitions();
        Transition taskTransition = taskTransitions.insert();
        taskTransition.setName(finalStateName);
        taskTransition.setTarget(finalStateName);
        ElementHandle<WorkflowNodeMetadata> wfMetadata = state.getMetadata();
        WorkflowNodeMetadata stateMetadata = wfMetadata.content();
        Position statePosition = stateMetadata.getPosition();
        statePosition.setX(100);
        statePosition.setY(50);
        ElementList<TransitionMetadata> transitionMetadata = stateMetadata.getTransitionsMetadata();
        TransitionMetadata insertTransitionMetadata = transitionMetadata.insert();
        insertTransitionMetadata.setName(initialTaskName);
        ElementHandle<WorkflowNodeMetadata> taskWorkflow = task.getMetadata();
        WorkflowNodeMetadata taskMetadata = taskWorkflow.content();
        Position taskPosition = taskMetadata.getPosition();
        taskPosition.setX(300);
        taskPosition.setY(35);
        ElementList<TransitionMetadata> transitionTask = taskMetadata.getTransitionsMetadata();
        TransitionMetadata transitionTaskMetadata = transitionTask.insert();
        transitionTaskMetadata.setName(finalStateName);
        ElementHandle<WorkflowNodeMetadata> finalMetadata = finalState.getMetadata();
        WorkflowNodeMetadata finalStateMetadata = finalMetadata.content();
        Position finalStatePosition = finalStateMetadata.getPosition();
        finalStatePosition.setX(520);
        finalStatePosition.setY(50);
        /*
			 * Document document = rootXmlResource.getDomDocument(); Element
			 * docElement = document.getDocumentElement(); Attr schemaLocation =
			 * docElement.getAttributeNode( "xsi:schemaLocation" ); =
			 * schemaLocation.getNodeValue(); String nodeValue =
			 * schemaLocation.getNodeValue(); schemaLocation.setNodeValue(
			 * nodeValue.replaceAll( " http://www.w3.org/XML/1998/namespace ",
			 * "" ) );
			 */
        rootXmlResource.save();
        IPath fullPath = newDefinitionFile.getFullPath();
        op.setNewFilePath(fullPath.toPortableString());
        return Status.createOkStatus();
    } catch (Exception e) {
        KaleoCore.logError("Error creating new kaleo workflow file.", e);
        return Status.createErrorStatus("Error creating new kaleo workflow file.", e);
    }
}
Also used : Task(com.liferay.ide.kaleo.core.model.Task) Action(com.liferay.ide.kaleo.core.model.Action) IFile(org.eclipse.core.resources.IFile) TransitionMetadata(com.liferay.ide.kaleo.core.model.TransitionMetadata) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) ScriptLanguageType(com.liferay.ide.kaleo.core.model.ScriptLanguageType) WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata) WorkspaceFileResourceStore(org.eclipse.sapphire.workspace.WorkspaceFileResourceStore) TemplateLanguageType(com.liferay.ide.kaleo.core.model.TemplateLanguageType) IContainer(org.eclipse.core.resources.IContainer) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) IPath(org.eclipse.core.runtime.IPath) Position(com.liferay.ide.kaleo.core.model.Position) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) IProject(org.eclipse.core.resources.IProject) ByteArrayInputStream(java.io.ByteArrayInputStream) State(com.liferay.ide.kaleo.core.model.State) Transition(com.liferay.ide.kaleo.core.model.Transition)

Aggregations

Path (org.eclipse.sapphire.modeling.Path)71 IPath (org.eclipse.core.runtime.IPath)37 IStatus (org.eclipse.core.runtime.IStatus)18 Status (org.eclipse.sapphire.modeling.Status)18 IProject (org.eclipse.core.resources.IProject)17 SDK (com.liferay.ide.sdk.core.SDK)16 CoreException (org.eclipse.core.runtime.CoreException)16 IFile (org.eclipse.core.resources.IFile)12 File (java.io.File)9 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)8 ArrayList (java.util.ArrayList)8 IFolder (org.eclipse.core.resources.IFolder)8 Hook (com.liferay.ide.hook.core.model.Hook)6 Element (org.eclipse.sapphire.Element)6 CustomJspDir (com.liferay.ide.hook.core.model.CustomJspDir)5 IWebProject (com.liferay.ide.core.IWebProject)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)3 ValueProperty (org.eclipse.sapphire.ValueProperty)3 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)2