Java Code Examples for org.eclipse.core.resources.IContainer

The following are top voted examples for showing how to use org.eclipse.core.resources.IContainer. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: gw4e.project   File: ResourceManager.java   View source code 7 votes vote down vote up
/**
 * @param folder
 * @param filetorefresh
 * @return
 * @throws CoreException
 * @throws InterruptedException
 */
public static IResource resfreshFileInContainer(IContainer folder, String filetorefresh)
		throws CoreException, InterruptedException {
	final IResource buildfile = find(folder, filetorefresh);
	Job job = new WorkspaceJob("Refresh folders") {
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			if (buildfile != null && buildfile.exists()) {
				try {
					buildfile.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
				} catch (CoreException e) {
					ResourceManager.logException(e);
				}
			}
			return Status.OK_STATUS;
		}
	};
	job.setUser(true);
	job.schedule();

	return buildfile;
}
 
Example 2
Project: n4js   File: ModuleSpecifierSelectionDialog.java   View source code 6 votes vote down vote up
/**
 * Create the dialog.
 *
 * <p>
 * Note: The model should have a valid source folder path as this is the root folder for this browse dialog. If the
 * source folder path doesn't exist yet this dialog will be empty.
 * </p>
 *
 * @param parent
 *            Parent Shell  
 * @param sourceFolder
 *            The source folder to browse in for modules and module folders
 *
 *
 */
public ModuleSpecifierSelectionDialog(Shell parent, IPath sourceFolder) {
	super(parent, MODULE_ELEMENT_NAME, CREATE_FOLDER_LABEL);
	this.setTitle("Select a module");

	this.setInputValidator(inputValidator);

	IPath parentPath = sourceFolder.removeLastSegments(1);
	IContainer sourceFolderParent = containerForPath(parentPath);
	IFolder workspaceSourceFolder = workspaceRoot
			.getFolder(sourceFolder);

	// Use parent of source folder as root to show source folder itself in the tree
	this.treeRoot = sourceFolderParent;

	this.sourceFolder = workspaceSourceFolder;
	this.addFilter(new ModuleFolderFilter(this.sourceFolder.getFullPath()));

	this.setAutoExpandLevel(2);
	// Show the status line above the buttons
	this.setStatusLineAboveButtons(true);
}
 
