Java Code Examples for org.eclipse.core.resources.IResource#getParent()

The following examples show how to use org.eclipse.core.resources.IResource#getParent() . 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: LocalResource.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check whether any of the resources parent does not have svn status IGNORED present in cache.
 * @return true if there's parent with IGNORED status in cache, false otherwise
 * @throws SVNException
 */
protected boolean isParentInSvnIgnore() throws SVNException
{
	StatusCacheManager cacheMgr = SVNProviderPlugin.getPlugin().getStatusCacheManager();
	IResource parent = resource.getParent();
	
	//Traverse up to the first parent with status present in cache
   	while ((parent != null) && !cacheMgr.hasCachedStatus(parent)) {
   		parent = parent.getParent();
   	}
   	//Check if the first parent with status has status IGNORED
   	if (parent != null) {
   		LocalResourceStatus status = cacheMgr.getStatusFromCache(parent);
   		if ((status != null) && (SVNStatusKind.IGNORED.equals(status.getTextStatus()))) {
   			return true;
   		}
   	}
   	//It's not under svn:ignore (at least according to cached statuses)
	return false;
}
 
Example 2
Source File: PropertyConflict.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public static String getConflictSummary(ISVNLocalResource svnResource) throws Exception {
	String conflictSummary = null;
	IResource resource = svnResource.getResource();
	IResource conflictFile = null;
	if (resource instanceof IContainer) {
		conflictFile = ((IContainer)resource).getFile(new Path("dir_conflicts.prej"));
	} else {
		IContainer parent = resource.getParent();
		if (parent != null) {
			conflictFile = parent.getFile(new Path(resource.getName() + ".prej"));
		}
	}	
	if (conflictFile != null && conflictFile.exists()) {
		conflictSummary = getConflictFileContents(new File(conflictFile.getLocation().toString()));
	}
	return conflictSummary;
}
 
Example 3
Source File: ResourceSelectionTree.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private IContainer[] getFolders() {
	List rootList = new ArrayList();
	if (folders == null) {
		folderList = new ArrayList();
		for (int i = 0; i < resources.length; i++) {
			if (resources[i] instanceof IContainer) folderList.add(resources[i]);
			IResource parent = resources[i];
			while (parent != null && !(parent instanceof IWorkspaceRoot)) {
				if (!(parent.getParent() instanceof IWorkspaceRoot) && folderList.contains(parent.getParent())) break;
				if (parent.getParent() == null || parent.getParent() instanceof IWorkspaceRoot) {
					rootList.add(parent);
				}
				parent = parent.getParent();
				folderList.add(parent);
			}
		}
		folders = new IContainer[folderList.size()];
		folderList.toArray(folders);
		Arrays.sort(folders, comparator);
		rootFolders = new IContainer[rootList.size()];
		rootList.toArray(rootFolders);
		Arrays.sort(rootFolders, comparator);
	}
	return folders;
}
 
Example 4
Source File: ResourceSelectionTree.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private void updateParentState(IResource child, boolean baseChildState) {
	if (mode == MODE_FLAT || child == null || child.getParent() == null || resourceList.contains(child.getParent())) {
		return;
	}
	CheckboxTreeViewer checkboxTreeViewer = (CheckboxTreeViewer)treeViewer;
	if (child == null) return;
	Object parent = resourceSelectionContentProvider.getParent(child);
	if (parent == null) return;
	boolean allSameState = true;
	Object[] children = null;
	children = resourceSelectionContentProvider.getChildren(parent);
	for (int i = children.length - 1; i >= 0; i--) {
		if (checkboxTreeViewer.getChecked(children[i]) != baseChildState || checkboxTreeViewer.getGrayed(children[i])) {
		   allSameState = false;
	       break;
		}
	}
	checkboxTreeViewer.setGrayed(parent, !allSameState);
	checkboxTreeViewer.setChecked(parent, !allSameState || baseChildState);
	updateParentState((IResource)parent, baseChildState);
}
 
