Search in sources :

Example 1 with IPreset

use of org.eclipse.wst.common.project.facet.core.IPreset in project liferay-ide by liferay.

the class SDKPluginFacetUtil method configureProjectAsRuntimeProject.

public static void configureProjectAsRuntimeProject(IFacetedProjectWorkingCopy fpjwc, IRuntime runtime, String pluginType, String sdkLocation, ProjectRecord projectRecord) throws CoreException {
    fpjwc.setTargetedRuntimes(Collections.<IRuntime>emptySet());
    if (runtime != null) {
        fpjwc.setTargetedRuntimes(Collections.singleton(runtime));
    }
    fpjwc.setPrimaryRuntime(runtime);
    // fpjwc.setSelectedPreset(
    // FacetedProjectFramework.DEFAULT_CONFIGURATION_PRESET_ID );
    IFacetedProjectTemplate template = getLiferayTemplateForProject(pluginType);
    IPreset preset = getLiferayPresetForProject(pluginType);
    if (preset == null) {
        throw new CoreException(ProjectCore.createErrorStatus(NLS.bind(Msgs.noFacetPreset, fpjwc.getProjectName())));
    }
    Set<IProjectFacetVersion> currentProjectFacetVersions = fpjwc.getProjectFacets();
    Set<IProjectFacet> requiredFacets = template.getFixedProjectFacets();
    for (IProjectFacet requiredFacet : requiredFacets) {
        boolean hasRequiredFacet = false;
        for (IProjectFacetVersion currentFacetVersion : currentProjectFacetVersions) {
            if (currentFacetVersion.getProjectFacet().equals(requiredFacet)) {
                boolean supports = runtime.supports(currentFacetVersion);
                boolean requiredVersion = _isRequiredVersion(currentFacetVersion);
                if (supports && requiredVersion) {
                    hasRequiredFacet = true;
                } else {
                    fpjwc.removeProjectFacet(currentFacetVersion);
                }
                break;
            }
        }
        if (!hasRequiredFacet) {
            IProjectFacetVersion requiredFacetVersion = _getRequiredFacetVersionFromPreset(requiredFacet, preset);
            if (requiredFacetVersion != null) {
                fpjwc.addProjectFacet(requiredFacetVersion);
                if (ProjectUtil.isJavaFacet(requiredFacetVersion)) {
                    configureJavaFacet(fpjwc, requiredFacetVersion.getProjectFacet(), preset, projectRecord);
                } else if (ProjectUtil.isDynamicWebFacet(requiredFacetVersion)) {
                    configureWebFacet(fpjwc, requiredFacetVersion.getProjectFacet(), preset);
                }
            }
        } else {
            if (ProjectUtil.isJavaFacet(requiredFacet)) {
                configureJavaFacet(fpjwc, requiredFacet, preset, projectRecord);
            } else if (ProjectUtil.isDynamicWebFacet(requiredFacet)) {
                configureWebFacet(fpjwc, requiredFacet, preset);
            }
        }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) IFacetedProjectTemplate(org.eclipse.wst.common.project.facet.core.IFacetedProjectTemplate) IPreset(org.eclipse.wst.common.project.facet.core.IPreset) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet)

Example 2 with IPreset

use of org.eclipse.wst.common.project.facet.core.IPreset in project webtools.sourceediting by eclipse.

the class NewProjectDataModelFacetWizard method createPageControls.

@Override
public void createPageControls(Composite container) {
    super.createPageControls(container);
    final IPreset preset = this.template.getInitialPreset();
    final IRuntime runtime = (IRuntime) model.getProperty(FACET_RUNTIME);
    if (preset == null) {
        // If no preset is specified, select the runtime and it's default
        // facets.
        setRuntimeAndDefaultFacets(runtime);
    } else {
        // If preset is specified, select the runtime only if supports all
        // of the facets included in the preset.
        getFacetedProjectWorkingCopy().setSelectedPreset(preset.getId());
        boolean supports = false;
        if (runtime != null) {
            supports = true;
            for (Iterator itr = preset.getProjectFacets().iterator(); itr.hasNext(); ) {
                final IProjectFacetVersion fv = (IProjectFacetVersion) itr.next();
                if (!runtime.supports(fv)) {
                    supports = false;
                    break;
                }
            }
        }
        if (supports) {
            getFacetedProjectWorkingCopy().setTargetedRuntimes(Collections.singleton(runtime));
        } else {
            model.setProperty(FACET_RUNTIME, null);
        }
    }
    synchRuntimes();
}
Also used : IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) IPreset(org.eclipse.wst.common.project.facet.core.IPreset) Iterator(java.util.Iterator) IRuntime(org.eclipse.wst.common.project.facet.core.runtime.IRuntime)

Example 3 with IPreset

use of org.eclipse.wst.common.project.facet.core.IPreset in project webtools.sourceediting by eclipse.

the class DataModelFacetCreationWizardPage method createPresetPanel.