Example 3
Project: VerveineC-Cpp   File: FileUtil.java   View source code 6 votes vote down vote up
private static void mkdirs(IFolder destPath) {
	IContainer parent = destPath.getParent(); 
	if (! parent.exists()) {
		if (parent instanceof IFolder) {
			mkdirs((IFolder) parent);
		}
		else if (parent instanceof IProject) {
			mkdirs( ((IProject)parent).getFolder(".") );
		}
	}
	try {
		destPath.create(/*force*/true, /*local*/true, Constants.NULL_PROGRESS_MONITOR);
	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example 4
Project: n4js   File: CleanInstruction.java   View source code 6 votes vote down vote up
private void cleanOutput(IProject aProject, OutputConfiguration config, IProgressMonitor monitor)
		throws CoreException {
	IContainer container = getContainer(aProject, config.getOutputDirectory());
	if (!container.exists()) {
		return;
	}
	if (config.isCanClearOutputDirectory()) {
		for (IResource resource : container.members()) {
			resource.delete(IResource.KEEP_HISTORY, monitor);
		}
	} else if (config.isCleanUpDerivedResources()) {
		List<IFile> resources = derivedResourceMarkers.findDerivedResources(container, null);
		for (IFile iFile : resources) {
			iFile.delete(IResource.KEEP_HISTORY, monitor);
		}
	}
}
 
Example 5
Project: n4js   File: N4JSBuilderParticipant.java   View source code 6 votes vote down vote up
@Override
protected Map<OutputConfiguration, Iterable<IMarker>> getGeneratorMarkers(IProject builtProject,
		Collection<OutputConfiguration> outputConfigurations) throws CoreException {

	if (builtProject instanceof ExternalProject) {
		return emptyMap();
	}

	Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers = newHashMap();
	for (OutputConfiguration config : outputConfigurations) {
		if (config.isCleanUpDerivedResources()) {
			List<IMarker> markers = Lists.newArrayList();
			for (IContainer container : getOutputs(builtProject, config)) {
				Iterables.addAll(
						markers,
						getDerivedResourceMarkers().findDerivedResourceMarkers(container,
								getGeneratorIdProvider().getGeneratorIdentifier()));
			}
			generatorMarkers.put(config, markers);
		}
	}
	return generatorMarkers;
}
 
Example 6
Project: n4js   File: TestConfigurationConverter.java   View source code 6 votes vote down vote up
/**
 * Converts a {@link TestConfiguration} to an {@link ILaunchConfiguration}. Will throw a {@link WrappedException} in
 * case of error.
 *
 * @see TestConfiguration#readPersistentValues()
 */
public ILaunchConfiguration toLaunchConfiguration(ILaunchConfigurationType type, TestConfiguration testConfig) {
	try {
		final ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager()
				.getLaunchConfigurations(type);

		for (ILaunchConfiguration config : configs) {
			if (equals(testConfig, config))
				return config;
		}

		final IContainer container = null;
		final ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(container, testConfig.getName());

		workingCopy.setAttributes(testConfig.readPersistentValues());

		return workingCopy.doSave();
	} catch (Exception e) {
		throw new WrappedException("could not convert N4JS TestConfiguration to Eclipse ILaunchConfiguration", e);
	}
}
 
Example 7
Project: n4js   File: RunConfigurationConverter.java   View source code 6 votes vote down vote up
/**
 * Converts a {@link RunConfiguration} to an {@link ILaunchConfiguration}. Will throw a {@link WrappedException} in
 * case of error.
 *
 * @see RunConfiguration#readPersistentValues()
 */
public ILaunchConfiguration toLaunchConfiguration(ILaunchConfigurationType type, RunConfiguration runConfig) {
	try {
		final ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager()
				.getLaunchConfigurations(type);

		for (ILaunchConfiguration config : configs) {
			if (equals(runConfig, config))
				return config;
		}

		final IContainer container = null;
		final ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(container, runConfig.getName());

		workingCopy.setAttributes(runConfig.readPersistentValues());

		return workingCopy.doSave();
	} catch (Exception e) {
		throw new WrappedException("could not convert N4JS RunConfiguration to Eclipse ILaunchConfiguration", e);
	}
}
 
Example 8
Project: ec4e   File: NewEditorConfigWizard.java   View source code 6 votes vote down vote up
/**
 * Returns the content of the .editorconfig file to generate.
 *
 * @param container
 *
 * @return the content of the .editorconfig file to generate.
 */
private InputStream openContentStream(IContainer container) {
	IPreferenceStore store = EditorsUI.getPreferenceStore();
	boolean spacesForTabs = store.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS);
	int tabWidth = store.getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH);
	String lineDelimiter = getLineDelimiter(container);
	String endOfLine = org.ec4j.core.model.PropertyType.EndOfLineValue.ofEndOfLineString(lineDelimiter).name();

	StringBuilder content = new StringBuilder("# EditorConfig is awesome: http://EditorConfig.org");
	content.append(lineDelimiter);
	content.append(lineDelimiter);
	content.append("[*]");
	content.append(lineDelimiter);
	content.append("indent_style = ");
	content.append(spacesForTabs ? "space" : "tab");
	content.append(lineDelimiter);
	content.append("indent_size = ");
	content.append(tabWidth);
	if (endOfLine != null) {
		content.append(lineDelimiter);
		content.append("end_of_line = ");
		content.append(endOfLine);
	}

	return new ByteArrayInputStream(content.toString().getBytes());
}
 
Example 9
Project: neoscada   File: LaunchShortcut.java   View source code 6 votes vote down vote up
private void addJvmOptions ( final ILaunchConfigurationWorkingCopy cfg, final Profile profile, final IContainer container ) throws CoreException
{
    final List<String> args = new LinkedList<> ();

    args.addAll ( profile.getJvmArguments () );

    for ( final SystemProperty p : profile.getProperty () )
    {
        addSystemProperty ( profile, args, p.getKey (), p.getValue (), p.isEval () );
    }

    for ( final Map.Entry<String, String> entry : getInitialProperties ().entrySet () )
    {
        addSystemProperty ( profile, args, entry.getKey (), entry.getValue (), false );
    }

    final IFile dataJson = container.getFile ( new Path ( "data.json" ) ); //$NON-NLS-1$
    if ( dataJson.exists () )
    {
        addJvmArg ( args, "org.eclipse.scada.ca.file.provisionJsonUrl", escapeArgValue ( dataJson.getLocation ().toFile ().toURI ().toString () ) ); //$NON-NLS-1$
    }

    cfg.setAttribute ( IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, StringHelper.join ( args, "\n" ) );
    cfg.setAttribute ( IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, StringHelper.join ( profile.getArguments (), "\n" ) );
}
 
