Search in sources :

Example 1 with SwtPresentation

use of org.eclipse.sapphire.ui.forms.swt.SwtPresentation in project liferay-ide by liferay.

the class ServiceTypeImplBrowseActionHandler method browse.

@Override
public String browse(Presentation context) {
    Element element = getModelElement();
    Property property = property();
    IProject project = element.adapt(IProject.class);
    try {
        IJavaSearchScope scope = null;
        TypeSelectionExtension extension = null;
        if ("type".equals(_kind)) {
            scope = SearchEngine.createJavaSearchScope(new IJavaProject[] { JavaCore.create(project) });
            extension = new TypeSelectionExtension() {

                @Override
                public ITypeInfoFilterExtension getFilterExtension() {
                    return new ITypeInfoFilterExtension() {

                        public boolean select(ITypeInfoRequestor typeInfoRequestor) {
                            if (typeInfoRequestor.getPackageName().startsWith("com.liferay") && typeInfoRequestor.getTypeName().endsWith("Service")) {
                                return true;
                            }
                            return false;
                        }
                    };
                }
            };
        } else if ("impl".equals(_kind)) {
            String serviceType = _getServiceType(element);
            if (serviceType != null) {
                String wrapperType = serviceType + "Wrapper";
                scope = SearchEngine.createHierarchyScope(JavaCore.create(project).findType(wrapperType));
            } else {
                Shell shell = ((SwtPresentation) context).shell();
                MessageDialog.openInformation(shell, Msgs.serviceImplBrowse, Msgs.validServiceTypeProperty);
                return null;
            }
        }
        Shell shell = ((SwtPresentation) context).shell();
        SelectionDialog dlg = JavaUI.createTypeDialog(shell, null, scope, _browseDialogStyle, false, StringPool.DOUBLE_ASTERISK, extension);
        String title = property.definition().getLabel(true, CapitalizationType.TITLE_STYLE, false);
        dlg.setTitle(Msgs.select + title);
        if (dlg.open() == SelectionDialog.OK) {
            Object[] results = dlg.getResult();
            assert (results != null) && (results.length == 1);
            if (results[0] instanceof IType) {
                return ((IType) results[0]).getFullyQualifiedName();
            }
        }
    } catch (JavaModelException jme) {
        HookUI.logError(jme);
    }
    return null;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) Element(org.eclipse.sapphire.Element) ITypeInfoFilterExtension(org.eclipse.jdt.ui.dialogs.ITypeInfoFilterExtension) TypeSelectionExtension(org.eclipse.jdt.ui.dialogs.TypeSelectionExtension) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) IProject(org.eclipse.core.resources.IProject) IType(org.eclipse.jdt.core.IType) Shell(org.eclipse.swt.widgets.Shell) IJavaProject(org.eclipse.jdt.core.IJavaProject) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SwtPresentation(org.eclipse.sapphire.ui.forms.swt.SwtPresentation) Property(org.eclipse.sapphire.Property) ITypeInfoRequestor(org.eclipse.jdt.ui.dialogs.ITypeInfoRequestor)

Example 2 with SwtPresentation

use of org.eclipse.sapphire.ui.forms.swt.SwtPresentation 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 3 with SwtPresentation

use of org.eclipse.sapphire.ui.forms.swt.SwtPresentation in project liferay-ide by liferay.

the class SelectActiveProfilesActionHandler method run.

