Search in sources :

Example 1 with DefinitionLoader

use of org.eclipse.sapphire.ui.def.DefinitionLoader in project liferay-ide by liferay.

the class ChangeTaskAssignmentsActionHandler method run.

@Override
protected Object run(Presentation context) {
    Task task = _task(context);
    ChangeTaskAssignmentsOp op = ChangeTaskAssignmentsOp.TYPE.instantiate();
    for (WorkflowNode node : task.nearest(WorkflowDefinition.class).getDiagramNodes()) {
        Assignable assignable = node.nearest(Assignable.class);
        if (assignable != null) {
            for (Role role : assignable.getRoles()) {
                String name = role.getName().content(false);
                if (!isNullOrEmpty(name)) {
                    ElementList<RoleName> roleName = op.getRoleNames();
                    roleName.insert().setName(name);
                }
            }
        }
    }
    User existingUser = task.getUser().content(false);
    ElementList<Role> existingRoles = task.getRoles();
    ElementList<ResourceAction> existingActions = task.getResourceActions();
    Scriptable scriptedAssignment = task.getScriptedAssignment().content(false);
    if (existingUser != null) {
        op.getImpliedUser().copy(existingUser);
    } else if (ListUtil.isNotEmpty(existingRoles)) {
        op.getImpliedRole().copy(existingRoles.get(0));
        for (Role role : existingRoles) {
            Role newRole = op.getRoles().insert();
            newRole.copy(role);
            Boolean autoCreate = role.getAutoCreate().content(false);
            if (autoCreate != null) {
                newRole.setAutoCreate(role.getAutoCreate().content());
            }
        }
    } else if (ListUtil.isNotEmpty(existingActions)) {
        for (ResourceAction action : existingActions) {
            ElementList<ResourceAction> resourceActions = op.getResourceActions();
            ResourceAction resourceAction = resourceActions.insert();
            resourceAction.copy(action);
        }
    } else if (scriptedAssignment != null) {
        ElementHandle<Scriptable> scriptable = op.getScriptedAssignment();
        Scriptable content = scriptable.content(true);
        content.copy(scriptedAssignment);
    }
    DefinitionLoader loader = DefinitionLoader.context(NewWorkflowDefinitionWizard.class);
    DefinitionLoader loaderSdef = loader.sdef("WorkflowDefinitionWizards");
    SapphireWizard<ChangeTaskAssignmentsOp> wizard = new SapphireWizard<>(op, loaderSdef.wizard("changeTaskAssignmentsWizard"));
    int returnCode = new WizardDialog(((SwtPresentation) context).shell(), wizard).open();
    if (returnCode == IDialogConstants.OK_ID) {
        KaleoModelUtil.changeTaskAssignments(_task(context), op);
    }
    return null;
}
Also used : SapphireWizard(org.eclipse.sapphire.ui.forms.swt.SapphireWizard) Task(com.liferay.ide.kaleo.core.model.Task) User(com.liferay.ide.kaleo.core.model.User) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) Scriptable(com.liferay.ide.kaleo.core.model.Scriptable) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) Role(com.liferay.ide.kaleo.core.model.Role) RoleName(com.liferay.ide.kaleo.core.model.RoleName) DefinitionLoader(org.eclipse.sapphire.ui.def.DefinitionLoader) ElementHandle(org.eclipse.sapphire.ElementHandle) SwtPresentation(org.eclipse.sapphire.ui.forms.swt.SwtPresentation) WizardDialog(org.eclipse.jface.wizard.WizardDialog) ChangeTaskAssignmentsOp(com.liferay.ide.kaleo.core.op.ChangeTaskAssignmentsOp) Assignable(com.liferay.ide.kaleo.core.model.Assignable) ResourceAction(com.liferay.ide.kaleo.core.model.ResourceAction)

Example 2 with DefinitionLoader

use of org.eclipse.sapphire.ui.def.DefinitionLoader in project liferay-ide by liferay.