Example 10
Project: neoscada   File: RecipeHelper.java   View source code 6 votes vote down vote up
public static void processFile ( final IContainer parent, final Definition definition, final Profile profile, final IProgressMonitor monitor ) throws Exception
{
    monitor.beginTask ( makeJobLabel ( definition, profile ), 100 );

    final IFolder output = parent.getFolder ( new Path ( "output" ) ); //$NON-NLS-1$
    if ( output.exists () )
    {
        output.delete ( true, new SubProgressMonitor ( monitor, 9 ) );
    }
    output.create ( true, true, new SubProgressMonitor ( monitor, 1 ) );

    final Builder builder = new Builder ( definition, profile );
    final Recipe recipe = builder.build ();

    try
    {
        final Map<String, Object> initialContent = new HashMap<String, Object> ();
        initialContent.put ( "output", output ); //$NON-NLS-1$

        recipe.execute ( initialContent, new SubProgressMonitor ( monitor, 90 ) );
    }
    finally
    {
        monitor.done ();
    }
}
 
Example 11
Project: gw4e.project   File: GraphWalkerFacade.java   View source code 6 votes vote down vote up
/**
 * Retrieve the graph models contained in the container
 * 
 * @param container
 * @param models
 * @throws CoreException
 */
public static void getGraphModels(IContainer container, List<IFile> models) throws CoreException {
	if (!container.exists())
		return;
	IResource[] members = container.members();
	for (IResource member : members) {
		if (member instanceof IContainer)
			getGraphModels((IContainer) member, models);
		else if (member instanceof IFile) {
			IFile file = (IFile) member;
			if (PreferenceManager.isGraphModelFile(file))
				models.add(file);
			if (PreferenceManager.isGW3ModelFile(file))
				models.add(file);
			if (PreferenceManager.isJSONModelFile(file))
				models.add(file);

		}
	}
}
 
Example 12
Project: gw4e.project   File: ResourceManager.java   View source code 6 votes vote down vote up
/**
 * Create a file in a folder with the specified name and content
 * 
 * @param fullpath
 * @param filename
 * @param content
 * @throws CoreException
 * @throws InterruptedException
 */
public static IFile createFileDeleteIfExists(String fullpath, String filename, String content,
		IProgressMonitor monitor) throws CoreException, InterruptedException {
	SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
	subMonitor.setTaskName("Create file delete if it exists " + fullpath);
	IFile newFile;
	try {
		IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot();
		IContainer container = (IContainer) wroot.findMember(new Path(fullpath));
		newFile = container.getFile(new Path(filename));
		if (newFile.exists()) {
			JDTManager.rename(newFile, new NullProgressMonitor());
			newFile.delete(true, new NullProgressMonitor());
		}
		subMonitor.split(30);
		byte[] source = content.getBytes(Charset.forName("UTF-8"));
		newFile.create(new ByteArrayInputStream(source), true, new NullProgressMonitor());
		subMonitor.split(70);
	} finally {
		subMonitor.done();
	}
	return newFile;
}
 
Example 13
Project: gw4e.project   File: ResourceManager.java   View source code 6 votes vote down vote up
/**
 * @param container
 * @param path
 * @return
 * @throws CoreException
 */
private static IFile processContainer(IContainer container, String path) throws CoreException {
	IResource[] members = container.members();
	for (IResource member : members) {
		if (member instanceof IContainer) {
			IFile file = processContainer((IContainer) member, path);
			if (file != null) {
				IPath p = ResourceManager.getPathWithinPackageFragment(file); // avoid
																				// file
																				// within
																				// classes
																				// directory
				if (p != null)
					return file;
			}
		} else if (member instanceof IFile) {
			IFile ifile = (IFile) member;
			if (ifile.getFullPath().toString().endsWith(path)) {
				return ifile;
			}
		}
	}
	return null;
}
 
