|
From: <caw...@us...> - 2007-09-07 16:29:07
|
Revision: 3110
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=3110&view=rev
Author: cawilliams
Date: 2007-09-07 09:29:04 -0700 (Fri, 07 Sep 2007)
Log Message:
-----------
include non ruby resources inside external source folders. Wrap them in LocalFileStorage class. Use that class in UI, instead of SystemFileStorage (since it's the same implemntation).
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/Util.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/LocalFileStorage.java
Added: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/LocalFileStorage.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/LocalFileStorage.java (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/LocalFileStorage.java 2007-09-07 16:29:04 UTC (rev 3110)
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * 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.core;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.Status;
+
+/**
+ * Implementation of storage for a local file
+ * (<code>java.io.File</code>).
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ * @see IStorage
+ * @since 3.0
+ */
+public class LocalFileStorage extends PlatformObject implements IStorage {
+
+ /**
+ * The file this storage refers to.
+ */
+ private File fFile;
+
+ /**
+ * Constructs and returns storage for the given file.
+ *
+ * @param file a local file
+ */
+ public LocalFileStorage(File file){
+ setFile(file);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.resources.IStorage#getContents()
+ */
+ public InputStream getContents() throws CoreException {
+ try {
+ return new FileInputStream(getFile());
+ } catch (IOException e){
+ throw new CoreException(new Status(IStatus.ERROR, RubyCore.PLUGIN_ID, -1, "IO Exception opening file", e));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.resources.IStorage#getFullPath()
+ */
+ public IPath getFullPath() {
+ try {
+ return new Path(getFile().getCanonicalPath());
+ } catch (IOException e) {
+ RubyCore.log(e);
+ return null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.resources.IStorage#getName()
+ */
+ public String getName() {
+ return getFile().getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.resources.IStorage#isReadOnly()
+ */
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ /**
+ * Sets the file associated with this storage
+ *
+ * @param file a local file
+ */
+ private void setFile(File file) {
+ fFile = file;
+ }
+
+ /**
+ * Returns the file associated with this storage
+ *
+ * @return file
+ */
+ public File getFile() {
+ return fFile;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object object) {
+ return object instanceof LocalFileStorage &&
+ getFile().equals(((LocalFileStorage)object).getFile());
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ return getFile().hashCode();
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/LocalFileStorage.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolder.java 2007-09-07 16:28:56 UTC (rev 3109)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolder.java 2007-09-07 16:29:04 UTC (rev 3110)
@@ -3,10 +3,12 @@
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.LocalFileStorage;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.core.WorkingCopyOwner;
import org.rubypeople.rdt.internal.core.util.MementoTokenizer;
@@ -42,6 +44,7 @@
ArrayList<IRubyElement> vChildren = new ArrayList<IRubyElement>();
File file = getPath().toFile();
File[] members = file.listFiles();
+ List<LocalFileStorage> files = new ArrayList<LocalFileStorage>();
for (int i = 0, max = members.length; i < max; i++) {
File child = members[i];
if (!child.isDirectory()) {
@@ -49,9 +52,15 @@
if (Util.isValidRubyScriptName(child.getName())) {
childElement = new ExternalRubyScript(this, child.getName(), DefaultWorkingCopyOwner.PRIMARY);
vChildren.add(childElement);
+ } else {
+ files.add(new LocalFileStorage(child));
}
}
}
+ if (info instanceof SourceFolderInfo) {
+ SourceFolderInfo duh = (SourceFolderInfo) info;
+ duh.setNonRubyResources(files.toArray(new Object[files.size()]));
+ }
IRubyElement[] children= new IRubyElement[vChildren.size()];
vChildren.toArray(children);
info.setChildren(children);
@@ -78,4 +87,17 @@
}
return null;
}
+
+ /**
+ * Returns an array of non-ruby resources contained in the receiver.
+ */
+ public Object[] getNonRubyResources() throws RubyModelException {
+ if (this.isDefaultPackage()) {
+ // We don't want to show non ruby resources of the default package (see PR #1G58NB8)
+ return RubyElementInfo.NO_NON_RUBY_RESOURCES;
+ } else {
+ return this.storedNonRubyResources();
+ }
+ }
+
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java 2007-09-07 16:28:56 UTC (rev 3109)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java 2007-09-07 16:29:04 UTC (rev 3110)
@@ -2,6 +2,7 @@
import java.io.File;
import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IResource;
@@ -78,8 +79,7 @@
try {
RubyModelManager manager = RubyModelManager.getRubyModelManager();
- File[] members = folder.listFiles();
-
+ File[] members = folder.listFiles();
for (int i = 0, max = members.length; i < max; i++) {
File member = members[i];
String memberName = member.getName();
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/Util.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/Util.java 2007-09-07 16:28:56 UTC (rev 3109)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/Util.java 2007-09-07 16:29:04 UTC (rev 3110)
@@ -1074,4 +1074,55 @@
quickSortReverse(sortedCollection, left, original_right);
}
}
+
+ /**
+ * Returns the concatenation of the given array parts using the given separator between each
+ * part and appending the given name at the end.
+ * <br>
+ * <br>
+ * For example:<br>
+ * <ol>
+ * <li><pre>
+ * name = "c"
+ * array = { "a", "b" }
+ * separator = '.'
+ * => result = "a.b.c"
+ * </pre>
+ * </li>
+ * <li><pre>
+ * name = null
+ * array = { "a", "b" }
+ * separator = '.'
+ * => result = "a.b"
+ * </pre></li>
+ * <li><pre>
+ * name = " c"
+ * array = null
+ * separator = '.'
+ * => result = "c"
+ * </pre></li>
+ * </ol>
+ *
+ * @param array the given array
+ * @param name the given name
+ * @param separator the given separator
+ * @return the concatenation of the given array parts using the given separator between each
+ * part and appending the given name at the end
+ */
+ public static final String concatWith(
+ String[] array,
+ String name,
+ char separator) {
+
+ if (array == null || array.length == 0) return name;
+ if (name == null || name.length() == 0) return concatWith(array, separator);
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0, length = array.length; i < length; i++) {
+ buffer.append(array[i]);
+ buffer.append(separator);
+ }
+ buffer.append(name);
+ return buffer.toString();
+
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|