the class LiferayProjectPropertyPage method createInfoGroup.

protected void createInfoGroup(final Composite parent) {
    new Label(parent, SWT.LEFT).setText(Msgs.liferayPluginTypeLabel);
    final Text pluginTypeLabel = new Text(parent, SWT.READ_ONLY | SWT.BORDER);
    pluginTypeLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
    final IProjectFacet liferayFacet = ProjectUtil.getLiferayFacet(getFacetedProject());
    if (liferayFacet != null) {
        pluginTypeLabel.setText(liferayFacet.getLabel());
    }
    final IProject proj = getProject();
    if ((proj != null) && ProjectUtil.isLiferayFacetedProject(proj)) {
        try {
            if (!ProjectUtil.isMavenProject(proj)) {
                final SDK projectSdk = SDKUtil.getSDK(getProject());
                new Label(parent, SWT.LEFT).setText(Msgs.liferaySdkLabel);
                _sdkLabel = new Text(parent, SWT.READ_ONLY | SWT.BORDER);
                if (projectSdk != null) {
                    _sdkLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
                    _sdkLabel.setText(projectSdk.getName());
                } else {
                    _sdkLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
                    _sdkLabel.setText("");
                    final Hyperlink link = new Hyperlink(parent, SWT.NULL);
                    link.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
                    link.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
                    link.setUnderlined(true);
                    link.setText(Msgs.changeliferaySdk);
                    link.addHyperlinkListener(new HyperlinkAdapter() {

                        public void linkActivated(HyperlinkEvent e) {
                            String dialogId = new String("com.liferay.ide.project.ui.dialog.SelectPluginsSDKDialog");
                            final LiferayPluginSDKOp op = (LiferayPluginSDKOp) (LiferayPluginSDKOp.TYPE.instantiate().initialize());
                            DefinitionLoader sdefLoader = DefinitionLoader.context(getClass()).sdef(dialogId);
                            final Reference<DialogDef> dialogRef = sdefLoader.dialog("ConfigureLiferaySDK");
                            final SapphireDialog dialog = new SapphireDialog(UIUtil.getActiveShell(), op, dialogRef);
                            dialog.setBlockOnOpen(true);
                            final int result = dialog.open();
                            if (result != SapphireDialog.CANCEL) {
                                _sdkLabel.setText(op.getPluginsSDKName().content());
                            }
                        }
                    });
                }
                if (CoreUtil.compareVersions(new Version(projectSdk.getVersion()), ILiferayConstants.V700) < 0) {
                    new Label(parent, SWT.LEFT).setText(Msgs.liferayRuntimeLabel);
                    _runtimeCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
                    _runtimeCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
                    String currentRuntimeName = null;
                    try {
                        ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(getProject());
                        if (liferayRuntime != null) {
                            currentRuntimeName = liferayRuntime.getRuntime().getName();
                        }
                    } catch (Exception e) {
                        ProjectUI.logError("Could not determine liferay runtime", e);
                    }
                    List<String> runtimeNames = new ArrayList<>();
                    int selectionIndex = -1;
                    for (IRuntime runtime : ServerCore.getRuntimes()) {
                        if (ServerUtil.isLiferayRuntime(runtime) && FileUtil.exists(runtime.getLocation()) && (LiferayServerCore.newPortalBundle(runtime.getLocation()) == null)) {
                            runtimeNames.add(runtime.getName());
                            if (runtime.getName().equals(currentRuntimeName)) {
                                selectionIndex = runtimeNames.size() - 1;
                            }
                        }
                    }
                    if (ListUtil.isEmpty(runtimeNames)) {
                        runtimeNames.add("No Liferay runtimes available.");
                    }
                    _runtimeCombo.setItems(runtimeNames.toArray(new String[0]));
                    if (selectionIndex > -1) {
                        _runtimeCombo.select(selectionIndex);
                    }
                }
            }
        } catch (Exception e) {
            ProjectUI.logError("Could not determine whether its a maven project ", e);
        }
    }
}
Also used : HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) Reference(org.eclipse.sapphire.ui.def.DefinitionLoader.Reference) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) LiferayPluginSDKOp(com.liferay.ide.project.core.model.LiferayPluginSDKOp) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IRuntime(org.eclipse.wst.server.core.IRuntime) Version(org.osgi.framework.Version) DefinitionLoader(org.eclipse.sapphire.ui.def.DefinitionLoader) ILiferayRuntime(com.liferay.ide.server.core.ILiferayRuntime) GridData(org.eclipse.swt.layout.GridData) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) SDK(com.liferay.ide.sdk.core.SDK) SapphireDialog(org.eclipse.sapphire.ui.forms.swt.SapphireDialog) Hyperlink(org.eclipse.ui.forms.widgets.Hyperlink) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Example 3 with DefinitionLoader