Example 14
Project: gw4e.project   File: ResourceManager.java   View source code 6 votes vote down vote up
/**
 * @param container
 * @param files
 * @throws CoreException
 */
public static void getAllJUnitResultFiles(String projectName, List<IFile> files) throws CoreException {
	if (projectName == null)
		return;
	IContainer container = ResourceManager.getProject(projectName);
	container.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
	IResource[] members = container.members();
	for (IResource member : members) {
		if (member instanceof IFile) {
			IFile file = (IFile) member;
			if (isJUnitResultFile(file)) {
				files.add(file);
			}
		}
	}
}
 
Example 15
Project: gw4e.project   File: ResourceManager.java   View source code 6 votes vote down vote up
/**
 * Process recursively the containers until we found a resource with the
 * specified path
 * 
 * @param container
 * @param path
 * @return
 * @throws CoreException
 */
private static boolean resourceExistsIn(IContainer container, IPath path) throws CoreException {
	boolean found = false;
	IResource[] members = container.members();
	for (IResource member : members) {
		if (member instanceof IContainer) {

			found = resourceExistsIn((IContainer) member, path);
			if (found)
				break;
		} else if (member instanceof IFile) {
			IFile file = (IFile) member;

			if (path.equals(file.getFullPath()))
				return true;
		}
	}
	return found;
}
 
Example 16
Project: gw4e.project   File: BuildPoliciesCache.java   View source code 6 votes vote down vote up
/**
 * @param projectName
 * @param container
 * @param monitor
 */
private static void deleteCache(String cachename, IContainer container, IProgressMonitor monitor) {
	try {
		IResource[] members = container.members();
		for (IResource member : members) {
			if (member instanceof IContainer) {
				deleteCache(cachename, (IContainer) member, monitor);
			} else if (member instanceof IFile) {
				IFile file = (IFile) member;
				if (cachename.equals(file.getName())) {
					file.delete(true, monitor);
				}
			}
		}
	} catch (CoreException e) {
		ResourceManager.logException(e);
	}
}
 
Example 17
Project: gw4e.project   File: GW4EProject.java   View source code 6 votes vote down vote up
public static void cleanWorkspace() throws CoreException {
	IProject[] projects = getRoot().getProjects();
	deleteProjects(projects);
	IProject[] otherProjects = getRoot().getProjects(IContainer.INCLUDE_HIDDEN);
	deleteProjects(otherProjects);

	ILaunchConfigurationType configType = DebugPlugin.getDefault().getLaunchManager()
			.getLaunchConfigurationType(GW4ELaunchShortcut.GW4ELAUNCHCONFIGURATIONTYPE);
	ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager()
			.getLaunchConfigurations(configType);
	for (int i = 0; i < configs.length; i++) {
		ILaunchConfiguration config = configs[i];
		config.delete();
	}
	 
}
 
Example 18
Project: gw4e.project   File: ImportHelper.java   View source code 6 votes vote down vote up
public static void copyFiles(File srcFolder, IContainer destFolder) throws CoreException, FileNotFoundException {
	for (File f : srcFolder.listFiles()) {
		if (f.isDirectory()) {
			IFolder newFolder = destFolder.getFolder(new Path(f.getName()));
			newFolder.create(true, true, null);
			copyFiles(f, newFolder);
		} else {
			IFile newFile = destFolder.getFile(new Path(f.getName()));
			InputStream in = new FileInputStream(f);
			try {
				newFile.create(in, true, null);
			} finally {
				try {
					if (in != null)
						in.close();
				} catch (IOException e) {
				}
			}
		}
	}
}
 
Example 19
Project: n4js   File: AbstractBuilderParticipantTest.java   View source code 5 votes vote down vote up
/***/
protected void createParentFolder(IFolder folder) throws CoreException {
	IContainer parent = folder.getParent();
	if (parent instanceof IFolder) {
		IFolder parentFolder = (IFolder) parent;
		if (!parentFolder.exists()) {
			createParentFolder(parentFolder);
			parentFolder.create(true, true, null);
		}
	}
}
 
Example 20
Project: Tarski   File: LoadCompletionProcessor.java   View source code 5 votes vote down vote up
private void findAllEMFFiles(final IContainer container) throws CoreException {
  final IResource[] members = container.members();
  for (final IResource member : members) {
    if (member instanceof IContainer) {
      if (member.isAccessible()) {
        findAllEMFFiles((IContainer) member);
      }
    } else if (member instanceof IFile) {
      final IFile file = (IFile) member;
      if (file.getFileExtension().equals("ecore")) {
        allEcoreFiles.put(file.getName(), file);
      }
    }
  }
}
 
