List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getPath
IPath getPath();
From source file:com.iw.plugins.spindle.ui.wizards.fields.ContainerDialogField.java
License:Mozilla Public License
public void setPackageFragmentRoot(IPackageFragmentRoot root, boolean canBeModified) { IPackageFragmentRoot old = fCurrentRoot; fCurrentRoot = root;/*from w ww . ja v a2s.c om*/ String str = (root == null) ? "" : root.getPath().toString(); setTextValue(str); setEnabled(canBeModified); }
From source file:com.iw.plugins.spindle.ui.wizards.fields.PackageDialogField.java
License:Mozilla Public License
public IStatus packageChanged() { SpindleStatus status = new SpindleStatus(); checkButtonEnabled();// w ww . java 2 s. co m String packName = getTextValue(); if (!"".equals(packName)) { IStatus val = JavaConventions.validatePackageName(packName); if (val.getSeverity() == IStatus.ERROR) { status.setError(UIPlugin.getString(name + ".error.InvalidPackageName", val.getMessage())); return status; } else if (val.getSeverity() == IStatus.WARNING) { status.setWarning(UIPlugin.getString(name + ".warning.DiscouragedPackageName", val.getMessage())); // continue } } else { status.setError(UIPlugin.getString(name + ".error.defaultPackage")); return status; } IPackageFragmentRoot root; if (container == null) { root = null; } else { root = container.getPackageFragmentRoot(); } if (root != null) { IPackageFragment pack = root.getPackageFragment(packName); try { if (fSourcePackagesOnly && root.getKind() == IPackageFragmentRoot.K_BINARY) { status.setError(UIPlugin.getString(name + ".error.PackageMustBeSource")); return status; } IPath rootPath = root.getPath(); IPath outputPath = root.getJavaProject().getOutputLocation(); if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) { // if the bin folder is inside of our root, dont allow to name a // package // like the bin folder IPath packagePath = pack.getUnderlyingResource().getFullPath(); if (outputPath.isPrefixOf(packagePath)) { status.setError(UIPlugin.getString(name + ".error.ClashOutputLocation")); return status; } } } catch (JavaModelException e) { UIPlugin.log(e); // let pass } currentPackage = pack; if (currentPackage != null && nameField != null) { try { IContainer folder = (IContainer) getPackageFragment().getUnderlyingResource(); boolean isComponent = nameField.getKind() == AbstractNameField.COMPONENT_NAME; IFile file = folder .getFile(new Path(nameField.getTextValue() + (isComponent ? ".jwc" : ".page"))); if (file.exists()) { status.setError(UIPlugin.getString(name + ".error.ComponentAlreadyExists", file.getFullPath().toString())); return status; } } catch (JavaModelException e) { UIPlugin.log(e); } } } else { status.setError(""); } return status; }
From source file:com.iw.plugins.spindle.wizards.fields.ContainerDialogField.java
License:Mozilla Public License
public void setPackageFragmentRoot(IPackageFragmentRoot root, boolean canBeModified) { IPackageFragmentRoot old = currentRoot; currentRoot = root;/* w ww .j av a 2 s . co m*/ String str = (root == null) ? "" : root.getPath().toString(); setTextValue(str); setEnabled(canBeModified); }
From source file:com.iw.plugins.spindle.wizards.fields.PackageDialogField.java
License:Mozilla Public License
public IStatus packageChanged() { SpindleStatus status = new SpindleStatus(); checkButtonEnabled();/*from w w w . j a va2 s. c o m*/ String packName = getTextValue(); if (!"".equals(packName)) { IStatus val = JavaConventions.validatePackageName(packName); if (val.getSeverity() == IStatus.ERROR) { status.setError( MessageUtil.getFormattedString(name + ".error.InvalidPackageName", val.getMessage())); return status; } else if (val.getSeverity() == IStatus.WARNING) { status.setWarning( MessageUtil.getFormattedString(name + ".warning.DiscouragedPackageName", val.getMessage())); // continue } } else { status.setError("Using the default package is not allowed. Choose (or enter) a package"); return status; } IPackageFragmentRoot root; if (container == null) { root = null; } else { root = container.getPackageFragmentRoot(); } if (root != null) { IPackageFragment pack = root.getPackageFragment(packName); try { IPath rootPath = root.getPath(); IPath outputPath = root.getJavaProject().getOutputLocation(); if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) { // if the bin folder is inside of our root, dont allow to name a package // like the bin folder IPath packagePath = pack.getUnderlyingResource().getFullPath(); if (outputPath.isPrefixOf(packagePath)) { status.setError(MessageUtil.getString(name + ".error.ClashOutputLocation")); return status; } } } catch (JavaModelException e) { TapestryPlugin.getDefault().logException(e); // let pass } currentPackage = pack; } else { status.setError(""); } return status; }
From source file:com.liferay.ide.hook.core.operation.AddHookOperation.java
License:Open Source License
protected IStatus createLanguageProperties(IDataModel dm) { IProject project = getTargetProject(); String contentFolderValue = dm.getStringProperty(CONTENT_FOLDER); IFolder contentFolder = (IFolder) project.getWorkspace().getRoot().getFolder(new Path(contentFolderValue)); try {//from w w w . j a v a 2 s . co m CoreUtil.prepareFolder(contentFolder); } catch (CoreException e) { return HookCore.createErrorStatus(e); } List<String[]> languagePropertiesFiles = (List<String[]>) dm.getProperty(LANGUAGE_PROPERTIES_ITEMS); if (languagePropertiesFiles != null) { for (String[] languagePropertyFile : languagePropertiesFiles) { try { if (!languagePropertyFile[0].contains("*")) { IFile createdFile = ProjectUtil.createEmptyProjectFile(languagePropertyFile[0], contentFolder); if (createdFile != null) { Set<IFile> languageFilesCreated = (Set<IFile>) dm .getProperty(LANGUAGE_PROPERTIES_FILES_CREATED); languageFilesCreated.add(createdFile); dm.setProperty(LANGUAGE_PROPERTIES_FILES_CREATED, languageFilesCreated); } } } catch (Exception e) { HookCore.logError(e); } } } HookDescriptorHelper hookDescHelper = new HookDescriptorHelper(getTargetProject()); Set<IFile> languageFilesCreated = (Set<IFile>) dm.getProperty(LANGUAGE_PROPERTIES_FILES_CREATED); // need to get file paths relative to package root List<String> languageProperties = new ArrayList<String>(); IPackageFragmentRoot packRoot = (IPackageFragmentRoot) model .getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE_FRAGMENT_ROOT); if (packRoot != null) { for (IFile languageFile : languageFilesCreated) { if (packRoot.getPath().isPrefixOf(languageFile.getFullPath())) { String languageProperty = languageFile.getFullPath().makeRelativeTo(packRoot.getPath()) .toPortableString(); languageProperties.add(languageProperty); } } } IStatus status = hookDescHelper.addLanguageProperties(languageProperties); return status; }
From source file:com.liferay.ide.hook.core.operation.AddHookOperation.java
License:Open Source License
protected IStatus createPortalProperties(IDataModel dm) { IProject project = getTargetProject(); String portalPropertiesFile = dm.getStringProperty(PORTAL_PROPERTIES_FILE); // check to see if we have an existing file to read in IPath portalPropertiesPath = new Path(portalPropertiesFile); IPath propertiesFilesPath = portalPropertiesPath.makeRelativeTo(project.getFullPath()); IFile propertiesFile = project.getFile(propertiesFilesPath); Properties properties = new Properties(); if (propertiesFile.exists()) { try {/*from ww w . j ava 2s.c o m*/ properties.load(propertiesFile.getContents()); } catch (Exception e) { return HookCore.createErrorStatus(e); } } List<String[]> actionItems = (List<String[]>) dm.getProperty(PORTAL_PROPERTIES_ACTION_ITEMS); if (actionItems != null) { for (String[] actionItem : actionItems) { properties.put(actionItem[0], actionItem[1]); } } List<String[]> overrideItems = (List<String[]>) dm.getProperty(PORTAL_PROPERTIES_OVERRIDE_ITEMS); if (overrideItems != null) { for (String[] overrideItem : overrideItems) { properties.put(overrideItem[0], overrideItem[1]); } } StringBufferOutputStream buffer = new StringBufferOutputStream(); try { properties.store(buffer, StringPool.EMPTY); } catch (IOException e) { return HookCore.createErrorStatus(e); } try { ByteArrayInputStream bis = new ByteArrayInputStream(buffer.toString().getBytes("UTF-8")); //$NON-NLS-1$ if (propertiesFile.exists()) { propertiesFile.setContents(bis, IResource.FORCE, null); } else { CoreUtil.prepareFolder((IFolder) propertiesFile.getParent()); propertiesFile.create(bis, true, null); } } catch (Exception e) { return HookCore.createErrorStatus(e); } HookDescriptorHelper hookDescHelper = new HookDescriptorHelper(getTargetProject()); String propertiesClasspath = null; IPackageFragmentRoot packRoot = (IPackageFragmentRoot) model .getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE_FRAGMENT_ROOT); if (packRoot != null) { if (packRoot.getPath().isPrefixOf(propertiesFile.getFullPath())) { propertiesClasspath = propertiesFile.getFullPath().makeRelativeTo(packRoot.getPath()) .toPortableString(); } } IStatus status = hookDescHelper.setPortalProperties(this.model, propertiesClasspath); return status; }
From source file:com.liferay.ide.portlet.ui.wizard.NewPortletClassWizardPage.java
License:Open Source License
/** * Add folder group to composite/*w ww . java 2s. c o m*/ */ protected void createFolderGroup(Composite composite) { // folder Label folderLabel = new Label(composite, SWT.LEFT); folderLabel.setText(J2EEUIMessages.FOLDER_LABEL); folderLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); folderText = new Text(composite, SWT.SINGLE | SWT.BORDER); folderText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); synchHelper.synchText(folderText, INewJavaClassDataModelProperties.SOURCE_FOLDER, null); IPackageFragmentRoot root = getSelectedPackageFragmentRoot(); String projectName = model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME); if (projectName != null && projectName.length() > 0) { IProject targetProject = ProjectUtilities.getProject(projectName); if (root == null || !root.getJavaProject().getProject().equals(targetProject)) { IFolder folder = getDefaultJavaSourceFolder(targetProject); if (folder != null) { folderText.setText(folder.getFullPath().toPortableString()); } } else { folderText.setText(root.getPath().toString()); } } folderButton = new Button(composite, SWT.PUSH); folderButton.setText(J2EEUIMessages.BROWSE_BUTTON_LABEL); folderButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); folderButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // Do nothing } public void widgetSelected(SelectionEvent e) { handleFolderButtonPressed(); } }); }
From source file:com.liferay.ide.portlet.ui.wizard.NewPortletClassWizardPage.java
License:Open Source License
protected void createPackageGroup(Composite parent) { // package//from w w w. java 2 s . c om packageLabel = new Label(parent, SWT.LEFT); packageLabel.setText(J2EEUIMessages.JAVA_PACKAGE_LABEL); packageLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); packageText = new Text(parent, SWT.SINGLE | SWT.BORDER); packageText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); synchHelper.synchText(packageText, INewJavaClassDataModelProperties.JAVA_PACKAGE, null); IPackageFragment packageFragment = getSelectedPackageFragment(); String targetProject = model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME); if (packageFragment != null && packageFragment.exists() && packageFragment.getJavaProject().getElementName().equals(targetProject)) { IPackageFragmentRoot root = getPackageFragmentRoot(packageFragment); if (root != null) { folderText.setText(root.getPath().toString()); } model.setProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE, packageFragment.getElementName()); } if (this.fragment) { SWTUtil.createLabel(parent, StringPool.EMPTY, 1); } else { packageButton = new Button(parent, SWT.PUSH); packageButton.setText(J2EEUIMessages.BROWSE_BUTTON_LABEL); packageButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); packageButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // Do nothing } public void widgetSelected(SelectionEvent e) { handlePackageButtonPressed(); } }); } }
From source file:com.liferay.ide.server.remote.ModuleTraverser.java
License:Open Source License
private static Map getComponentClasspathDependencies(final IJavaProject javaProject, final boolean isWebApp) throws CoreException { // get the raw entries final Map referencedRawEntries = getRawComponentClasspathDependencies(javaProject); final Map<IClasspathEntry, IClasspathAttribute> validRawEntries = new HashMap<IClasspathEntry, IClasspathAttribute>(); // filter out non-valid referenced raw entries final Iterator i = referencedRawEntries.keySet().iterator(); while (i.hasNext()) { final IClasspathEntry entry = (IClasspathEntry) i.next(); final IClasspathAttribute attrib = (IClasspathAttribute) referencedRawEntries.get(entry); if (isValid(entry, attrib, isWebApp, javaProject.getProject())) { validRawEntries.put(entry, attrib); }/*from w w w . j ava2s . co m*/ } // if we have no valid raw entries, return empty map if (validRawEntries.isEmpty()) { return Collections.EMPTY_MAP; } // XXX Would like to replace the code below with use of a public JDT API that returns // the raw IClasspathEntry for a given resolved IClasspathEntry (see see https://bugs.eclipse.org/bugs/show_bug.cgi?id=183995) // The code must currently leverage IPackageFragmentRoot to determine this // mapping and, because IPackageFragmentRoots do not maintain IClasspathEntry data, a prior // call is needed to getResolvedClasspath() and the resolved IClasspathEntries have to be stored in a Map from IPath-to-IClasspathEntry to // support retrieval using the resolved IPackageFragmentRoot // retrieve the resolved classpath final IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); final Map<IPath, IClasspathEntry> pathToResolvedEntry = new HashMap<IPath, IClasspathEntry>(); // store in a map from path to entry for (int j = 0; j < entries.length; j++) { pathToResolvedEntry.put(entries[j].getPath(), entries[j]); } final Map<IClasspathEntry, IClasspathAttribute> referencedEntries = new LinkedHashMap<IClasspathEntry, IClasspathAttribute>(); // grab all IPackageFragmentRoots final IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int j = 0; j < roots.length; j++) { final IPackageFragmentRoot root = roots[j]; final IClasspathEntry rawEntry = root.getRawClasspathEntry(); // is the raw entry valid? IClasspathAttribute attrib = validRawEntries.get(rawEntry); if (attrib == null) { continue; } final IPath pkgFragPath = root.getPath(); final IClasspathEntry resolvedEntry = pathToResolvedEntry.get(pkgFragPath); final IClasspathAttribute resolvedAttrib = checkForComponentDependencyAttribute(resolvedEntry, DEPENDECYATTRIBUTETYPE_DEPENDENCY_OR_NONDEPENDENCY); // attribute for the resolved entry must either be unspecified or it must be the // dependency attribute for it to be included if (resolvedAttrib == null || resolvedAttrib.getName().equals(CLASSPATH_COMPONENT_DEPENDENCY)) { // filter out resolved entry if it doesn't pass the validation rules if (isValid(resolvedEntry, resolvedAttrib != null ? resolvedAttrib : attrib, isWebApp, javaProject.getProject())) { if (resolvedAttrib != null) { // if there is an attribute on the sub-entry, use that attrib = resolvedAttrib; } referencedEntries.put(resolvedEntry, attrib); } } } return referencedEntries; }
From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java
License:Open Source License
private boolean appendVariableLabel(IPackageFragmentRoot root, long flags) { try {/*w ww . j ava 2 s . co m*/ IClasspathEntry rawEntry = root.getRawClasspathEntry(); if (rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { IClasspathEntry entry = getClasspathEntry(root); if (entry.getReferencingEntry() != null) { return false; // not the variable entry itself, but a referenced entry } IPath path = rawEntry.getPath().makeRelative(); if (getFlag(flags, REFERENCED_ROOT_POST_QUALIFIED)) { int segements = path.segmentCount(); if (segements > 0) { fBuffer.append(path.segment(segements - 1)); if (segements > 1) { int offset = fBuffer.length(); fBuffer.append(CONCAT_STRING); fBuffer.append(path.removeLastSegments(1).toOSString()); } } else { fBuffer.append(path.toString()); } } else { fBuffer.append(path.toString()); } int offset = fBuffer.length(); fBuffer.append(CONCAT_STRING); if (root.isExternal()) fBuffer.append(root.getPath().toOSString()); else fBuffer.append(root.getPath().makeRelative().toString()); return true; } } catch (JavaModelException e) { // problems with class path, ignore (bug 202792) return false; } return false; }