|
From: <caw...@us...> - 2007-04-20 22:54:50
|
Revision: 2352
http://svn.sourceforge.net/rubyeclipse/?rev=2352&view=rev
Author: cawilliams
Date: 2007-04-20 15:54:48 -0700 (Fri, 20 Apr 2007)
Log Message:
-----------
more build/load path support
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/AddSelectedSourceFolderOperation.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/CreateFolderOperation.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/EditFiltersOperation.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/ExcludeOperation.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/ILoadpathInformationProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/IPackageExplorerActionListener.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/LinkedSourceFolderOperation.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/LoadpathModifier.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/PackageExplorerActionEvent.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/RemoveFromLoadpathOperation.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/ResetAllOperation.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/UnexcludeOperation.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/LoadPathContainer.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackagesMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/AddSourceFolderWizard.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/AddSourceFolderWizardPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/BuildPathBasePage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/BuildPathSupport.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/BuildPathWizard.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/BuildPathsBlock.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPListElement.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPListElementAttribute.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPListElementSorter.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPListLabelProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPUserLibraryElement.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CreateMultipleSourceFoldersDialog.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/EditFilterWizard.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/ExclusionInclusionDialog.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/ExclusionInclusionEntryDialog.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/FolderSelectionDialog.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/LibrariesWorkbookPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/LoadpathContainerDefaultPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/LoadpathContainerDescriptor.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/LoadpathContainerSelectionPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/LoadpathContainerWizard.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/LoadpathOrderingWorkbookPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/MultipleFolderSelectionDialog.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/NewContainerDialog.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/ProjectsWorkbookPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/SetFilterWizardPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/SourceContainerWorkbookPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/OthersWorkingSetUpdater.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetModel.java
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/AddSelectedSourceFolderOperation.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/AddSelectedSourceFolderOperation.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/AddSelectedSourceFolderOperation.java 2007-04-20 22:54:48 UTC (rev 2352)
@@ -0,0 +1,149 @@
+/**
+ * Copyright (c) 2007 Aptana, Inc.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl -v10.html. If redistributing this code,
+ * this entire header must remain intact.
+ *
+ * This file is based on a JDT equivalent:
+ *******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.rubypeople.rdt.internal.corext.buildpath;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.corext.buildpath.LoadpathModifier.ILoadpathModifierListener;
+import org.rubypeople.rdt.internal.corext.util.Messages;
+import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.LoadpathModifierOperation;
+
+
+/**
+ * Operation to add objects (of type <code>IFolder</code> or <code>
+ * IRubyElement</code> as source folder to the classpath.
+ *
+ * @see org.eclipse.jdt.internal.corext.buildpath.LoadpathModifier#addToLoadpath(List, IRubyProject, OutputFolderQuery, IProgressMonitor)
+ * @see org.eclipse.jdt.internal.corext.buildpath.RemoveFromLoadpathOperation
+ */
+public class AddSelectedSourceFolderOperation extends LoadpathModifierOperation {
+
+ /**
+ * Constructor
+ *
+ * @param listener a <code>ILoadpathModifierListener</code> that is notified about
+ * changes on classpath entries or <code>null</code> if no such notification is
+ * necessary.
+ * @param informationProvider a provider to offer information to the action
+ *
+ * @see ILoadpathInformationProvider
+ * @see LoadpathModifier
+ */
+ public AddSelectedSourceFolderOperation(ILoadpathModifierListener listener, ILoadpathInformationProvider informationProvider) {
+ super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_AddSelSFToCP_tooltip, ILoadpathInformationProvider.ADD_SEL_SF_TO_BP);
+ }
+
+ /**
+ * Method which runs the actions with a progress monitor.<br>
+ *
+ * This operation requires the following query from the provider:
+ * <li>IOutputFolderQuery</li>
+ *
+ * @param monitor a progress monitor, can be <code>null</code>
+ */
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
+ List result= null;
+ fException= null;
+ try {
+ List elements= getSelectedElements();
+ IRubyProject project= fInformationProvider.getRubyProject();
+ result= addToLoadpath(elements, project, monitor);
+ } catch (CoreException e) {
+ fException= e;
+ result= null;
+ }
+ super.handleResult(result, monitor);
+ }
+
+ /**
+ * Find out whether this operation can be executed on
+ * the provided list of elements.
+ *
+ * @param elements a list of elements
+ * @param types an array of types for each element, that is,
+ * the type at position 'i' belongs to the selected element
+ * at position 'i'
+ *
+ * @return <code>true</code> if the operation can be
+ * executed on the provided list of elements, <code>
+ * false</code> otherwise.
+ * @throws RubyModelException
+ */
+ public boolean isValid(List elements, int[] types) throws RubyModelException {
+ if (elements.size() == 0)
+ return false;
+ for (int i= 0; i < elements.size(); i++) {
+ Object object= elements.get(i);
+ switch (types[i]) {
+ case DialogPackageExplorerActionGroup.RUBY_PROJECT: if (isSourceFolder((IRubyProject) object)) return false; break;
+ case DialogPackageExplorerActionGroup.SOURCE_FOLDER: break; // is ok
+ case DialogPackageExplorerActionGroup.INCLUDED_FOLDER: break; // is ok
+ case DialogPackageExplorerActionGroup.FOLDER: break; // is ok
+ case DialogPackageExplorerActionGroup.EXCLUDED_FOLDER: break; // is ok
+ default: return false; // all others are not ok
+ }
+
+ }
+ return true;
+ }
+
+ /**
+ * Get a description for this operation. The description depends on
+ * the provided type parameter, which must be a constant of
+ * <code>DialogPackageExplorerActionGroup</code>. If the type is
+ * <code>DialogPackageExplorerActionGroup.MULTI</code>, then the
+ * description will be very general to describe the situation of
+ * all the different selected objects as good as possible.
+ *
+ * @param type the type of the selected object, must be a constant of
+ * <code>DialogPackageExplorerActionGroup</code>.
+ * @return a string describing the operation
+ */
+ public String getDescription(int type) {
+ Object obj= getSelectedElements().get(0);
+ if (obj instanceof IRubyElement) {
+ String name= escapeSpecialChars(((IRubyElement) obj).getElementName());
+ if (type == DialogPackageExplorerActionGroup.RUBY_PROJECT)
+ return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_ProjectToBuildpath, name);
+ if (type == DialogPackageExplorerActionGroup.SOURCE_FOLDER)
+ return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_PackageToBuildpath, name);
+ if (type == DialogPackageExplorerActionGroup.MODIFIED_FRAGMENT_ROOT)
+ return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_PackageToBuildpath, name);
+ } else if (obj instanceof IResource) {
+ String name= escapeSpecialChars(((IResource) obj).getName());
+ if (type == DialogPackageExplorerActionGroup.FOLDER)
+ return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_FolderToBuildpath, name);
+ if (type == DialogPackageExplorerActionGroup.EXCLUDED_FOLDER)
+ return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_FolderToBuildpath, name);
+ }
+ return NewWizardMessages.PackageExplorerActionGroup_FormText_Default_toBuildpath;
+ }
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/CreateFolderOperation.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/CreateFolderOperation.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/CreateFolderOperation.java 2007-04-20 22:54:48 UTC (rev 2352)
@@ -0,0 +1,103 @@
+/**
+ * Copyright (c) 2007 Aptana, Inc.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl -v10.html. If redistributing this code,
+ * this entire header must remain intact.
+ *
+ * This file is based on a JDT equivalent:
+ *******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.corext.buildpath;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.rubypeople.rdt.core.ISourceFolderRoot;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.LoadpathModifierOperation;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.GenerateBuildPathActionGroup.CreateLocalSourceFolderAction;
+
+public class CreateFolderOperation extends LoadpathModifierOperation {
+
+ private final ILoadpathModifierListener fListener;
+ private final ILoadpathInformationProvider fCPInformationProvider;
+
+ /**
+ * Creates a new <code>AddFolderOperation</code>.
+ *
+ * @param listener a <code>ILoadpathModifierListener</code> that is notified about
+ * changes on classpath entries or <code>null</code> if no such notification is
+ * necessary.
+ * @param informationProvider a provider to offer information to the action
+ *
+ * @see ILoadpathInformationProvider
+ * @see LoadpathModifier
+ */
+ public CreateFolderOperation(ILoadpathModifierListener listener, ILoadpathInformationProvider informationProvider) {
+ super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_AddLibCP_tooltip, ILoadpathInformationProvider.CREATE_FOLDER);
+ fListener= listener;
+ fCPInformationProvider= informationProvider;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ CreateLocalSourceFolderAction action= new CreateLocalSourceFolderAction();
+ action.selectionChanged(new StructuredSelection(fCPInformationProvider.getRubyProject()));
+ action.run();
+ ISourceFolderRoot createdElement= (ISourceFolderRoot)action.getCreatedElement();
+ if (createdElement == null) {
+ //Wizard was cancled.
+ return;
+ }
+ try {
+ IResource correspondingResource= createdElement.getCorrespondingResource();
+ List result= new ArrayList();
+ result.add(correspondingResource);
+ if (fListener != null) {
+ List entries= action.getCPListElements();
+ fListener.classpathEntryChanged(entries);
+ }
+ fCPInformationProvider.handleResult(result, null, ILoadpathInformationProvider.CREATE_FOLDER);
+ } catch (RubyModelException e) {
+ if (monitor == null) {
+ fCPInformationProvider.handleResult(Collections.EMPTY_LIST, e, ILoadpathInformationProvider.CREATE_FOLDER);
+ } else {
+ throw new InvocationTargetException(e);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isValid(List elements, int[] types) throws RubyModelException {
+ return types.length == 1 && types[0] == DialogPackageExplorerActionGroup.RUBY_PROJECT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getDescription(int type) {
+ return NewWizardMessages.PackageExplorerActionGroup_FormText_createNewSourceFolder;
+ }
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/EditFiltersOperation.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/EditFiltersOperation.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/EditFiltersOperation.java 2007-04-20 22:54:48 UTC (rev 2352)
@@ -0,0 +1,142 @@
+/**
+ * Copyright (c) 2007 Aptana, Inc.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl -v10.html. If redistributing this code,
+ * this entire header must remain intact.
+ *
+ * This file is based on a JDT equivalent:
+ *******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.rubypeople.rdt.internal.corext.buildpath;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.ISourceFolderRoot;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.LoadpathModifierOperation;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.GenerateBuildPathActionGroup.EditFilterAction;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.LoadpathModifierQueries.IInclusionExclusionQuery;
+
+/**
+ * Operation to edit the inclusion / exclusion filters of an
+ * <code>IRubyElement</code>.
+ *
+ * @see org.eclipse.jdt.internal.corext.buildpath.LoadpathModifier#editFilters(IRubyElement, IRubyProject, IInclusionExclusionQuery, IProgressMonitor)
+ */
+public class EditFiltersOperation extends LoadpathModifierOperation {
+
+ private final ILoadpathInformationProvider fCPInformationProvider;
+ private final ILoadpathModifierListener fListener;
+
+ /**
+ * Constructor
+ *
+ * @param listener a <code>ILoadpathModifierListener</code> that is notified about
+ * changes on classpath entries or <code>null</code> if no such notification is
+ * necessary.
+ * @param informationProvider a provider to offer information to the action
+ *
+ * @see ILoadpathInformationProvider
+ * @see LoadpathModifier
+ */
+ public EditFiltersOperation(ILoadpathModifierListener listener, ILoadpathInformationProvider informationProvider) {
+ super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_Edit_tooltip, ILoadpathInformationProvider.EDIT_FILTERS);
+ fListener= listener;
+ fCPInformationProvider= informationProvider;
+
+ }
+
+ /**
+ * Method which runs the actions with a progress monitor.<br>
+ *
+ * This operation requires the following query:
+ * <li>IInclusionExclusionQuery</li>
+ *
+ * @param monitor a progress monitor, can be <code>null</code>
+ */
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
+ EditFilterAction action= new EditFilterAction();
+ IStructuredSelection selection= fCPInformationProvider.getSelection();
+ Object firstElement= selection.getFirstElement();
+ action.selectionChanged(selection);
+ action.run();
+ List l= new ArrayList();
+ l.add(firstElement);
+ if (fListener != null) {
+ List entries= action.getCPListElements();
+ fListener.classpathEntryChanged(entries);
+ }
+ fCPInformationProvider.handleResult(l, null, ILoadpathInformationProvider.EDIT_FILTERS);
+ }
+
+ /**
+ * Find out whether this operation can be executed on
+ * the provided list of elements.
+ *
+ * @param elements a list of elements
+ * @param types an array of types for each element, that is,
+ * the type at position 'i' belongs to the selected element
+ * at position 'i'
+ *
+ * @return <code>true</code> if the operation can be
+ * executed on the provided list of elements, <code>
+ * false</code> otherwise.
+ * @throws RubyModelException
+ */
+ public boolean isValid(List elements, int[] types) throws RubyModelException {
+ if (elements.size() != 1)
+ return false;
+ IRubyProject project= fInformationProvider.getRubyProject();
+ Object element= elements.get(0);
+
+ if (element instanceof IRubyProject) {
+ if (isSourceFolder(project))
+ return true;
+ } else if (element instanceof ISourceFolderRoot) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Get a description for this operation. The description depends on
+ * the provided type parameter, which must be a constant of
+ * <code>DialogPackageExplorerActionGroup</code>. If the type is
+ * <code>DialogPackageExplorerActionGroup.MULTI</code>, then the
+ * description will be very general to describe the situation of
+ * all the different selected objects as good as possible.
+ *
+ * @param type the type of the selected object, must be a constant of
+ * <code>DialogPackageExplorerActionGroup</code>.
+ * @return a string describing the operation
+ */
+ public String getDescription(int type) {
+ if (type == DialogPackageExplorerActionGroup.RUBY_PROJECT)
+ return NewWizardMessages.PackageExplorerActionGroup_FormText_Edit;
+ if (type == DialogPackageExplorerActionGroup.SOURCE_FOLDER_ROOT)
+ return NewWizardMessages.PackageExplorerActionGroup_FormText_Edit;
+ if (type == DialogPackageExplorerActionGroup.MODIFIED_FRAGMENT_ROOT)
+ return NewWizardMessages.PackageExplorerActionGroup_FormText_Edit;
+ return NewWizardMessages.PackageExplorerActionGroup_FormText_Default_Edit;
+ }
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/ExcludeOperation.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/ExcludeOperation.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/ExcludeOperation.java 2007-04-20 22:54:48 UTC (rev 2352)
@@ -0,0 +1,137 @@
+/**
+ * Copyright (c) 2007 Aptana, Inc.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl -v10.html. If redistributing this code,
+ * this entire header must remain intact.
+ *
+ * This file is based on a JDT equivalent:
+ *******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.rubypeople.rdt.internal.corext.buildpath;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.corext.buildpath.LoadpathModifier.ILoadpathModifierListener;
+import org.rubypeople.rdt.internal.corext.util.Messages;
+import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.LoadpathModifierOperation;
+
+
+/**
+ * Operation to exclude objects of type <code>IRubyElement</code>.
+ *
+ * @see org.eclipse.jdt.internal.corext.buildpath.LoadpathModifier#exclude(List, IRubyProject, IProgressMonitor)
+ * @see org.eclipse.jdt.internal.corext.buildpath.UnexcludeOperation
+ */
+public class ExcludeOperation extends LoadpathModifierOperation {
+
+ /**
+ * Constructor
+ *
+ * @param listener a <code>ILoadpathModifierListener</code> that is notified about
+ * changes on classpath entries or <code>null</code> if no such notification is
+ * necessary.
+ * @param informationProvider a provider to offer information to the operation
+ *
+ * @see ILoadpathInformationProvider
+ * @see LoadpathModifier
+ */
+ public ExcludeOperation(ILoadpathModifierListener listener, ILoadpathInformationProvider informationProvider) {
+ super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_Exclude_tooltip, ILoadpathInformationProvider.EXCLUDE);
+ }
+
+ /**
+ * Method which runs the actions with a progress monitor.<br>
+ *
+ * This operation does not require any queries from the provider.
+ *
+ * @param monitor a progress monitor, can be <code>null</code>
+ */
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
+ List result= null;
+ fException= null;
+ try {
+ List javaElements= getSelectedElements();
+ IRubyProject project= fInformationProvider.getRubyProject();
+ result= exclude(javaElements, project, monitor);
+ } catch (CoreException e) {
+ fException= e;
+ result= null;
+ }
+ super.handleResult(result, monitor);
+ }
+
+ /**
+ * Find out whether this operation can be executed on
+ * the provided list of elements.
+ *
+ * @param elements a list of elements
+ * @param types an array of types for each element, that is,
+ * the type at position 'i' belongs to the selected element
+ * at position 'i'
+ *
+ * @return <code>true</code> if the operation can be
+ * executed on the provided list of elements, <code>
+ * false</code> otherwise.
+ * @throws RubyModelException
+ */
+ public boolean isValid(List elements, int[] types) throws RubyModelException {
+ if (elements.size() == 0)
+ return false;
+ for(int i= 0; i < elements.size(); i++) {
+ Object element= elements.get(i);
+ int type= types[i];
+ if (!(type == DialogPackageExplorerActionGroup.SOURCE_FOLDER ||
+ type == DialogPackageExplorerActionGroup.INCLUDED_FOLDER ||
+ element instanceof IRubyScript))
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Get a description for this operation. The description depends on
+ * the provided type parameter, which must be a constant of
+ * <code>DialogPackageExplorerActionGroup</code>. If the type is
+ * <code>DialogPackageExplorerActionGroup.MULTI</code>, then the
+ * description will be very general to describe the situation of
+ * all the different selected objects as good as possible.
+ *
+ * @param type the type of the selected object, must be a constant of
+ * <code>DialogPackageExplorerActionGroup</code>.
+ * @return a string describing the operation
+ */
+ public String getDescription(int type) {
+ IRubyElement elem= (IRubyElement) getSelectedElements().get(0);
+ String name= escapeSpecialChars(elem.getElementName());
+ if (type == DialogPackageExplorerActionGroup.SOURCE_FOLDER)
+ return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_ExcludePackage, name);
+ if (type == DialogPackageExplorerActionGroup.INCLUDED_FOLDER)
+ return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_ExcludePackage, name);
+ if (type == DialogPackageExplorerActionGroup.RUBY_SCRIPT)
+ return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_ExcludeFile, name);
+ if (type == DialogPackageExplorerActionGroup.INCLUDED_FILE)
+ return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_ExcludeFile, name);
+ return NewWizardMessages.PackageExplorerActionGroup_FormText_Default_Exclude;
+ }
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/ILoadpathInformationProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/ILoadpathInformationProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/ILoadpathInformationProvider.java 2007-04-20 22:54:48 UTC (rev 2352)
@@ -0,0 +1,117 @@
+/**
+ * Copyright (c) 2007 Aptana, Inc.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl -v10.html. If redistributing this code,
+ * this entire header must remain intact.
+ *
+ * This file is based on a JDT equivalent:
+ *******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.rubypeople.rdt.internal.corext.buildpath;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.LoadpathModifierQueries.IRemoveLinkedFolderQuery;
+
+
+/**
+ * Interface representing a information provider for
+ * operations. The interface allows the operation to get
+ * information about the current state and to callback on
+ * the provider if the result of an operation needs to be handled.
+ *
+ * @see org.eclipse.jdt.internal.corext.buildpath.LoadpathModifierOperation
+ * @see org.eclipse.jdt.internal.corext.buildpath.CreateFolderOperation
+ * @see org.eclipse.jdt.internal.corext.buildpath.AddSelectedSourceFolderOperation
+ * @see org.eclipse.jdt.internal.corext.buildpath.RemoveFromLoadpathOperation
+ * @see org.eclipse.jdt.internal.corext.buildpath.IncludeOperation
+ * @see org.eclipse.jdt.internal.corext.buildpath.UnincludeOperation
+ * @see org.eclipse.jdt.internal.corext.buildpath.ExcludeOperation
+ * @see org.eclipse.jdt.internal.corext.buildpath.UnexcludeOperation
+ * @see org.eclipse.jdt.internal.corext.buildpath.EditFiltersOperation
+ * @see org.eclipse.jdt.internal.corext.buildpath.ResetOperation
+ */
+public interface ILoadpathInformationProvider {
+ public static final int ADD_SEL_SF_TO_BP= 0x00;
+ public static final int REMOVE_FROM_BP= 0x01;
+ public static final int EXCLUDE= 0x02;
+ public static final int UNEXCLUDE= 0x03;
+ public static final int EDIT_FILTERS= 0x04;
+ public static final int CREATE_LINK= 0x05;
+ public static final int RESET_ALL= 0x06;
+// public static final int EDIT_OUTPUT= 0x07;
+ public static final int CREATE_OUTPUT= 0x08;
+ public static final int RESET= 0x09;
+ public static final int INCLUDE= 0xA;
+ public static final int UNINCLUDE= 0xB;
+ public static final int CREATE_FOLDER= 0xC;
+ public static final int ADD_JAR_TO_BP= 0xD;
+ public static final int ADD_LIB_TO_BP= 0xE;
+ public static final int ADD_SEL_LIB_TO_BP= 0xF;
+
+ /**
+ * Method to invoce the <code>ILoadpathInformationProvider</code> to
+ * process the result of the corresponding operation. Normally, operations
+ * call this method at the end of their computation an pass the result
+ * back to the provider.
+ *
+ * @param resultElements the result list of an operation, can be empty
+ * @param exception an exception object in case that an exception occurred,
+ * <code>null</code> otherwise. Note: clients should check the exception
+ * object before processing the result because otherwise, the result might be
+ * incorrect
+ * @param operationType constant to specify which kind of operation was executed;
+ * corresponds to one of the following constants of <code>ILoadpathInformationProvider</code>:
+ * <li>CREATE_FOLDER</li>
+ * <li>ADD_TO_BP</li>
+ * <li>REMOVE_FROM_BP</li>
+ * <li>INCLUDE</li>
+ * <li>UNINCLUDE</li>
+ * <li>EXCLUDE</li>
+ * <li>UNEXCLUDE</li>
+ * <li>EDIT</li>
+ * <li>RESET</li>
+ * <li>CREATE_OUTPUT</li>
+ */
+ public void handleResult(List resultElements, CoreException exception, int operationType);
+
+ /**
+ * Method to retrieve the current list of selected elements of the provider, this is
+ * the objects on which the operation should be executed on.
+ *
+ * For example: if a tree item is selected and an operation should be
+ * executed on behalf of this item, then <code>getSelection()</code>
+ * should return this item.
+ *
+ * @return the current list of selected elements from the provider, must not be
+ * <code>null</code>
+ */
+ public IStructuredSelection getSelection();
+
+ /**
+ * Method to retrieve the Ruby project from the provider.
+ *
+ * @return the current Ruby project, must not be <code>null</code>
+ */
+ public IRubyProject getRubyProject();
+
+ public void deleteCreatedResources();
+
+ public IRemoveLinkedFolderQuery getRemoveLinkedFolderQuery() throws RubyModelException;
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/IPackageExplorerActionListener.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/IPackageExplorerActionListener.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/IPackageExplorerActionListener.java 2007-04-20 22:54:48 UTC (rev 2352)
@@ -0,0 +1,42 @@
+/**
+ * Copyright (c) 2007 Aptana, Inc.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl -v10.html. If redistributing this code,
+ * this entire header must remain intact.
+ *
+ * This file is based on a JDT equivalent:
+ *******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.rubypeople.rdt.internal.corext.buildpath;
+
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup;
+
+/**
+ * Interface for listeners of <code>PackageExplorerActionEvent</code>.
+ */
+public interface IPackageExplorerActionListener {
+
+ /**
+ * Handle the <code>PackageExplorerActionEvent</code> which is fired
+ * whenever the set of available actions changes.
+ *
+ * @param event event to be processed
+ *
+ * @see PackageExplorerActionEvent
+ * @see DialogPackageExplorerActionGroup#addListener(IPackageExplorerActionListener)
+ */
+ public void handlePackageExplorerActionEvent(PackageExplorerActionEvent event);
+
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/LinkedSourceFolderOperation.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/LinkedSourceFolderOperation.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/LinkedSourceFolderOperation.java 2007-04-20 22:54:48 UTC (rev 2352)
@@ -0,0 +1,130 @@
+/**
+ * Copyright (c) 2007 Aptana, Inc.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl -v10.html. If redistributing this code,
+ * this entire header must remain intact.
+ *
+ * This file is based on a JDT equivalent:
+ *******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.corext.buildpath;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.ISourceFolderRoot;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.LoadpathModifierOperation;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.GenerateBuildPathActionGroup.CreateLinkedSourceFolderAction;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.LoadpathModifierQueries.ILinkToQuery;
+
+/**
+ * Operation create a link to a source folder.
+ *
+ * @see org.eclipse.jdt.internal.corext.buildpath.LoadpathModifier#createLinkedSourceFolder(ILinkToQuery, IRubyProject, IProgressMonitor)
+ */
+public class LinkedSourceFolderOperation extends LoadpathModifierOperation {
+
+ private ILoadpathModifierListener fListener;
+ private ILoadpathInformationProvider fCPInformationProvider;
+
+ /**
+ * Constructor
+ *
+ * @param listener a <code>ILoadpathModifierListener</code> that is notified about
+ * changes on classpath entries or <code>null</code> if no such notification is
+ * necessary.
+ * @param informationProvider a provider to offer information to the action
+ *
+ * @see ILoadpathInformationProvider
+ * @see LoadpathModifier
+ */
+ public LinkedSourceFolderOperation(ILoadpathModifierListener listener, ILoadpathInformationProvider informationProvider) {
+ super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_Link_tooltip, ILoadpathInformationProvider.CREATE_LINK);
+ fListener= listener;
+ fCPInformationProvider= informationProvider;
+ }
+
+ /**
+ * Method which runs the actions with a progress monitor.<br>
+ *
+ * This operation requires the following query from the provider:
+ * <li>ILinkToQuery</li>
+ *
+ * @param monitor a progress monitor, can be <code>null</code>
+ */
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ CreateLinkedSourceFolderAction action= new CreateLinkedSourceFolderAction();
+ action.selectionChanged(new StructuredSelection(fCPInformationProvider.getRubyProject()));
+ action.run();
+ ISourceFolderRoot createdElement= (ISourceFolderRoot)action.getCreatedElement();
+ if (createdElement == null) {
+ //Wizard was cancled.
+ return;
+ }
+ try {
+ IResource correspondingResource= createdElement.getCorrespondingResource();
+ List result= new ArrayList();
+ result.add(correspondingResource);
+ if (fListener != null) {
+ List entries= action.getCPListElements();
+ fListener.classpathEntryChanged(entries);
+ }
+ fCPInformationProvider.handleResult(result, null, ILoadpathInformationProvider.CREATE_LINK);
+ } catch (RubyModelException e) {
+ if (monitor == null) {
+ fCPInformationProvider.handleResult(Collections.EMPTY_LIST, e, ILoadpathInformationProvider.CREATE_LINK);
+ } else {
+ throw new InvocationTargetException(e);
+ }
+ }
+ }
+
+ /**
+ * This particular operation is always valid.
+ *
+ * @param elements a list of elements
+ * @param types an array of types for each element, that is,
+ * the type at position 'i' belongs to the selected element
+ * at position 'i'
+ *
+ * @return <code>true</code> if the operation can be
+ * executed on the provided list of elements, <code>
+ * false</code> otherwise.
+ * @throws RubyModelException
+ */
+ public boolean isValid(List elements, int[] types) throws RubyModelException {
+ return types.length == 1 && types[0] == DialogPackageExplorerActionGroup.RUBY_PROJECT;
+ }
+
+ /**
+ * Get a description for this operation.
+ *
+ * @param type the type of the selected object, must be a constant of
+ * <code>DialogPackageExplorerActionGroup</code>.
+ * @return a string describing the operation
+ */
+ public String getDescription(int type) {
+ return NewWizardMessages.PackageExplorerActionGroup_FormText_createLinkedFolder;
+ }
+
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/LoadpathModifier.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/LoadpathModifier.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/buildpath/LoadpathModifier.java 2007-04-20 22:54:48 UTC (rev 2352)
@@ -0,0 +1,1270 @@
+/**
+ * Copyright (c) 2007 Aptana, Inc.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl -v10.html. If redistributing this code,
+ * this entire header must remain intact.
+ *
+ * This file is based on a JDT equivalent:
+ *******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Matt Chapman, mpc...@gm... - 89977 Make JDT .java agnostic
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.corext.buildpath;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.rubypeople.rdt.core.ILoadpathEntry;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyModelStatus;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.ISourceFolder;
+import org.rubypeople.rdt.core.ISourceFolderRoot;
+import org.rubypeople.rdt.core.RubyConventions;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.corext.util.Messages;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.dialogs.StatusInfo;
+import org.rubypeople.rdt.internal.ui.packageview.LoadPathContainer;
+import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.BuildPathBasePage;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.CPListElement;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.LoadpathModifierQueries;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.LoadpathModifierQueries.IRemoveLinkedFolderQuery;
+
+public class LoadpathModifier {
+
+ /**
+ * Interface for listeners that want to receive a notification about
+ * changes on <code>ILoadpathEntry</code>. For example, if a source
+ * folder changes one of it's inclusion/exclusion filters, then
+ * this event will be fired.
+ */
+ public static interface ILoadpathModifierListener {
+ /**
+ * The new build path entry that was generated upon calling a method of
+ * <code>LoadpathModifier</code>. The type indicates which kind of
+ * interaction was executed on this entry.
+ *
+ * Note that the list does not contain elements of type
+ * <code>ILoadpathEntry</code>, but <code>CPListElement</code>
+ *
+ * @param newEntries list of <code>CPListElement</code>
+ */
+ public void classpathEntryChanged(List newEntries); // XXX Rename!
+ }
+
+ private ILoadpathModifierListener fListener;
+
+ public LoadpathModifier() {
+ this(null);
+ }
+
+ protected LoadpathModifier(ILoadpathModifierListener listener) {
+ fListener= listener;
+ }
+
+ /**
+ * Remove <code>path</code> from inclusion/exlusion filters in all <code>existingEntries</code>
+ *
+ * @param path the path to remove
+ * @param project the Java project
+ * @param existingEntries a list of <code>CPListElement</code> representing the build path
+ * entries of the project.
+ * @return returns a <code>List</code> of <code>CPListElement</code> of modified elements, not null.
+ */
+ public static List removeFilters(IPath path, IRubyProject project, List existingEntries) {
+ if (path == null)
+ return Collections.EMPTY_LIST;
+
+ IPath projPath= project.getPath();
+ if (projPath.isPrefixOf(path)) {
+ path= path.removeFirstSegments(projPath.segmentCount()).addTrailingSeparator();
+ }
+
+ List result= new ArrayList();
+ for (Iterator iter= existingEntries.iterator(); iter.hasNext();) {
+ CPListElement element= (CPListElement)iter.next();
+ boolean hasChange= false;
+ IPath[] exlusions= (IPath[])element.getAttribute(CPListElement.EXCLUSION);
+ if (exlusions != null) {
+ List exlusionList= new ArrayList(exlusions.length);
+ for (int i= 0; i < exlusions.length; i++) {
+ if (!exlusions[i].equals(path)) {
+ exlusionList.add(exlusions[i]);
+ } else {
+ hasChange= true;
+ }
+ }
+ element.setAttribute(CPListElement.EXCLUSION, exlusionList.toArray(new IPath[exlusionList.size()]));
+ }
+
+ IPath[] inclusion= (IPath[])element.getAttribute(CPListElement.INCLUSION);
+ if (inclusion != null) {
+ List inclusionList= new ArrayList(inclusion.length);
+ for (int i= 0; i < inclusion.length; i++) {
+ if (!inclusion[i].equals(path)) {
+ inclusionList.add(inclusion[i]);
+ } else {
+ hasChange= true;
+ }
+ }
+ element.setAttribute(CPListElement.INCLUSION, inclusionList.toArray(new IPath[inclusionList.size()]));
+ }
+ if (hasChange) {
+ result.add(element);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get the <code>ILoadpathEntry</code> from the project and
+ * convert it into a list of <code>CPListElement</code>s.
+ *
+ * @param project the Ruby project to get it's build path entries from
+ * @return a list of <code>CPListElement</code>s corresponding to the
+ * build path entries of the project
+ * @throws RubyModelException
+ */
+ public static List getExistingEntries(IRubyProject project) throws RubyModelException {
+ ILoadpathEntry[] classpathEntries= project.getRawLoadpath();
+ ArrayList newClassPath= new ArrayList();
+ for (int i= 0; i < classpathEntries.length; i++) {
+ ILoadpathEntry curr= classpathEntries[i];
+ newClassPath.add(CPListElement.createFromExisting(curr, project));
+ }
+ return newClassPath;
+ }
+
+ /**
+ * Try to find the corresponding and modified <code>CPListElement</code> for the root
+ * in the list of elements and return it.
+ * If no one can be found, the roots <code>ClasspathEntry</code> is converted to a
+ * <code>CPListElement</code> and returned.
+ *
+ * @param elements a list of <code>CPListElements</code>
+ * @param root the root to find the <code>ClasspathEntry</code> for represented by
+ * a <code>CPListElement</code>
+ * @return the <code>CPListElement</code> found in the list (matching by using the path) or
+ * the roots own <code>IClasspathEntry</code> converted to a <code>CPListElement</code>.
+ * @throws RubyModelException
+ */
+ public static CPListElement getLoadpathEntry(List elements, ISourceFolderRoot root) throws RubyModelException {
+ ILoadpathEntry entry= root.getRawLoadpathEntry();
+ for (int i= 0; i < elements.size(); i++) {
+ CPListElement element= (CPListElement) elements.get(i);
+ if (element.getPath().equals(root.getPath()) && element.getEntryKind() == entry.getEntryKind())
+ return (CPListElement) elements.get(i);
+ }
+ CPListElement newElement= CPListElement.createFromExisting(entry, root.getRubyProject());
+ elements.add(newElement);
+ return newElement;
+ }
+
+ /**
+ * Get the <code>ILoadpathEntry</code> for the
+ * given path by looking up all
+ * build path entries on the project
+ *
+ * @param path the path to find a build path entry for
+ * @param project the Ruby project
+ * @return the <code>ILoadpathEntry</code> corresponding
+ * to the <code>path</code> or <code>null</code> if there
+ * is no such entry
+ * @throws RubyModelException
+ */
+ public static ILoadpathEntry getLoadpathEntryFor(IPath path, IRubyProject project, int entryKind) throws RubyModelException {
+ ILoadpathEntry[] entries= project.getRawLoadpath();
+ for (int i= 0; i < entries.length; i++) {
+ ILoadpathEntry entry= entries[i];
+ if (entry.getPath().equals(path) && equalEntryKind(entry, entryKind))
+ return entry;
+ }
+ return null;
+ }
+
+ /**
+ * Test if the provided kind is of type
+ * <code>ILoadpathEntry.CPE_SOURCE</code>
+ *
+ * @param entry the classpath entry to be compared with the provided type
+ * @param kind the kind to be checked
+ * @return <code>true</code> if kind equals
+ * <code>ILoadpathEntry.CPE_SOURCE</code>,
+ * <code>false</code> otherwise
+ */
+ private static boolean equalEntryKind(ILoadpathEntry entry, int kind) {
+ return entry.getEntryKind() == kind;
+ }
+
+ /**
+ * Check whether the input paramenter of type <code>
+ * ISourceFolderRoot</code> has either it's inclusion or
+ * exclusion filter or both set (that means they are
+ * not empty).
+ *
+ * @param root the fragment root to be inspected
+ * @return <code>true</code> inclusion or exclusion filter set,
+ * <code>false</code> otherwise.
+ */
+ public static boolean filtersSet(ISourceFolderRoot root) throws RubyModelException {
+ if (root == null)
+ return false;
+ ILoadpathEntry entry= root.getRawLoadpathEntry();
+ IPath[] inclusions= entry.getInclusionPatterns();
+ IPath[] exclusions= entry.getExclusionPatterns();
+ if (inclusions != null && inclusions.length > 0)
+ return true;
+ if (exclusions != null && exclusions.length > 0)
+ return true;
+ return false;
+ }
+
+ /**
+ * Find out whether the <code>IResource</code> excluded or not.
+ *
+ * @param resource the resource to be checked
+ * @param project the Ruby project
+ * @return <code>true</code> if the resource is excluded, <code>
+ * false</code> otherwise
+ * @throws RubyModelException
+ */
+ public static boolean isExcluded(IResource resource, IRubyProject project) throws RubyModelException {
+ ISourceFolderRoot root= getFolderRoot(resource, project, null);
+ if (root == null)
+ return false;
+ String fragmentName= getName(resource.getFullPath(), root.getPath());
+ fragmentName= completeName(fragmentName);
+ ILoadpathEntry entry= root.getRawLoadpathEntry();
+ return entry != null && contains(new Path(fragmentName), entry.getExclusionPatterns(), null);
+ }
+
+ /**
+ * Find out whether the provided path equals to one
+ * in the array.
+ *
+ * @param path path to find an equivalent for
+ * @param paths set of paths to compare with
+ * @param monitor progress monitor, can be <code>null</code>
+ * @return <code>true</code> if there is an occurrence, <code>
+ * false</code> otherwise
+ */
+ private static boolean contains(IPath path, IPath[] paths, IProgressMonitor monitor) {
+ if (monitor == null)
+ monitor= new NullProgressMonitor();
+ if (path == null)
+ return false;
+ try {
+ monitor.beginTask(NewWizardMessages.ClasspathModifier_Monitor_ComparePaths, paths.length);
+ if (path.getFileExtension() == null)
+ path= new Path(completeName(path.toString()));
+ for (int i= 0; i < paths.length; i++) {
+ if (paths[i].equals(path))
+ return true;
+ monitor.worked(1);
+ }
+ } finally {
+ monitor.done();
+ }
+ return false;
+ }
+
+ /**
+ * Add a '/' at the end of the name if
+ * it does not end with '.rb', or other Ruby-like extension.
+ *
+ * @param name append '/' at the end if
+ * necessary
+ * @return modified string
+ */
+ private static String completeName(String name) {
+ if (!RubyCore.isRubyLikeFileName(name)) {
+ name= name + "/"; //$NON-NLS-1$
+ name= name.replace('.', '/');
+ return name;
+ }
+ return name;
+ }
+
+ /**
+ * Returns a string corresponding to the <code>path</code>
+ * with the <code>rootPath<code>'s number of segments
+ * removed
+ *
+ * @param path path to remove segments
+ * @param rootPath provides the number of segments to
+ * be removed
+ * @return a string corresponding to the mentioned
+ * action
+ */
+ private static String getName(IPath path, IPath rootPath) {
+ return path.removeFirstSegments(rootPath.segmentCount()).toString();
+ }
+
+ /**
+ * Get the source folder of a given <code>IResource</code> element,
+ * starting with the resource's parent.
+ *
+ * @param resource the resource to get the fragment root from
+ * @param project the Ruby project
+ * @param monitor progress monitor, can be <code>null</code>
+ * @return resolved fragment root
+ * @throws RubyModelException
+ */
+ public static ISourceFolderRoot getFolderRoot(IResource resource, IRubyProject project, IProgressMonitor monitor) throws RubyModelException {
+ if (monitor == null)
+ monitor= new NullProgressMonitor();
+ IRubyElement javaElem= null;
+ if (resource.getFullPath().equals(project.getPath()))
+ return project.getSourceFolderRoot(resource);
+ IContainer container= resource.getParent();
+ do {
+ if (container instanceof IFolder)
+ javaElem= RubyCore.create((IFolder) container);
+ if (container.getFullPath().equals(project.getPath())) {
+ javaElem= project;
+ break;
+ }
+ container= container.getParent();
+ if (container == null)
+ return null;
+ } while (javaElem == null || !(javaElem instanceof ISourceFolderRoot));
+ if (javaElem instanceof IRubyProject)
+ javaElem= project.getSourceFolderRoot(project.getResource());
+ return (ISourceFolderRoot) javaElem;
+ }
+
+ protected static String escapeSpecialChars(String value) {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < value.length(); i++) {
+ char c = value.charAt(i);
+
+ switch (c) {
+ case '&':
+ buf.append("&"); //$NON-NLS-1$
+ break;
+ case '<':
+ buf.append("<"); //$NON-NLS-1$
+ break;
+ case '>':
+ buf.append(">"); //$NON-NLS-1$
+ break;
+ case '\'':
+ buf.append("'"); //$NON-NLS-1$
+ break;
+ case '\"':
+ buf.append("""); //$NON-NLS-1$
+ break;
+ case 160:
+ buf.append(" "); //$NON-NLS-1$
+ break;
+ default:
+ buf.append(c);
+ break;
+ }
+ }
+ return buf.toString();
+ }
+
+ /**
+ * Check whether the <code>IRubyProject</code>
+ * is a source folder
+ *
+ * @param project the project to test
+ * @return <code>true</code> if <code>project</code> is a source folder
+ * <code>false</code> otherwise.
+ */
+ public static boolean isSourceFolder(IRubyProject project) throws RubyModelException {
+ return LoadpathModifier.getLoadpathEntryFor(project.getPath(), project, ILoadpathEntry.CPE_SOURCE) != null;
+ }
+
+ /**
+ * Add a list of elements to the build path.
+ *
+ * @param elements a list of eleme...
[truncated message content] |