Java Code Examples for org.eclipse.core.resources.IProject#isOpen()

The following examples show how to use org.eclipse.core.resources.IProject#isOpen() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectInfoForPackageExplorer.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return the information on a project. Can create it if it's not available.
 */
public static ProjectInfoForPackageExplorer getProjectInfo(final IProject project) {
    if (project == null) {
        return null;
    }
    synchronized (lockProjectToSourceFolders) {
        ProjectInfoForPackageExplorer projectInfo = projectToSourceFolders.get(project);
        if (projectInfo == null) {
            if (!project.isOpen()) {
                return null;
            }
            //No project info: create it
            projectInfo = projectToSourceFolders.get(project);
            if (projectInfo == null) {
                projectInfo = new ProjectInfoForPackageExplorer(project);
                projectToSourceFolders.put(project, projectInfo);
            }
        } else {
            if (!project.isOpen()) {
                projectToSourceFolders.remove(project);
                projectInfo = null;
            }
        }
        return projectInfo;
    }
}
 
Example 2
Source File: ProjectModulesManager.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param project the project for which we want references.
 * @param referenced whether we want to get the referenced projects or the ones referencing this one.
 * @param memo (out) this is the place where all the projects will e available.
 *
 * Note: the project itself will not be added.
 */
private static void getProjectsRecursively(IProject project, boolean referenced, HashSet<IProject> memo) {
    IProject[] projects = null;
    try {
        if (project == null || !project.isOpen() || !project.exists()) {
            return;
        }
        if (referenced) {
            projects = project.getReferencedProjects();
        } else {
            projects = project.getReferencingProjects();
        }
    } catch (CoreException e) {
        //ignore (it's closed)
    }

    if (projects != null) {
        for (IProject p : projects) {
            if (!memo.contains(p)) {
                memo.add(p);
                getProjectsRecursively(p, referenced, memo);
            }
        }
    }
}
 