Example 5
Source File: NewNameQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IInputValidator createResourceNameValidator(final IResource res){
	IInputValidator validator= new IInputValidator(){
		public String isValid(String newText) {
			if (newText == null || "".equals(newText) || res.getParent() == null) //$NON-NLS-1$
				return INVALID_NAME_NO_MESSAGE;
			if (res.getParent().findMember(newText) != null)
				return ReorgMessages.ReorgQueries_resourceWithThisNameAlreadyExists;
			if (! res.getParent().getFullPath().isValidSegment(newText))
				return ReorgMessages.ReorgQueries_invalidNameMessage;
			IStatus status= res.getParent().getWorkspace().validateName(newText, res.getType());
			if (status.getSeverity() == IStatus.ERROR)
				return status.getMessage();

			if (res.getName().equalsIgnoreCase(newText))
				return ReorgMessages.ReorgQueries_resourceExistsWithDifferentCaseMassage;

			return null;
		}
	};
	return validator;
}
 
Example 6
Source File: DotnetDebugLaunchShortcut.java    From aCute with Eclipse Public License 2.0 5 votes vote down vote up
private ILaunchConfiguration getLaunchConfiguration(IResource resource) {
	final String mode = "debug"; //$NON-NLS-1$
	ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
	ILaunchConfigurationType configType = launchManager
			.getLaunchConfigurationType(DotnetDebugLaunchDelegate.ID);
	try {
		ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(configType);

		String configName;
		if (resource.getLocation().toFile().isFile()) {
			configName = NLS.bind(Messages.DotnetRunDelegate_configuration, resource.getParent().getName() + "." + resource.getName()); //$NON-NLS-1$
		} else {
			configName = NLS.bind(Messages.DotnetRunDelegate_configuration, resource.getName());
		}

		for (ILaunchConfiguration iLaunchConfiguration : launchConfigurations) {
			if (iLaunchConfiguration.getName().equals(configName)
					&& iLaunchConfiguration.getModes().contains(mode)) {
				return iLaunchConfiguration;
			}
		}
		configName = launchManager.generateLaunchConfigurationName(configName);
		ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, configName);
		if (resource.getLocation().toFile().isFile()) {
			resource = resource.getParent();
		}
		wc.setAttribute(DotnetRunDelegate.PROJECT_FOLDER, resource.getFullPath().toString());
		DebuggerInfo info = DebuggersRegistry.getDefaultDebugger();
		wc.setAttribute(DSPPlugin.ATTR_DSP_CMD, info.debugger.getAbsolutePath());
		wc.setAttribute(DSPPlugin.ATTR_DSP_ARGS, info.args);
		return wc;
	} catch (CoreException e) {
		AcutePlugin.logError(e);
	}
	return null;
}
 
Example 7
Source File: SvnWizardCommitPage.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private boolean isChild(IResource resource, IContainer folder) {
	IContainer container = resource.getParent();
	while (container != null) {
		if (container.getFullPath().toString().equals(folder.getFullPath().toString()))
			return true;
		container = container.getParent();
	}
	return false;
}
 
Example 8
Source File: JarWriter3.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates the directory entries for the given path and writes it to the
 * current archive.
 *
 * @param resource
 *            the resource for which the parent directories are to be added
 * @param destinationPath
 *            the path to add
 *
 * @throws IOException
 *             if an I/O error has occurred
 * @throws CoreException
 *             if accessing the resource failes
 */
protected void addDirectories(IResource resource, IPath destinationPath) throws IOException, CoreException {
	IContainer parent= null;
	String path= destinationPath.toString().replace(File.separatorChar, '/');
	int lastSlash= path.lastIndexOf('/');
	List<JarEntry> directories= new ArrayList<JarEntry>(2);
	while (lastSlash != -1) {
		path= path.substring(0, lastSlash + 1);
		if (!fDirectories.add(path))
			break;

		parent= resource.getParent();
		long timeStamp= System.currentTimeMillis();
		URI location= parent.getLocationURI();
		if (location != null) {
			IFileInfo info= EFS.getStore(location).fetchInfo();
			if (info.exists())
				timeStamp= info.getLastModified();
		}

		JarEntry newEntry= new JarEntry(path);
		newEntry.setMethod(ZipEntry.STORED);
		newEntry.setSize(0);
		newEntry.setCrc(0);
		newEntry.setTime(timeStamp);
		directories.add(newEntry);

		lastSlash= path.lastIndexOf('/', lastSlash - 1);
	}

	for (int i= directories.size() - 1; i >= 0; --i) {
		fJarOutputStream.putNextEntry(directories.get(i));
	}
}
 