@Override
protected Object run(Presentation context) {
    if (context instanceof SwtPresentation) {
        final SwtPresentation swt = (SwtPresentation) context;
        final NewLiferayPluginProjectOp op = getModelElement().nearest(NewLiferayPluginProjectOp.class);
        final String previousActiveProfilesValue = op.getActiveProfilesValue().content();
        // we need to rebuild the 'selected' list from what is specified in the
        // 'activeProfiles' property
        op.getSelectedProfiles().clear();
        final String activeProfiles = op.getActiveProfilesValue().content();
        if (!CoreUtil.isNullOrEmpty(activeProfiles)) {
            final String[] profileIds = activeProfiles.split(",");
            if (ListUtil.isNotEmpty(profileIds)) {
                for (String profileId : profileIds) {
                    if (!CoreUtil.isNullOrEmpty(profileId)) {
                        boolean foundExistingProfile = false;
                        for (Profile profile : op.getSelectedProfiles()) {
                            if (profileId.equals(profile.getId().content())) {
                                foundExistingProfile = true;
                                break;
                            }
                        }
                        if (!foundExistingProfile) {
                            Profile newlySelectedProfile = op.getSelectedProfiles().insert();
                            newlySelectedProfile.setId(profileId);
                        }
                    }
                }
            }
        }
        final CustomSapphireDialog dialog = new CustomSapphireDialog(swt.shell(), op, DefinitionLoader.sdef(NewLiferayPluginProjectWizard.class).dialog("SelectActiveProfiles"));
        dialog.setBlockOnOpen(true);
        final int result = dialog.open();
        if (result == SapphireDialog.CANCEL) {
            // restore previous value
            op.setActiveProfilesValue(previousActiveProfilesValue);
        } else {
            final ElementList<Profile> selectedProfiles = op.getSelectedProfiles();
            NewLiferayPluginProjectOpMethods.updateActiveProfilesValue(op, selectedProfiles);
        }
    }
    return null;
}
Also used : SwtPresentation(org.eclipse.sapphire.ui.forms.swt.SwtPresentation) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) Profile(com.liferay.ide.project.core.model.Profile)

Example 4 with SwtPresentation

use of org.eclipse.sapphire.ui.forms.swt.SwtPresentation in project liferay-ide by liferay.

the class NewLiferayProfileActionHandler method run.

@Override
protected Object run(Presentation context) {
    if (context instanceof SwtPresentation) {
        final SwtPresentation swt = (SwtPresentation) context;
        final NewLiferayPluginProjectOp op = _op(context);
        final NewLiferayProfile newLiferayProfile = op.getNewLiferayProfiles().insert();
        final SapphireDialog dialog = new SapphireDialog(swt.shell(), newLiferayProfile, DefinitionLoader.sdef(NewLiferayPluginProjectWizard.class).dialog("NewLiferayProfile"));
        dialog.setBlockOnOpen(true);
        final int result = dialog.open();
        if (result == SapphireDialog.OK) {
            addToActiveProfiles(op, newLiferayProfile);
        } else {
            op.getNewLiferayProfiles().remove(newLiferayProfile);
        }
    }
    return null;
}
Also used : NewLiferayProfile(com.liferay.ide.project.core.model.NewLiferayProfile) SwtPresentation(org.eclipse.sapphire.ui.forms.swt.SwtPresentation) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) SapphireDialog(org.eclipse.sapphire.ui.forms.swt.SapphireDialog)

Example 5 with SwtPresentation

use of org.eclipse.sapphire.ui.forms.swt.SwtPresentation in project liferay-ide by liferay.

the class OpenPluginTypeDescriptionDialogAction method run.

@Override
protected Object run(Presentation context) {
    if (context instanceof SwtPresentation) {
        final SwtPresentation swt = (SwtPresentation) context;
        final NewLiferayPluginProjectOp op = getModelElement().nearest(NewLiferayPluginProjectOp.class);
        final PluginTypeDescriptionDialog dialog = new PluginTypeDescriptionDialog(swt.shell(), op, DefinitionLoader.sdef(NewLiferayPluginProjectWizard.class).dialog("PluginTypeDescription"));
        dialog.setBlockOnOpen(false);
        dialog.open();
    }
    return null;
}
Also used : SwtPresentation(org.eclipse.sapphire.ui.forms.swt.SwtPresentation) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) PluginTypeDescriptionDialog(com.liferay.ide.project.ui.dialog.PluginTypeDescriptionDialog)

Aggregations

SwtPresentation (org.eclipse.sapphire.ui.forms.swt.SwtPresentation)6 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)3 IProject (org.eclipse.core.resources.IProject)2 IType (org.eclipse.jdt.core.IType)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)2 Element (org.eclipse.sapphire.Element)2 Property (org.eclipse.sapphire.Property)2 SelectionDialog (org.eclipse.ui.dialogs.SelectionDialog)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 NewLiferayProfile (com.liferay.ide.project.core.model.NewLiferayProfile)1