Example 3
Source File: WebUtils.java    From developer-studio with Apache License 2.0 6 votes vote down vote up
public static boolean isDynamicWebProject(IProject containerProject) {
	boolean isWebProject = false;
	try {
		if (containerProject.isOpen()) {
			for (String natureId : containerProject.getDescription().getNatureIds()) {
				isWebProject = natureId.startsWith("org.eclipse.wst");
				if (isWebProject) {
					break;
				}
			}
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return isWebProject;
}
 
Example 4
Source File: TexlipseProjectCreationOperation.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create the project directory.
 * If the user has specified an external project location,
 * the project is created with a custom description for the location.
 * 
 * @param project project
 * @param monitor progress monitor
 * @throws CoreException
 */
private void createProject(IProject project, IProgressMonitor monitor)
        throws CoreException {

    monitor.subTask(TexlipsePlugin.getResourceString("projectWizardProgressDirectory"));
    
    if (!project.exists()) {
        if (attributes.getProjectLocation() != null) {
            IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName());
            IPath projectPath = new Path(attributes.getProjectLocation());
            IStatus stat = ResourcesPlugin.getWorkspace().validateProjectLocation(project, projectPath);
            if (stat.getSeverity() != IStatus.OK) {
                // should not happen. the location should have been checked in the wizard page
                throw new CoreException(stat);
            }
            desc.setLocation(projectPath);
            project.create(desc, monitor);
        } else {
            project.create(monitor);
        }
    }
    if (!project.isOpen()) {
        project.open(monitor);
    }
}
 
Example 5
Source File: XdsModel.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public XdsProject getXdsProjectBy(IProject p) {
    IProjectNature nature;
    try {
        nature = p.isOpen() ? p.getNature(NatureIdRegistry.MODULA2_SOURCE_PROJECT_NATURE_ID) : null;
        if (nature == null){
            return null;
        }
    } catch (CoreException e) {
        LogHelper.logError(e);
        return null;
    }
    Lock readLock = instanceLock.readLock();
    try{
    	readLock.lock();
    	return name2XdsProject.get(p.getName());
    }
    finally {
    	readLock.unlock();
    }
}
 
Example 6
Source File: BuildPathsPropertyPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Control createContents(Composite parent) {
	// ensure the page has no special buttons
	noDefaultAndApplyButton();

	IProject project= getProject();
	Control result;
	if (project == null || !isJavaProject(project)) {
		result= createWithoutJava(parent);
	} else if (!project.isOpen()) {
		result= createForClosedProject(parent);
	} else {
		result= createWithJava(parent, project);
	}
	Dialog.applyDialogFont(result);
	return result;
}
 
Example 7
Source File: YangProjectSupport.java    From yang-design-studio with Eclipse Public License 1.0 6 votes vote down vote up
private static IProject createBaseProject(String projectName, URI location)
{
  IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
  if (!newProject.exists())
  {
    URI projectLocation = location;
    IProjectDescription desc = newProject.getWorkspace().newProjectDescription(newProject.getName());
    if ((location != null) && (ResourcesPlugin.getWorkspace().getRoot().getLocationURI().equals(location))) {
      projectLocation = null;
    }
    desc.setLocationURI(projectLocation);
    try
    {
      newProject.create(desc, null);
      if (!newProject.isOpen()) {
        newProject.open(null);
      }
    }
    catch (CoreException e)
    {
      e.printStackTrace();
    }
  }
  System.out.println("returning project");
  return newProject;
}
 
Example 8
Source File: ActivateProjectsAction.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {

  for (IProject configurationTarget : mProjectsToActivate) {

    if (configurationTarget.isOpen()
            && !configurationTarget.hasNature(CheckstyleNature.NATURE_ID)) {

      ConfigureDeconfigureNatureJob job = new ConfigureDeconfigureNatureJob(configurationTarget,
              CheckstyleNature.NATURE_ID);
      job.schedule();
    }
  }

  return Status.OK_STATUS;
}
 
Example 9
Source File: CrySLParser.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
public CrySLParser(IProject iProject) throws CoreException, IOException {
	final Injector injector = CrySLActivator.getInstance().getInjector(CrySLActivator.DE_DARMSTADT_TU_CROSSING_CRYSL);
	resourceSet = injector.getInstance(XtextResourceSet.class);

	if (iProject == null) {
		// if no project selected abort with error message
		iProject = Utils.complileListOfJavaProjectsInWorkspace().get(0);
	}
	if (iProject.isOpen()) {
		resourceSet.setClasspathURIContext(JavaCore.create(iProject));
	}
	new JdtTypeProviderFactory(injector.getInstance(IJavaProjectProvider.class)).createTypeProvider(resourceSet);

	resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
}
 
Example 10
Source File: NewProjectCreator.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private static void openProject(IProject project) {
    if (!project.isOpen()) {
        try {
            project.open(null);
        } catch (CoreException e) {
            LogHelper.logError(e);
        }
    }
}
 
Example 11
Source File: DerbyServerUtils.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void stopDerbyServer( IProject proj) throws CoreException, ClassNotFoundException, SQLException {
	String args = CommonNames.SHUTDOWN_DERBY_SERVER;
	String vmargs="";
	DerbyProperties dprop=new DerbyProperties(proj);
	args+=" -h "+dprop.getHost()+ " -p "+dprop.getPort();
	
	//	Set Derby System Home from the Derby Properties
	if((dprop.getSystemHome()!=null)&& !(dprop.getSystemHome().equals(""))){
		vmargs=CommonNames.D_SYSTEM_HOME+dprop.getSystemHome();
	}
	String procName="["+proj.getName()+"] - "+CommonNames.DERBY_SERVER+" "+CommonNames.SHUTDOWN_DERBY_SERVER+" ("+dprop.getHost()+ ", "+dprop.getPort()+")";
	
	// starts the server as a Java app
	ILaunch launch = DerbyUtils.launch(proj, procName,
	CommonNames.DERBY_SERVER_CLASS, args, vmargs,CommonNames.SHUTDOWN_DERBY_SERVER);
	IProcess ip=launch.getProcesses()[0];
	
	//set a name to be seen in the Console list
	ip.setAttribute(IProcess.ATTR_PROCESS_LABEL,procName);
	
	//update the objectState
	setRunning(proj, Boolean.FALSE);
	if(proj.isOpen()){
		Shell shell = new Shell();
		MessageDialog.openInformation(
		shell,
		CommonNames.PLUGIN_NAME,
		Messages.D_NS_ATTEMPT_STOPPED+dprop.getPort()+"." );
	}
}
 
Example 12
Source File: ResourceSelectionComposite.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
  if (element instanceof IFile || element instanceof IFolder) {
    return true;
  } else if (element instanceof IProject) {
    IProject project = (IProject) element;
    return project.isOpen();
  }
  return false;
}
 
Example 13
Source File: ResourceUtils.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static IProject getProjectFromMemberLocation(Location fileLocation) {
	IFile[] files = getWorkspaceRoot().findFilesForLocationURI(fileLocation.toUri());
	
	for (IFile file : files) {
		IProject project = file.getProject();
		if(project.exists() && project.isOpen()) {
			return project;
		}
	}
	
	return null;
}
 
Example 14
Source File: ExportUtil.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
/**
 * Carbon application builder
 * 
 * @param project
 * @return
 * @throws Exception
 */