use of org.eclipse.sapphire.ui.def.DefinitionLoader in project liferay-ide by liferay.

the class PluginsSDKNotSetResolution method run.

public void run(IMarker marker) {
    if (marker.getResource() instanceof IProject) {
        final IProject proj = (IProject) marker.getResource();
        final LiferayPluginSDKOp op = (LiferayPluginSDKOp) (LiferayPluginSDKOp.TYPE.instantiate().initialize());
        DefinitionLoader loader = DefinitionLoader.context(getClass());
        final Reference<DialogDef> dialogRef = loader.sdef("com.liferay.ide.project.ui.dialog.SelectPluginsSDKDialog").dialog("ConfigureLiferaySDK");
        final SapphireDialog dialog = new SapphireDialog(UIUtil.getActiveShell(), op, dialogRef);
        dialog.setBlockOnOpen(true);
        final int result = dialog.open();
        if (result != SapphireDialog.CANCEL) {
            String sdkName = op.getPluginsSDKName().content();
            SDKUtil.saveSDKNameSetting(proj, sdkName);
        }
    }
}
Also used : DialogDef(org.eclipse.sapphire.ui.forms.DialogDef) DefinitionLoader(org.eclipse.sapphire.ui.def.DefinitionLoader) LiferayPluginSDKOp(com.liferay.ide.project.core.model.LiferayPluginSDKOp) SapphireDialog(org.eclipse.sapphire.ui.forms.swt.SapphireDialog) IProject(org.eclipse.core.resources.IProject)

Aggregations

DefinitionLoader (org.eclipse.sapphire.ui.def.DefinitionLoader)3 LiferayPluginSDKOp (com.liferay.ide.project.core.model.LiferayPluginSDKOp)2 IProject (org.eclipse.core.resources.IProject)2 SapphireDialog (org.eclipse.sapphire.ui.forms.swt.SapphireDialog)2 Assignable (com.liferay.ide.kaleo.core.model.Assignable)1 ResourceAction (com.liferay.ide.kaleo.core.model.ResourceAction)1 Role (com.liferay.ide.kaleo.core.model.Role)1 RoleName (com.liferay.ide.kaleo.core.model.RoleName)1 Scriptable (com.liferay.ide.kaleo.core.model.Scriptable)1 Task (com.liferay.ide.kaleo.core.model.Task)1 User (com.liferay.ide.kaleo.core.model.User)1 WorkflowDefinition (com.liferay.ide.kaleo.core.model.WorkflowDefinition)1 WorkflowNode (com.liferay.ide.kaleo.core.model.WorkflowNode)1 ChangeTaskAssignmentsOp (com.liferay.ide.kaleo.core.op.ChangeTaskAssignmentsOp)1 SDK (com.liferay.ide.sdk.core.SDK)1 ILiferayRuntime (com.liferay.ide.server.core.ILiferayRuntime)1 ArrayList (java.util.ArrayList)1 CoreException (org.eclipse.core.runtime.CoreException)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 ElementHandle (org.eclipse.sapphire.ElementHandle)1