Search in sources :

Example 1 with IProjectFacetActionEvent

use of org.eclipse.wst.common.project.facet.core.events.IProjectFacetActionEvent in project jbosstools-hibernate by jbosstools.

the class JPAPostInstallFasetListener method handleEvent.

public void handleEvent(IFacetedProjectEvent event) {
    if (event.getType() == Type.POST_INSTALL) {
        IProject project = event.getProject().getProject();
        IProjectFacetActionEvent pEvent = (IProjectFacetActionEvent) event;
        if (pEvent.getProjectFacet().getId().equals(JpaProject.FACET_ID)) {
            String platformId = HibernateEclipseUtils.getJpaPlatformID(project);
            if (platformId != null && (platformId.equals(HibernateJpaPlatform.HIBERNATE_PLATFORM_ID) || platformId.equals(HibernateJpaPlatform.HIBERNATE2_0_PLATFORM_ID) || platformId.equals(HibernateJpaPlatform.HIBERNATE2_1_PLATFORM_ID))) {
                if (checkPreConditions(project)) {
                    exportConnectionProfilePropertiesToPersistenceXml(project);
                    buildConsoleConfiguration(project, platformId);
                }
            }
        }
    }
}
Also used : IProjectFacetActionEvent(org.eclipse.wst.common.project.facet.core.events.IProjectFacetActionEvent) IProject(org.eclipse.core.resources.IProject)

Example 2 with IProjectFacetActionEvent

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

the class LiferayFacetedProjectListener method handleEvent.

public void handleEvent(IFacetedProjectEvent event) {
    if (event.getType() != IFacetedProjectEvent.Type.POST_INSTALL) {
        return;
    }
    IProjectFacetActionEvent actionEvent = (IProjectFacetActionEvent) event;
    if (!JSDT_FACET.equals(actionEvent.getProjectFacet().getId())) {
        return;
    }
    Job uninstall = new WorkspaceJob("uninstall jsdt facet") {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            try {
                IFacetedProject fProject = actionEvent.getProject();
                Set<IProjectFacet> fixedFacets = fProject.getFixedProjectFacets();
                Set<IProjectFacet> updatedFacets = new HashSet<>();
                for (IProjectFacet f : fixedFacets) {
                    if (!JSDT_FACET.equals(f.getId())) {
                        updatedFacets.add(f);
                    }
                }
                fProject.setFixedProjectFacets(updatedFacets);
            } catch (Exception e) {
                ProjectCore.logError("Unable to removed fixed jsdt facet", e);
            }
            try {
                Set<Action> actions = new HashSet<>();
                Type type = Type.valueOf("uninstall");
                Action uninstallJsdt = new Action(type, actionEvent.getProjectFacetVersion(), null);
                actions.add(uninstallJsdt);
                actionEvent.getProject().modify(actions, monitor);
                // try to remove unneeded jsdt files
                IProject project = actionEvent.getProject().getProject();
                IFile jsdtscope = project.getFile(".settings/.jsdtscope");
                if (FileUtil.exists(jsdtscope)) {
                    jsdtscope.delete(true, monitor);
                }
                IFile container = project.getFile(".settings/org.eclipse.wst.jsdt.ui.superType.container");
                if (FileUtil.exists(container)) {
                    container.delete(true, monitor);
                }
                IFile name = project.getFile(".settings/org.eclipse.wst.jsdt.ui.superType.name");
                if (FileUtil.exists(name)) {
                    name.delete(true, monitor);
                }
            } catch (CoreException ce) {
                ProjectCore.logError("Unable to uninstall jsdt facet", ce);
            }
            return Status.OK_STATUS;
        }
    };
    uninstall.schedule();
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) Action(org.eclipse.wst.common.project.facet.core.IFacetedProject.Action) IFile(org.eclipse.core.resources.IFile) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) IProjectFacetActionEvent(org.eclipse.wst.common.project.facet.core.events.IProjectFacetActionEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Type(org.eclipse.wst.common.project.facet.core.IFacetedProject.Action.Type) CoreException(org.eclipse.core.runtime.CoreException) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) HashSet(java.util.HashSet)

Aggregations

IProject (org.eclipse.core.resources.IProject)2 IProjectFacetActionEvent (org.eclipse.wst.common.project.facet.core.events.IProjectFacetActionEvent)2 HashSet (java.util.HashSet)1 IFile (org.eclipse.core.resources.IFile)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 IFacetedProject (org.eclipse.wst.common.project.facet.core.IFacetedProject)1 Action (org.eclipse.wst.common.project.facet.core.IFacetedProject.Action)1 Type (org.eclipse.wst.common.project.facet.core.IFacetedProject.Action.Type)1 IProjectFacet (org.eclipse.wst.common.project.facet.core.IProjectFacet)1