public static IResource buildCAppProject(IProject project) throws Exception {
	List<IResource> buildProject = new ArrayList<IResource>();
	if (!project.isOpen()) {
		throw new Exception("\"" + project.getName() + "\" project is not open!");
	}
	if (project.hasNature("org.wso2.developerstudio.eclipse.distribution.project.nature")) {
		buildProject = ExportUtil.buildProject(project, "carbon/application");
	} else {
		throw new Exception("\"" + project.getName() + "\" project is not a carbon application project");
	}
	return buildProject.get(0);
}
 
Example 15
Source File: HybridProjectConvertTest.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void createBaseProject() throws CoreException{
    
    IProject newProject = getTheProject();
    
    if ( !newProject.exists() ){
        IProjectDescription description = newProject.getWorkspace().newProjectDescription(PROJECT_NAME);
        
        newProject.create(description, new NullProgressMonitor());
        if( !newProject.isOpen() ){
            newProject.open(new NullProgressMonitor());
        }
    }
}
 
Example 16
Source File: ArtifactProjectDeleteParticipant.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
/**
 * This method gets executed before the refactoring gets executed on
 * original file which means this method is executed before the actual
 * project is deleted from the workspace. If you have any task need to run
 * before the project is deleted, you need to generate Changes for those
 * tasks in this method.
 */
@Override
public Change createPreChange(IProgressMonitor arg0) throws CoreException, OperationCanceledException {

	CompositeChange deleteChange = new CompositeChange("Delete Artifact Project");

	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();

	for (IProject project : projects) {
		if (project.isOpen() && project.hasNature("org.wso2.developerstudio.eclipse.distribution.project.nature")) {
			try {
				IFile pomFile = project.getFile(POM_XML);
				MavenProject mavenProject = ProjectRefactorUtils.getMavenProject(project);
				Dependency projectDependency = ProjectRefactorUtils.getDependencyForTheProject(originalProject);
				if (mavenProject != null) {
					List<?> dependencies = mavenProject.getDependencies();
					if (projectDependency != null) {
						for (Iterator<?> iterator = dependencies.iterator(); iterator.hasNext();) {
							Dependency dependency = (Dependency) iterator.next();
							if (ProjectRefactorUtils.isDependenciesEqual(projectDependency, dependency)) {
								deleteChange.add(new MavenConfigurationFileDeleteChange(project.getName(), pomFile,
								                                                        originalProject));
							}
						}
					}
				}
			} catch (Exception e) {
				log.error("Error occured while trying to generate the Refactoring", e);
			}
		}
	}

	return deleteChange;
}
 
Example 17
Source File: OpenResourceAction.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The <code>OpenResourceAction</code> implementation of this <code>SelectionListenerAction</code> method ensures
 * that this action is enabled only if one of the selections is a closed project.
 */
@Override
protected boolean updateSelection(final IStructuredSelection s) {
	// don't call super since we want to enable if closed project is
	// selected.

	if (!selectionIsOfType(IResource.PROJECT)) { return false; }

	final Iterator<?> resources = getSelectedResources().iterator();
	while (resources.hasNext()) {
		final IProject currentResource = (IProject) resources.next();
		if (!currentResource.isOpen()) { return true; }
	}
	return false;
}
 
Example 18
Source File: ResourcesWatcher.java    From typescript.java with MIT License 4 votes vote down vote up
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
	IResource resource = delta.getResource();
	if (resource == null) {
		return false;
	}
	switch (resource.getType()) {
	case IResource.ROOT:
		return true;
	case IResource.PROJECT:
		IProject project = (IProject) resource;
		if (project.isOpen() && delta.getKind() == IResourceDelta.CHANGED
                   && ((delta.getFlags() & IResourceDelta.OPEN) != 0)) {
			// System.err.println("Open");
		}
		// Continue if project has defined file listeners.
		return fileListeners.containsKey(resource);
	case IResource.FOLDER:
		return true;
	case IResource.FILE:
		IFile file = (IFile) resource;
		synchronized (fileListeners) {
			Map<String, List<IFileWatcherListener>> listenersForFilename = fileListeners.get(file.getProject());
			List<IFileWatcherListener> listeners = listenersForFilename.get(file.getName());
			if (listeners != null) {
				for (IFileWatcherListener listener : listeners) {
					switch (delta.getKind()) {
					case IResourceDelta.ADDED:							
						// handle added resource
						listener.onAdded(file);
						break;
					case IResourceDelta.REMOVED:
						// handle removed resource
						listener.onDeleted(file);
						break;
					default:
						listener.onChanged(file);
					}
				}
			}
		}
		return false;
	}
	return false;
}
 