protected void createPresetPanel(Composite top) {
    final IFacetedProjectWorkingCopy workingCopy = ((ModifyFacetedProjectWizard) getWizard()).getFacetedProjectWorkingCopy();
    final IFilter<IPreset> filter = new AbstractFilter<IPreset>() {

        {
            IFacetedProjectListener fpjwcListenerForPreset = new IFacetedProjectListener() {

                @Override
                public void handleEvent(final IFacetedProjectEvent event) {
                    handleProjectFacetsChangedEvent((IProjectFacetsChangedEvent) event);
                }
            };
            facetedProjectListeners.add(fpjwcListenerForPreset);
            workingCopy.addListener(fpjwcListenerForPreset, IFacetedProjectEvent.Type.PROJECT_FACETS_CHANGED);
        }

        @Override
        public boolean check(final IPreset preset) {
            final IProjectFacetVersion primaryFacetVersion = getPrimaryFacetVersion();
            return preset.getProjectFacets().contains(primaryFacetVersion);
        }

        private void handleProjectFacetsChangedEvent(final IProjectFacetsChangedEvent event) {
            for (IProjectFacetVersion fv : event.getFacetsWithChangedVersions()) {
                if (fv.getProjectFacet() == getPrimaryFacet()) {
                    final IFilterEvent<IPreset> filterEvent = new FilterEvent<IPreset>(this, IFilterEvent.Type.FILTER_CHANGED);
                    notifyListeners(filterEvent);
                }
            }
        }
    };
    final PresetSelectionPanel ppanel = new PresetSelectionPanel(top, workingCopy, filter);
    ppanel.setLayoutData(gdhfill());
}
Also used : IFacetedProjectListener(org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener) FilterEvent(org.eclipse.wst.common.project.facet.core.util.FilterEvent) AbstractFilter(org.eclipse.wst.common.project.facet.core.util.AbstractFilter) IFacetedProjectEvent(org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) ModifyFacetedProjectWizard(org.eclipse.wst.common.project.facet.ui.ModifyFacetedProjectWizard) IProjectFacetsChangedEvent(org.eclipse.wst.common.project.facet.core.events.IProjectFacetsChangedEvent) PresetSelectionPanel(org.eclipse.wst.common.project.facet.ui.PresetSelectionPanel) IPreset(org.eclipse.wst.common.project.facet.core.IPreset) IFacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy)

Example 4 with IPreset

use of org.eclipse.wst.common.project.facet.core.IPreset in project liferay-ide by liferay.

the class SDKPluginFacetUtil method configureProjectAsSDKProject.

public static void configureProjectAsSDKProject(IFacetedProjectWorkingCopy fpjwc, String pluginType, String sdkLocation, ProjectRecord projectRecord) throws CoreException {
    IFacetedProjectTemplate template = getLiferayTemplateForProject(pluginType);
    IPreset preset = getLiferayPresetForProject(pluginType);
    if (preset == null) {
        throw new CoreException(ProjectCore.createErrorStatus(NLS.bind(Msgs.noFacetPreset, fpjwc.getProjectName())));
    }
    IRuntime primaryRuntime = fpjwc.getPrimaryRuntime();
    if (primaryRuntime != null) {
        fpjwc.removeTargetedRuntime(primaryRuntime);
    }
    Set<IProjectFacetVersion> currentProjectFacetVersions = fpjwc.getProjectFacets();
    Set<IProjectFacet> requiredFacets = template.getFixedProjectFacets();
    for (IProjectFacet requiredFacet : requiredFacets) {
        boolean hasRequiredFacet = false;
        for (IProjectFacetVersion currentFacetVersion : currentProjectFacetVersions) {
            if (currentFacetVersion.getProjectFacet().equals(requiredFacet)) {
                // TODO how to check the bundle support status?
                boolean requiredVersion = _isRequiredVersion(currentFacetVersion);
                if (requiredVersion) {
                    hasRequiredFacet = true;
                } else {
                    fpjwc.removeProjectFacet(currentFacetVersion);
                }
                break;
            }
        }
        if (!hasRequiredFacet) {
            IProjectFacetVersion requiredFacetVersion = _getRequiredFacetVersionFromPreset(requiredFacet, preset);
            if (requiredFacetVersion != null) {
                fpjwc.addProjectFacet(requiredFacetVersion);
                if (ProjectUtil.isJavaFacet(requiredFacetVersion)) {
                    configureJavaFacet(fpjwc, requiredFacetVersion.getProjectFacet(), preset, projectRecord);
                } else if (ProjectUtil.isDynamicWebFacet(requiredFacetVersion)) {
                    configureWebFacet(fpjwc, requiredFacetVersion.getProjectFacet(), preset);
                }
            }
        } else {
            if (ProjectUtil.isJavaFacet(requiredFacet)) {
                configureJavaFacet(fpjwc, requiredFacet, preset, projectRecord);
            } else if (ProjectUtil.isDynamicWebFacet(requiredFacet)) {
                configureWebFacet(fpjwc, requiredFacet, preset);
            }
        }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) IFacetedProjectTemplate(org.eclipse.wst.common.project.facet.core.IFacetedProjectTemplate) IPreset(org.eclipse.wst.common.project.facet.core.IPreset) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) IRuntime(org.eclipse.wst.common.project.facet.core.runtime.IRuntime)

Aggregations

IPreset (org.eclipse.wst.common.project.facet.core.IPreset)4 IProjectFacetVersion (org.eclipse.wst.common.project.facet.core.IProjectFacetVersion)4 CoreException (org.eclipse.core.runtime.CoreException)2 IFacetedProjectTemplate (org.eclipse.wst.common.project.facet.core.IFacetedProjectTemplate)2 IProjectFacet (org.eclipse.wst.common.project.facet.core.IProjectFacet)2 IRuntime (org.eclipse.wst.common.project.facet.core.runtime.IRuntime)2 Iterator (java.util.Iterator)1 IFacetedProjectWorkingCopy (org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy)1 IFacetedProjectEvent (org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent)1 IFacetedProjectListener (org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener)1 IProjectFacetsChangedEvent (org.eclipse.wst.common.project.facet.core.events.IProjectFacetsChangedEvent)1 AbstractFilter (org.eclipse.wst.common.project.facet.core.util.AbstractFilter)1 FilterEvent (org.eclipse.wst.common.project.facet.core.util.FilterEvent)1 ModifyFacetedProjectWizard (org.eclipse.wst.common.project.facet.ui.ModifyFacetedProjectWizard)1 PresetSelectionPanel (org.eclipse.wst.common.project.facet.ui.PresetSelectionPanel)1