Example 21
Project: n4js   File: ModuleSpecifierSelectionDialog.java   View source code 5 votes vote down vote up
@Override
protected void computeResult() {

	Object selection = treeViewer.getStructuredSelection().getFirstElement();

	if (selection == null) {
		return;
	}

	String moduleName = elementNameInput.getText();
	String moduleFileExtension = elementNameInput.getSuffix();

	// For selected files where the element name input equals the selected file
	if (selection instanceof IFile
			&& ((IFile) selection).getFullPath().removeFileExtension().lastSegment().equals(moduleName)) {
		// Use the selected file's path as result
		IPath fileSpec = sourceFolderRelativePath((IResource) selection);
		this.setResult(Arrays.asList(fileSpec.toString()));
		return;
	} else if (selection instanceof IResource) {
		// For files with different element name input value, use their container as basepath
		if (selection instanceof IFile) {
			selection = ((IFile) selection).getParent();
		}

		IFile moduleFile = ((IContainer) selection).getFile(new Path(moduleName + moduleFileExtension));
		this.setResult(
				Arrays.asList(moduleFile.getFullPath().makeRelativeTo(sourceFolder.getFullPath()).toString()));

		return;
	} else {
		updateError("Invalid selection type.");
	}
}
 
Example 22
Project: Hydrograph   File: ExternalSchemaFileSelectionDialog.java   View source code 5 votes vote down vote up
public Object[] getChildren(Object element) {
    if (element instanceof IContainer) {
        try {
            return ((IContainer) element).members();
        }
        catch (CoreException e) {
        }
    }
    return null;
}
 
Example 23
Project: ec4e   File: NewEditorConfigWizard.java   View source code 5 votes vote down vote up
private static String getLineDelimiter(IContainer file) {
	String lineDelimiter = getLineDelimiterPreference(file);
	if (lineDelimiter == null) {
		lineDelimiter = System.getProperty("line.separator");
	}
	if (lineDelimiter != null) {
		return lineDelimiter;
	}
	return "\n";
}
 
Example 24
Project: n4js   File: WorkspaceWizardPage.java   View source code 5 votes vote down vote up
/**
 * This method should be invoked whenever source folder or project value change, to update the proposal contexts for
 * the field source folder and module specifier
 */
private void updateProposalContext() {
	IPath projectPath = model.getProject();
	IPath sourceFolderPath = model.getSourceFolder();

	// Early exit for empty project value
	if (projectPath.isEmpty()) {
		sourceFolderContentProposalAdapter.setContentProposalProvider(null);
		moduleSpecifierContentProposalAdapter.setContentProposalProvider(null);
		return;
	}

	IProject project = ResourcesPlugin.getWorkspace().getRoot()
			.getProject(projectPath.toString());

	if (null == project || !project.exists()) {
		// Disable source folder and module specifier proposals
		sourceFolderContentProposalAdapter.setContentProposalProvider(null);
		moduleSpecifierContentProposalAdapter.setContentProposalProvider(null);
	} else {
		// Try to retrieve the source folder and if not specified set it to null
		IContainer sourceFolder = sourceFolderPath.segmentCount() != 0 ? project.getFolder(sourceFolderPath) : null;

		// If the project exists, enable source folder proposals
		sourceFolderContentProposalAdapter
				.setContentProposalProvider(sourceFolderContentProviderFactory.createProviderForProject(project));

		if (null != sourceFolder && sourceFolder.exists()) {
			// If source folder exists as well enable module specifier proposal
			moduleSpecifierContentProposalAdapter.setContentProposalProvider(
					moduleSpecifierContentProviderFactory.createProviderForPath(sourceFolder.getFullPath()));
		} else {
			// Otherwise disable module specifier proposals
			moduleSpecifierContentProposalAdapter.setContentProposalProvider(null);
		}
	}
}
 