Example 9
Source File: GenerateDiffFileSynchronizeOperation.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private boolean isDupe(IResource resource) {
	IResource parent = resource;
	while (parent != null) {
		parent = parent.getParent();
		if (unaddedList.contains(parent)) return true;
	}
	return false;
}
 
Example 10
Source File: SVNWorkspaceRoot.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return true when a resource is a SVN "meta" resource.
 * I.e. .svn dir or any file within it.
 * @param resource
 * @return
 */
public static boolean isSvnMetaResource(IResource resource)
{
	if ((resource.getType() == IResource.FOLDER) && (SVNProviderPlugin.getPlugin().isAdminDirectory(resource.getName())))
		return true;

       IResource parent = resource.getParent();
       if (parent == null) {
           return false;
       }
       else
       {
       	return isSvnMetaResource(parent);
       }
}
 
Example 11
Source File: WorkspaceAction.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private boolean needsToSave(IFile file, IResource[] selectedResources) {
	if (file != null) {
		IResource parent = file;
		while (parent != null) {
			for (IResource selectedResource : selectedResources) {
				if (selectedResource.equals(parent)) {
					return true;
				}
			}
			parent = parent.getParent();
		}
	}
	return false;
}
 
Example 12
Source File: DotnetTestDelegate.java    From aCute with Eclipse Public License 2.0 5 votes vote down vote up
private ILaunchConfiguration getLaunchConfiguration(String mode, IResource resource) {
	ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
	ILaunchConfigurationType configType = launchManager
			.getLaunchConfigurationType("org.eclipse.acute.dotnettest.DotnetTestDelegate"); //$NON-NLS-1$
	try {
		ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(configType);

		String configName;
		if (resource.getLocation().toFile().isFile()) {
			configName = NLS.bind(Messages.DotnetTestDelegate_configuration, resource.getParent().getName() + "." + resource.getName()); //$NON-NLS-1$
		} else {
			configName = NLS.bind(Messages.DotnetTestDelegate_configuration, resource.getName());
		}

		for (ILaunchConfiguration iLaunchConfiguration : launchConfigurations) {
			if (iLaunchConfiguration.getName().equals(configName)
					&& iLaunchConfiguration.getModes().contains(mode)) {
				return iLaunchConfiguration;
			}
		}
		configName = launchManager.generateLaunchConfigurationName(configName);
		ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, configName);
		if (resource.getLocation().toFile().isFile()) {
			if (resource.getFileExtension().equals("cs")) { //$NON-NLS-1$
				wc.setAttribute(TEST_SELECTION_TYPE, SELECTED_TEST);
				wc.setAttribute(TEST_CLASS, resource.getName().replaceFirst("\\.cs$", "")); //$NON-NLS-1$ //$NON-NLS-2$
			}
			resource = resource.getParent();
		}
		wc.setAttribute(DebugPlugin.ATTR_WORKING_DIRECTORY, resource.getLocation().toString());

		return wc;
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 13
Source File: WorkbenchResourceUtil.java    From typescript.java with MIT License 4 votes vote down vote up
private static IContainer getContainer(IResource resource) {
	if (resource instanceof IContainer) {
		return (IContainer) resource;
	}
	return resource.getParent();
}
 
Example 14
Source File: CoreModelWizard.java    From ifml-editor with MIT License 4 votes vote down vote up
/**
 * The framework calls this to create the contents of the wizard. <!--
 * begin-user-doc --> <!-- end-user-doc -->
 * 
 * @generated
 */
@Override
public void addPages() {
	// Create a page, set the title, and the initial model file name.
	//
	newFileCreationPage = new CoreModelWizardNewFileCreationPage(
			"Whatever", selection);
	newFileCreationPage.setTitle(IFMLMetamodelEditorPlugin.INSTANCE
			.getString("_UI_CoreModelWizard_label"));
	newFileCreationPage.setDescription(IFMLMetamodelEditorPlugin.INSTANCE
			.getString("_UI_CoreModelWizard_description"));
	newFileCreationPage.setFileName(IFMLMetamodelEditorPlugin.INSTANCE
			.getString("_UI_CoreEditorFilenameDefaultBase")
			+ "."
			+ FILE_EXTENSIONS.get(0));
	addPage(newFileCreationPage);

	// Try and get the resource selection to determine a current directory
	// for the file dialog.
	//
	if (selection != null && !selection.isEmpty()) {
		// Get the resource...
		//
		Object selectedElement = selection.iterator().next();
		if (selectedElement instanceof IResource) {
			// Get the resource parent, if its a file.
			//
			IResource selectedResource = (IResource) selectedElement;
			if (selectedResource.getType() == IResource.FILE) {
				selectedResource = selectedResource.getParent();
			}

			// This gives us a directory...
			//
			if (selectedResource instanceof IFolder
					|| selectedResource instanceof IProject) {
				// Set this for the container.
				//
				newFileCreationPage.setContainerFullPath(selectedResource
						.getFullPath());

				// Make up a unique new name here.
				//
				String defaultModelBaseFilename = IFMLMetamodelEditorPlugin.INSTANCE
						.getString("_UI_CoreEditorFilenameDefaultBase");
				String defaultModelFilenameExtension = FILE_EXTENSIONS
						.get(0);
				String modelFilename = defaultModelBaseFilename + "."
						+ defaultModelFilenameExtension;
				for (int i = 1; ((IContainer) selectedResource)
						.findMember(modelFilename) != null; ++i) {
					modelFilename = defaultModelBaseFilename + i + "."
							+ defaultModelFilenameExtension;
				}
				newFileCreationPage.setFileName(modelFilename);
			}
		}
	}
	// initialObjectCreationPage = new
	// CoreModelWizardInitialObjectCreationPage("Whatever2");
	// initialObjectCreationPage.setTitle(IFMLMetamodelEditorPlugin.INSTANCE.getString("_UI_CoreModelWizard_label"));
	// initialObjectCreationPage.setDescription(IFMLMetamodelEditorPlugin.INSTANCE.getString("_UI_Wizard_initial_object_description"));
	// addPage(initialObjectCreationPage);

	newUMLImportPage = new UMLModelWizardPage();
	addPage(newUMLImportPage);
}
 
Example 15
Source File: RecipeModelWizard.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * The framework calls this to create the contents of the wizard.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * 
 * @generated
 */
@Override
public void addPages ()
{
    // Create a page, set the title, and the initial model file name.
    //
    this.newFileCreationPage = new RecipeModelWizardNewFileCreationPage ( "Whatever", this.selection ); //$NON-NLS-1$
    this.newFileCreationPage.setTitle ( RecipeEditorPlugin.INSTANCE.getString ( "_UI_RecipeModelWizard_label" ) ); //$NON-NLS-1$
    this.newFileCreationPage.setDescription ( RecipeEditorPlugin.INSTANCE.getString ( "_UI_RecipeModelWizard_description" ) ); //$NON-NLS-1$
    this.newFileCreationPage.setFileName ( RecipeEditorPlugin.INSTANCE.getString ( "_UI_RecipeEditorFilenameDefaultBase" ) + "." + FILE_EXTENSIONS.get ( 0 ) ); //$NON-NLS-1$ //$NON-NLS-2$
    addPage ( this.newFileCreationPage );

    // Try and get the resource selection to determine a current directory for the file dialog.
    //
    if ( this.selection != null && !this.selection.isEmpty () )
    {
        // Get the resource...
        //
        final Object selectedElement = this.selection.iterator ().next ();
        if ( selectedElement instanceof IResource )
        {
            // Get the resource parent, if its a file.
            //
            IResource selectedResource = (IResource)selectedElement;
            if ( selectedResource.getType () == IResource.FILE )
            {
                selectedResource = selectedResource.getParent ();
            }

            // This gives us a directory...
            //
            if ( selectedResource instanceof IFolder || selectedResource instanceof IProject )
            {
                // Set this for the container.
                //
                this.newFileCreationPage.setContainerFullPath ( selectedResource.getFullPath () );

                // Make up a unique new name here.
                //
                final String defaultModelBaseFilename = RecipeEditorPlugin.INSTANCE.getString ( "_UI_RecipeEditorFilenameDefaultBase" ); //$NON-NLS-1$
                final String defaultModelFilenameExtension = FILE_EXTENSIONS.get ( 0 );
                String modelFilename = defaultModelBaseFilename + "." + defaultModelFilenameExtension; //$NON-NLS-1$
                for ( int i = 1; ( (IContainer)selectedResource ).findMember ( modelFilename ) != null; ++i )
                {
                    modelFilename = defaultModelBaseFilename + i + "." + defaultModelFilenameExtension; //$NON-NLS-1$
                }
                this.newFileCreationPage.setFileName ( modelFilename );
            }
        }
    }
    this.initialObjectCreationPage = new RecipeModelWizardInitialObjectCreationPage ( "Whatever2" ); //$NON-NLS-1$
    this.initialObjectCreationPage.setTitle ( RecipeEditorPlugin.INSTANCE.getString ( "_UI_RecipeModelWizard_label" ) ); //$NON-NLS-1$
    this.initialObjectCreationPage.setDescription ( RecipeEditorPlugin.INSTANCE.getString ( "_UI_Wizard_initial_object_description" ) ); //$NON-NLS-1$
    addPage ( this.initialObjectCreationPage );
}
 
Example 16
Source File: PythonModelProvider.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Converts elements to the python model -- but only creates it if it's parent is found in the python model
 */
protected boolean convertToPythonElementsUpdateOrRefresh(Set<Object> currentChildren) {
    final Map<PythonNature, Set<String>> natureToSourcePathSet = new HashMap<>();
    LinkedHashSet<Object> convertedChildren = new LinkedHashSet<>();
    for (Iterator<Object> childrenItr = currentChildren.iterator(); childrenItr.hasNext();) {
        Object child = childrenItr.next();

        if (child == null) {
            //only case when a child is removed and another one is not added (null)
            childrenItr.remove();
            continue;
        }

        if (child instanceof IResource && !(child instanceof IWrappedResource)) {
            IResource res = (IResource) child;

            Object resourceInPythonModel = getResourceInPythonModel(res, true);
            if (resourceInPythonModel != null) {
                //if it is in the python model, just go on
                childrenItr.remove();
                convertedChildren.add(resourceInPythonModel);

            } else {
                //now, if it's not but its parent is, go on and create it
                IContainer p = res.getParent();
                if (p == null) {
                    continue;
                }

                Object pythonParent = getResourceInPythonModel(p, true);
                if (pythonParent instanceof IWrappedResource) {
                    IWrappedResource parent = (IWrappedResource) pythonParent;

                    if (res instanceof IProject) {
                        throw new RuntimeException("A project's parent should never be an IWrappedResource!");

                    } else if (res instanceof IFolder) {
                        childrenItr.remove();
                        convertedChildren.add(new PythonFolder(parent, (IFolder) res, parent.getSourceFolder()));

                    } else if (res instanceof IFile) {
                        childrenItr.remove();
                        convertedChildren.add(new PythonFile(parent, (IFile) res, parent.getSourceFolder()));

                    } else if (child instanceof IResource) {
                        childrenItr.remove();
                        convertedChildren.add(new PythonResource(parent, (IResource) child, parent
                                .getSourceFolder()));
                    }

                } else if (res instanceof IFolder) {
                    //ok, still not in the model... could it be a PythonSourceFolder
                    IFolder folder = (IFolder) res;
                    IProject project = folder.getProject();
                    if (project == null) {
                        continue;
                    }
                    PythonNature nature = PythonNature.getPythonNature(project);
                    if (nature == null) {
                        continue;
                    }

                    Set<String> sourcePathSet = this.getSourcePathSet(natureToSourcePathSet, nature);

                    PythonSourceFolder wrapped = tryWrapSourceFolder(p, folder, sourcePathSet);
                    if (wrapped != null) {
                        childrenItr.remove();
                        convertedChildren.add(wrapped);
                    }
                }
            }
        }
    }
    if (!convertedChildren.isEmpty()) {
        currentChildren.addAll(convertedChildren);
        return true;
    }
    return false;

}
 
Example 17
Source File: FileUtils.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Makes sure that the parent directories of the given {@linkplain IResource resource} exist.
 *
 * @throws CoreException
 */
public static void mkdirs(final IResource resource) throws CoreException {

  final List<IFolder> parents = new ArrayList<IFolder>();

  IContainer parent = resource.getParent();

  while (parent != null && parent.getType() == IResource.FOLDER) {
    if (parent.exists()) break;

    parents.add((IFolder) parent);
    parent = parent.getParent();
  }

  Collections.reverse(parents);

  for (final IFolder folder : parents) folder.create(false, true, null);
}
 
Example 18
Source File: BeansModelWizard.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * The framework calls this to create the contents of the wizard.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
	@Override
public void addPages() {
	// Create a page, set the title, and the initial model file name.
	//
	newFileCreationPage = new BeansModelWizardNewFileCreationPage("Whatever", selection);
	newFileCreationPage.setTitle(BeansEditorPlugin.INSTANCE.getString("_UI_BeansModelWizard_label"));
	newFileCreationPage.setDescription(BeansEditorPlugin.INSTANCE.getString("_UI_BeansModelWizard_description"));
	newFileCreationPage.setFileName(BeansEditorPlugin.INSTANCE.getString("_UI_BeansEditorFilenameDefaultBase") + "." + FILE_EXTENSIONS.get(0));
	addPage(newFileCreationPage);

	// Try and get the resource selection to determine a current directory for the file dialog.
	//
	if (selection != null && !selection.isEmpty()) {
		// Get the resource...
		//
		Object selectedElement = selection.iterator().next();
		if (selectedElement instanceof IResource) {
			// Get the resource parent, if its a file.
			//
			IResource selectedResource = (IResource)selectedElement;
			if (selectedResource.getType() == IResource.FILE) {
				selectedResource = selectedResource.getParent();
			}

			// This gives us a directory...
			//
			if (selectedResource instanceof IFolder || selectedResource instanceof IProject) {
				// Set this for the container.
				//
				newFileCreationPage.setContainerFullPath(selectedResource.getFullPath());

				// Make up a unique new name here.
				//
				String defaultModelBaseFilename = BeansEditorPlugin.INSTANCE.getString("_UI_BeansEditorFilenameDefaultBase");
				String defaultModelFilenameExtension = FILE_EXTENSIONS.get(0);
				String modelFilename = defaultModelBaseFilename + "." + defaultModelFilenameExtension;
				for (int i = 1; ((IContainer)selectedResource).findMember(modelFilename) != null; ++i) {
					modelFilename = defaultModelBaseFilename + i + "." + defaultModelFilenameExtension;
				}
				newFileCreationPage.setFileName(modelFilename);
			}
		}
	}
	typeSelectionPage = new BeansModelWizardTypeSelectionPage("TypeSelection");
	typeSelectionPage.setTitle(BeansEditorPlugin.INSTANCE.getString("_UI_BeansModelWizard_label"));
	typeSelectionPage.setDescription(BeansEditorPlugin.INSTANCE.getString("_UI_Wizard_type_selection_description"));
	addPage(typeSelectionPage);
}
 
Example 19
Source File: ItemModelWizard.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * The framework calls this to create the contents of the wizard.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void addPages ()
{
    // Create a page, set the title, and the initial model file name.
    //
    newFileCreationPage = new ItemModelWizardNewFileCreationPage ( "Whatever", selection ); //$NON-NLS-1$
    newFileCreationPage.setTitle ( ItemEditorPlugin.INSTANCE.getString ( "_UI_ItemModelWizard_label" ) ); //$NON-NLS-1$
    newFileCreationPage.setDescription ( ItemEditorPlugin.INSTANCE.getString ( "_UI_ItemModelWizard_description" ) ); //$NON-NLS-1$
    newFileCreationPage.setFileName ( ItemEditorPlugin.INSTANCE.getString ( "_UI_ItemEditorFilenameDefaultBase" ) + "." + FILE_EXTENSIONS.get ( 0 ) ); //$NON-NLS-1$ //$NON-NLS-2$
    addPage ( newFileCreationPage );

    // Try and get the resource selection to determine a current directory for the file dialog.
    //
    if ( selection != null && !selection.isEmpty () )
    {
        // Get the resource...
        //
        Object selectedElement = selection.iterator ().next ();
        if ( selectedElement instanceof IResource )
        {
            // Get the resource parent, if its a file.
            //
            IResource selectedResource = (IResource)selectedElement;
            if ( selectedResource.getType () == IResource.FILE )
            {
                selectedResource = selectedResource.getParent ();
            }

            // This gives us a directory...
            //
            if ( selectedResource instanceof IFolder || selectedResource instanceof IProject )
            {
                // Set this for the container.
                //
                newFileCreationPage.setContainerFullPath ( selectedResource.getFullPath () );

                // Make up a unique new name here.
                //
                String defaultModelBaseFilename = ItemEditorPlugin.INSTANCE.getString ( "_UI_ItemEditorFilenameDefaultBase" ); //$NON-NLS-1$
                String defaultModelFilenameExtension = FILE_EXTENSIONS.get ( 0 );
                String modelFilename = defaultModelBaseFilename + "." + defaultModelFilenameExtension; //$NON-NLS-1$
                for ( int i = 1; ( (IContainer)selectedResource ).findMember ( modelFilename ) != null; ++i )
                {
                    modelFilename = defaultModelBaseFilename + i + "." + defaultModelFilenameExtension; //$NON-NLS-1$
                }
                newFileCreationPage.setFileName ( modelFilename );
            }
        }
    }
    initialObjectCreationPage = new ItemModelWizardInitialObjectCreationPage ( "Whatever2" ); //$NON-NLS-1$
    initialObjectCreationPage.setTitle ( ItemEditorPlugin.INSTANCE.getString ( "_UI_ItemModelWizard_label" ) ); //$NON-NLS-1$
    initialObjectCreationPage.setDescription ( ItemEditorPlugin.INSTANCE.getString ( "_UI_Wizard_initial_object_description" ) ); //$NON-NLS-1$
    addPage ( initialObjectCreationPage );
}
 
Example 20
Source File: CopyFilesAndFoldersOperation.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Checks whether the destination is valid for copying the source resources.
 * <p>
 * Note this method is for internal use only. It is not API.
 * </p>
 *
 * @param destination
 *            the destination container
 * @param sourceResources
 *            the source resources
 * @return an error message, or <code>null</code> if the path is valid
 */
public String validateDestination(IContainer destination, IResource[] sourceResources) {
    if (!isAccessible(destination)) {
        return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_destinationAccessError;
    }
    IContainer firstParent = null;
    URI destinationLocation = destination.getLocationURI();
    for (int i = 0; i < sourceResources.length; i++) {
        IResource sourceResource = sourceResources[i];
        if (firstParent == null) {
            firstParent = sourceResource.getParent();
        } else if (firstParent.equals(sourceResource.getParent()) == false) {
            // Resources must have common parent. Fixes bug 33398.
            return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_parentNotEqual;
        }

        URI sourceLocation = sourceResource.getLocationURI();
        if (sourceLocation == null) {
            if (sourceResource.isLinked()) {
                // Don't allow copying linked resources with undefined path
                // variables. See bug 28754.
                return NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_missingPathVariable,
                        sourceResource.getName());
            }
            return NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceDeleted,
                    sourceResource.getName());

        }
        if (sourceLocation.equals(destinationLocation)) {
            return NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_sameSourceAndDest,
                    sourceResource.getName());
        }
        // is the source a parent of the destination?
        if (new Path(sourceLocation.toString()).isPrefixOf(new Path(destinationLocation.toString()))) {
            return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_destinationDescendentError;
        }

        String linkedResourceMessage = validateLinkedResource(destination, sourceResource);
        if (linkedResourceMessage != null) {
            return linkedResourceMessage;
        }
    }
    return null;
}