Example 19
Source File: ProjectNaturesPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Control createContents(Composite parent)
{
	Composite composite = new Composite(parent, SWT.NONE);
	composite.setLayout(new GridLayout());
	composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

	fProject = (IProject) getElement().getAdapter(IResource.class);
	try
	{
		if (fProject.isOpen())
		{
			// Can only access decription if project exists and is open...
			fCurrentProjectNatures = fProject.getDescription().getNatureIds();
		}
		else
		{
			fCurrentProjectNatures = new String[0];
		}
	}
	catch (CoreException e)
	{
		IdeLog.logError(UIEplPlugin.getDefault(), EplMessages.ProjectNaturesPage_ERR_RetrieveNatures, e);
		fCurrentProjectNatures = new String[0];
	}
	fLabelProvider = new NaturesLabelProvider(fNatureDescriptions);

	// assumes the first one in the array is the primary nature
	fInitialPrimaryNature = fCurrentProjectNatures.length == 0 ? null : fCurrentProjectNatures[0];
	updatePrimaryNature(fInitialPrimaryNature);

	setDescription(MessageFormat.format(EplMessages.ProjectNaturesPage_Description, fProject.getName()));
	Label description = createDescriptionLabel(composite);
	description.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

	Composite tableComposite = new Composite(composite, SWT.NONE);
	tableComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
	tableComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

	fTableViewer = CheckboxTableViewer.newCheckList(tableComposite, SWT.TOP | SWT.BORDER);
	Table table = fTableViewer.getTable();
	table.setLinesVisible(true);
	table.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

	TableColumn column = new TableColumn(table, SWT.LEFT);
	column.setWidth(350);

	fTableViewer.setContentProvider(getContentProvider());
	fTableViewer.setLabelProvider(getLabelProvider());
	fTableViewer.setComparator(getViewerComperator());
	fTableViewer.setInput(fProject.getWorkspace());
	if (!fProject.isAccessible())
	{
		fTableViewer.getControl().setEnabled(false);
	}
	fTableViewer.setCheckedElements(fCurrentProjectNatures);
	fTableViewer.addCheckStateListener(this);
	fTableViewer.addSelectionChangedListener(new ISelectionChangedListener()
	{
		public void selectionChanged(SelectionChangedEvent event)
		{
			updateButtons();
		}
	});
	fInitialCheckedItems = fTableViewer.getCheckedElements();
	table.setMenu(createMenu(table));

	// Add the buttons
	Composite buttons = new Composite(tableComposite, SWT.NONE);
	buttons.setLayout(GridLayoutFactory.fillDefaults().create());
	buttons.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create());
	fMakePrimaryButton = createButton(EplMessages.ProjectNaturesPage_LBL_MakePrimary, buttons);
	updateButtons();

	noDefaultAndApplyButton();

	return composite;
}
 
Example 20
Source File: Core.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This private operation configures the project area for the Core. It uses
 * the Eclipse Resources Plugin and behaves differently based on the value
 * of the osgi.instance.area system property.
 * </p>
 * <!-- end-UML-doc -->
 *
 * @return True if the setup operation was successful and false otherwise.
 */
private boolean setupProjectLocation() {

	// Local Declarations
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	IProject project = null;
	boolean status = true;
	String defaultProjectName = "itemDB";

	// Print some diagnostic information
	if (Platform.getInstanceLocation() != null) {
		logger.info("ICore Message: Default workspace location is "
				+ Platform.getInstanceLocation().getURL().toString());
	}
	// Create the project space for the *default* user. This will have to
	// change to something more efficient and better managed when multi-user
	// support is added.
	try {
		// Get the project handle
		project = workspaceRoot.getProject(defaultProjectName);
		// If the project does not exist, create it
		if (!project.exists()) {
			// Create the project description
			IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(defaultProjectName);
			// Create the project
			project.create(desc, null);
		}

		// Open the project if it is not already open. Note that this is not
		// an "else if" because it always needs to be checked.
		if (project.exists() && !project.isOpen()) {
			project.open(null);
			// Always refresh the project too in case users manipulated the
			// files.
			project.refreshLocal(IResource.DEPTH_INFINITE, null);
		}
		// Add the project to the master table
		projectTable.put("defaultUser", project);
		itemDBProject = project;
	} catch (CoreException e) {
		// Catch for creating the project
		logger.error(getClass().getName() + " Exception!", e);
		status = false;
	}

	// Load any SerializedItems that are stored in the default directory
	if (status) {
		status = loadDefaultAreaItems();
	}
	return status;
}