Example 25
Project: n4js   File: SelectionFilesCollector.java   View source code 5 votes vote down vote up
/** Dispatches based on provided element (can call itself recursively). */
private void collectRelevantFiles(Object element, Set<IFile> collected) {
	// order of type check matters!
	if (element instanceof IWorkingSet) {
		collectIAdaptable((IWorkingSet) element, collected);
	} else if (element instanceof IContainer) {
		collectResource((IContainer) element, collected);
	} else if (element instanceof IFile) {
		collectIFile((IFile) element, collected);
	} else {
		LOGGER.warn("Files collector ignores " + element.getClass().getName() + ".");
	}
}
 
Example 26
Project: n4js   File: SelectionFilesCollector.java   View source code 5 votes vote down vote up
private void collectResource(IContainer container, Set<IFile> collected) {
	try {
		IResource[] resources = container.members(IContainer.EXCLUDE_DERIVED);
		for (IResource resource : resources) {
			collectRelevantFiles(resource, collected);
		}
	} catch (CoreException c) {
		LOGGER.warn("Error while collecting files", c);
	}
}
 
Example 27
Project: n4js   File: N4JSEclipseModel.java   View source code 5 votes vote down vote up
@Override
protected IN4JSEclipseSourceContainer createProjectN4JSSourceContainer(N4JSProject project,
		SourceFragmentType type, String relativeLocation) {

	N4JSEclipseProject casted = (N4JSEclipseProject) project;
	IProject eclipseProject = casted.getProject();
	final IContainer container;
	if (".".equals(relativeLocation)) {
		container = eclipseProject;
	} else {
		container = eclipseProject.getFolder(relativeLocation);
	}
	return new EclipseSourceContainer(casted, type, container);
}
 
Example 28
Project: n4js   File: N4JSEclipseModel.java   View source code 5 votes vote down vote up
private boolean pathStartsWithFolder(IPath fullPath, IContainer container) {
	IPath containerPath = container.getFullPath();
	int maxSegments = containerPath.segmentCount();
	if (fullPath.segmentCount() >= maxSegments) {
		for (int j = 0; j < maxSegments; j++) {
			if (!fullPath.segment(j).equals(containerPath.segment(j))) {
				return false;
			}
		}
		return true;
	}
	return false;
}
 
Example 29
Project: ec4e   File: ContainerResourcePath.java   View source code 5 votes vote down vote up
@Override
public ResourcePath getParent() {
	if (container.getType() == IResource.PROJECT) {
		// Stop the search of  '.editorconfig' files in the parent container
		return null;
	}
	IContainer parent = container.getParent();
	return parent == null ? null : new ContainerResourcePath(parent);
}
 
Example 30
Project: n4js   File: AbstractExportToSingleFileWizardPage.java   View source code 5 votes vote down vote up
/**
 * Returns the name of a {@link IProject} with a location that includes targetDirectory. Returns null if there is no
 * such {@link IProject}.
 *
 * @param targetDirectory
 *            the path of the directory to check.
 * @return the overlapping project name or <code>null</code>
 */
private String getOverlappingProjectName(String targetDirectory) {
	IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
	IPath testPath = new Path(targetDirectory);
	IContainer[] containers = root.findContainersForLocationURI(testPath.makeAbsolute().toFile().toURI());
	if (containers.length > 0) {
		return containers[0].getProject().getName();
	}
	return null;
}
 
Example 31
Project: ide-plugins   File: ProjectUtils.java   View source code 5 votes vote down vote up
public ProjectUtils(IContainer project) {
    this.project = project;

    if (project != null && getGradleBuildFile(project) != null) {
        configure();
    }
    
}
 
Example 32
Project: ide-plugins   File: ProjectUtils.java   View source code 5 votes vote down vote up
public static IFile getGradleBuildFile(IContainer project) {
    IResource resource = project.findMember("build.gradle");
        if (resource != null && resource.exists()) {
            return (IFile) resource;
        }
        return null;
}
 
Example 33
Project: time4sys   File: NewModelWizard.java   View source code 5 votes vote down vote up
/**
 * Compute the name of the new Time4Sys model.
 *
 * @param selectedResource
 *            Selected resource
 * @return Name of the new Time4Sys model
 */
private String getNewModelName(IResource selectedResource) {
	final String defaultModelBaseFilename = "NewProject";
	String modelFilename = defaultModelBaseFilename + ".time4sys"; //$NON-NLS-1$
	for (int i = 1; ((IContainer) selectedResource).findMember(modelFilename) != null; ++i) {
		modelFilename = defaultModelBaseFilename + i + ".time4sys"; //$NON-NLS-1$
	}
	return modelFilename;
}
 
Example 34
Project: neoscada   File: ClientTemplate.java   View source code 5 votes vote down vote up
private void addResource ( final IProject project, final String name, final InputStream stream, final IProgressMonitor monitor ) throws CoreException
{
    try
    {
        final String[] toks = name.split ( "\\/" ); //$NON-NLS-1$
        IContainer container = project;
        for ( int i = 0; i < toks.length - 1; i++ )
        {
            final IFolder folder = container.getFolder ( new Path ( toks[i] ) );
            if ( !folder.exists () )
            {
                folder.create ( true, true, null );
            }
            container = folder;
        }
        final IFile file = project.getFile ( name );
        if ( file.exists () )
        {
            file.setContents ( stream, IResource.FORCE, monitor );
        }
        else
        {
            file.create ( stream, true, monitor );
        }
    }
    finally
    {
        try
        {
            stream.close ();
        }
        catch ( final IOException e )
        {
        }
    }
    monitor.done ();
}
 
Example 35
Project: pgcodekeeper   File: PgUIDumpLoader.java   View source code 5 votes vote down vote up
public static int countFiles(IContainer container) throws CoreException {
    int[] count = new int[1];
    container.accept(p -> {
        if (p.getType() == IResource.FILE) {
            ++count[0];
        }
        return true;
    }, 0);
    return count[0];
}
 
Example 36
Project: xmontiarc   File: DesignerHelper.java   View source code 5 votes vote down vote up
private static List<String> loadModels(IContainer container) throws CoreException {
	List<String> files = new ArrayList<String>();
	IResource[] members = container.members();
	for (IResource member : members) {
		if (member instanceof IContainer) {
			files.addAll(loadModels((IContainer) member));
		} else if (member instanceof IFile) {
			if (member.getFileExtension() != null && member.getFileExtension().equals("xmontiarc")) {
				String path = member.getFullPath().toOSString();
				files.add(path);
			}
		}
	}
	return files;
}
 
Example 37
Project: Tarski   File: LoadCompletionProcessor.java   View source code 5 votes vote down vote up
private void findAllXMIFiles(final IContainer container) throws CoreException {
  final IResource[] members = container.members();
  for (final IResource member : members) {
    if (member instanceof IContainer) {
      if (member.isAccessible()) {
        findAllXMIFiles((IContainer) member);
      }
    } else if (member instanceof IFile) {
      final IFile file = (IFile) member;
      allFiles.put(file.getName(), file);
    }
  }
}
 
Example 38
Project: neoscada   File: ProfilesContribution.java   View source code 5 votes vote down vote up
private void addDefinition ( final List<IContributionItem> items, final IContainer parent, final Definition def )
{
    items.add ( new DefinitionContributionItem ( parent, def ) );
    for ( final Profile p : def.getProfiles () )
    {
        items.add ( new ProfileContributionItem ( parent, def, p ) );
    }
}
 
Example 39
Project: gw4e.project   File: FolderSelectionGroup.java   View source code 5 votes vote down vote up
/**
 * @param container
 * @throws CoreException 
 */
public void setContainerFullPath(IProject project, IPath path) throws CoreException {
	IResource container = ResourceManager.getResource(path.toString());
	if (container==null)
		container = ResourceManager.ensureFolder(project, path.removeFirstSegments(1).toString(), new NullProgressMonitor());
	typeTreeViewer.refresh();
	selectedContainer=(IContainer)container;
	typeTreeViewer.expandToLevel(path, 1);
	typeTreeViewer.setSelection(new StructuredSelection(selectedContainer), true);
	fireEvent ();
}
 
Example 40
Project: gw4e.project   File: ResourceManager.java   View source code 5 votes vote down vote up
/**
 * @param container
 * @param files
 * @throws CoreException
 */
public static void getAllGraphFiles(IContainer container, List<IFile> files) throws CoreException {
	IResource[] members = container.members();
	for (IResource member : members) {
		if (member instanceof IContainer) {
			getAllGraphFiles((IContainer) member, files);
		} else if (member instanceof IFile) {
			IFile file = (IFile) member;
			if (PreferenceManager.isGraphModelFile(file))
				files.add(file);
		}
	}
}