|
From: <caw...@us...> - 2006-12-15 21:55:09
|
Revision: 1714
http://svn.sourceforge.net/rubyeclipse/?rev=1714&view=rev
Author: cawilliams
Date: 2006-12-15 13:55:07 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
make a new class wizard (better than the old)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CreateSourceFolderOperation.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ElementCache.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/Openable.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelCache.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelManager.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java
trunk/org.rubypeople.rdt.ui/plugin.xml
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewClassWizardAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.properties
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewContainerWizardPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewTypeWizardPage.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/IUIConstants.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewClassCreationWizard.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewElementWizard.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/dialogfields/SelectionButtonDialogFieldGroup.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewClassWizardPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewElementWizardPage.java
Removed Paths:
-------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/RubyNewClassWizardPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/RubyNewClassWizard.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CreateSourceFolderOperation.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CreateSourceFolderOperation.java 2006-12-15 15:40:46 UTC (rev 1713)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CreateSourceFolderOperation.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -14,7 +14,6 @@
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyModelStatus;
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ElementCache.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ElementCache.java 2006-12-15 15:40:46 UTC (rev 1713)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ElementCache.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -10,15 +10,18 @@
*******************************************************************************/
package org.rubypeople.rdt.internal.core;
+import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.core.buffer.LRUCache;
import org.rubypeople.rdt.internal.core.buffer.OverflowingLRUCache;
/**
- * An LRU cache of <code>JavaElements</code>.
+ * An LRU cache of <code>RubyElements</code>.
*/
public class ElementCache extends OverflowingLRUCache {
+ IRubyElement spaceLimitParent = null;
+
/**
* Constructs a new element cache of the given size.
*/
@@ -32,6 +35,32 @@
public ElementCache(int size, int overflow) {
super(size, overflow);
}
+
+ /*
+ * Ensures that there is enough room for adding the given number of children.
+ * If the space limit must be increased, record the parent that needed this space limit.
+ */
+ protected void ensureSpaceLimit(int childrenSize, IRubyElement parent) {
+ // ensure the children can be put without closing other elements
+ int spaceNeeded = 1 + (int)((1 + fLoadFactor) * (childrenSize + fOverflow));
+ if (fSpaceLimit < spaceNeeded) {
+ // parent is being opened with more children than the space limit
+ shrink(); // remove overflow
+ setSpaceLimit(spaceNeeded);
+ this.spaceLimitParent = parent;
+ }
+ }
+
+ /*
+ * If the given parent was the one that increased the space limit, reset
+ * the space limit to the given default value.
+ */
+ protected void resetSpaceLimit(int defaultLimit, IRubyElement parent) {
+ if (parent.equals(this.spaceLimitParent)) {
+ setSpaceLimit(defaultLimit);
+ this.spaceLimitParent = null;
+ }
+ }
/**
* Returns true if the element is successfully closed and removed from the
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/Openable.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/Openable.java 2006-12-15 15:40:46 UTC (rev 1713)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/Openable.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -6,7 +6,6 @@
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import org.eclipse.core.resources.IResource;
@@ -52,7 +51,7 @@
RubyModelManager.getRubyModelManager().getElementsOutOfSynchWithBuffers().remove(this);
getBufferManager().removeBuffer(event.getBuffer());
} else {
- RubyModelManager.getRubyModelManager().getElementsOutOfSynchWithBuffers().put(this, this);
+ RubyModelManager.getRubyModelManager().getElementsOutOfSynchWithBuffers().add(this);
}
}
@@ -295,35 +294,7 @@
* @see IOpenable
*/
public void makeConsistent(IProgressMonitor monitor) throws RubyModelException {
- if (isConsistent()) return;
-
- // create a new info and make it the current info
- // (this will remove the info and its children just before storing the
- // new infos)
- RubyModelManager manager = RubyModelManager.getRubyModelManager();
- boolean hadTemporaryCache = manager.hasTemporaryCache();
- try {
- HashMap newElements = manager.getTemporaryCache();
- openWhenClosed(newElements, monitor);
- if (newElements.get(this) == null) {
- // close any buffer that was opened for the new elements
- Iterator iterator = newElements.keySet().iterator();
- while (iterator.hasNext()) {
- IRubyElement element = (IRubyElement) iterator.next();
- if (element instanceof Openable) {
- ((Openable) element).closeBuffer();
- }
- }
- throw newNotPresentException();
- }
- if (!hadTemporaryCache) {
- manager.putInfos(this, newElements);
- }
- } finally {
- if (!hadTemporaryCache) {
- manager.resetTemporaryCache();
- }
- }
+ // only scripts can be inconsistent
}
/**
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelCache.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelCache.java 2006-12-15 15:40:46 UTC (rev 1713)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelCache.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -15,7 +15,6 @@
import java.util.Map;
import org.rubypeople.rdt.core.IRubyElement;
-import org.rubypeople.rdt.internal.core.buffer.OverflowingLRUCache;
/**
* The cache of java elements to their respective info.
@@ -33,41 +32,50 @@
* Cache of open projects.
*/
protected HashMap projectCache;
+
+ /**
+ * Cache of open source folders
+ */
+ protected ElementCache folderCache;
- /**
- * Cache of open compilation unit and class files
- */
- protected OverflowingLRUCache openableCache;
+ /**
+ * Cache of open ruby script files
+ */
+ protected ElementCache openableCache;
/**
* Cache of open children of openable Ruby Model Ruby elements
*/
protected Map childrenCache;
+
+ public static final int DEFAULT_PROJECT_SIZE = 5; // average 25552 bytes per project.
+ public static final int DEFAULT_FOLDER_SIZE = 500; // average 1782 bytes per pkg -> maximum size : 178200*BASE_VALUE bytes
+ public static final int DEFAULT_OPENABLE_SIZE = 500; // average 6629 bytes per openable (includes children) -> maximum size : 662900*BASE_VALUE bytes
+ public static final int DEFAULT_CHILDREN_SIZE = 500*20; // average 20 children per openable
+
+ /*
+ * The memory ratio that should be applied to the above constants.
+ */
+ protected double memoryRatio = -1;
public RubyModelCache() {
- this.projectCache = new HashMap(5); // average 25552 bytes per project.
- // bytes per pkg
- // -> maximum
- // size :
- // 178200*CACHE_RATIO
- // bytes
- this.openableCache = new ElementCache(CACHE_RATIO * 100); // average
- // 6629
- // bytes per
- // openable
- // (includes
- // children)
- // ->
- // maximum
- // size :
- // 662900*CACHE_RATIO
- // bytes
- this.childrenCache = new HashMap(CACHE_RATIO * 10 * 20); // average
- // 20
- // children
- // per
- // openable
+// set the size of the caches in function of the maximum amount of memory available
+ double ratio = getMemoryRatio();
+ this.projectCache = new HashMap(DEFAULT_PROJECT_SIZE); // NB: Don't use a LRUCache for projects as they are constantly reopened (e.g. during delta processing)
+ this.openableCache = new ElementCache((int) (DEFAULT_OPENABLE_SIZE * ratio));
+ this.folderCache = new ElementCache((int) (DEFAULT_FOLDER_SIZE * ratio));
+ this.childrenCache = new HashMap((int) (DEFAULT_CHILDREN_SIZE * ratio));
}
+
+ protected double getMemoryRatio() {
+ if (this.memoryRatio == -1) {
+ long maxMemory = Runtime.getRuntime().maxMemory();
+ // if max memory is infinite, set the ratio to 4d which corresponds to the 256MB that Eclipse defaults to
+ // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=111299)
+ this.memoryRatio = maxMemory == Long.MAX_VALUE ? 4d : ((double) maxMemory) / (64 * 0x100000); // 64MB is the base memory for most JVM
+ }
+ return this.memoryRatio;
+ }
/**
* Returns the info for the element.
@@ -78,6 +86,8 @@
return this.modelInfo;
case IRubyElement.RUBY_PROJECT:
return this.projectCache.get(element);
+ case IRubyElement.SOURCE_FOLDER:
+ return this.folderCache.get(element);
case IRubyElement.SCRIPT:
return this.openableCache.get(element);
default:
@@ -94,6 +104,8 @@
return this.modelInfo;
case IRubyElement.RUBY_PROJECT:
return this.projectCache.get(element);
+ case IRubyElement.SOURCE_FOLDER:
+ return this.folderCache.peek(element);
case IRubyElement.SCRIPT:
return this.openableCache.peek(element);
default:
@@ -105,38 +117,48 @@
* Remember the info for the element.
*/
protected void putInfo(IRubyElement element, Object info) {
- switch (element.getElementType()) {
- case IRubyElement.RUBY_MODEL:
- this.modelInfo = (RubyModelInfo) info;
- break;
- case IRubyElement.RUBY_PROJECT:
- this.projectCache.put(element, info);
- break;
- case IRubyElement.SCRIPT:
- this.openableCache.put(element, info);
- break;
- default:
- this.childrenCache.put(element, info);
- }
+ switch (element.getElementType()) {
+ case IRubyElement.RUBY_MODEL:
+ this.modelInfo = (RubyModelInfo) info;
+ break;
+ case IRubyElement.RUBY_PROJECT:
+ this.projectCache.put(element, info);
+ this.folderCache.ensureSpaceLimit(((RubyElementInfo) info).children.length, element);
+ break;
+ case IRubyElement.SOURCE_FOLDER:
+ this.folderCache.put(element, info);
+ this.openableCache.ensureSpaceLimit(((RubyElementInfo) info).children.length, element);
+ break;
+ case IRubyElement.SCRIPT:
+ this.openableCache.put(element, info);
+ break;
+ default:
+ this.childrenCache.put(element, info);
+ }
}
/**
* Removes the info of the element from the cache.
*/
protected void removeInfo(IRubyElement element) {
- switch (element.getElementType()) {
- case IRubyElement.RUBY_MODEL:
- this.modelInfo = null;
- break;
- case IRubyElement.RUBY_PROJECT:
- this.projectCache.remove(element);
- break;
- case IRubyElement.SCRIPT:
- this.openableCache.remove(element);
- break;
- default:
- this.childrenCache.remove(element);
- }
+ switch (element.getElementType()) {
+ case IRubyElement.RUBY_MODEL:
+ this.modelInfo = null;
+ break;
+ case IRubyElement.RUBY_PROJECT:
+ this.projectCache.remove(element);
+ this.folderCache.resetSpaceLimit((int) (DEFAULT_FOLDER_SIZE * getMemoryRatio()), element);
+ break;
+ case IRubyElement.SOURCE_FOLDER:
+ this.folderCache.remove(element);
+ this.openableCache.resetSpaceLimit((int) (DEFAULT_OPENABLE_SIZE * getMemoryRatio()), element);
+ break;
+ case IRubyElement.SCRIPT:
+ this.openableCache.remove(element);
+ break;
+ default:
+ this.childrenCache.remove(element);
+ }
}
public String toStringFillingRation(String prefix) {
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelManager.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelManager.java 2006-12-15 15:40:46 UTC (rev 1713)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelManager.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -86,7 +86,7 @@
/**
* Set of elements which are out of sync with their buffers.
*/
- protected Map elementsOutOfSynchWithBuffers = new HashMap(11);
+ protected HashSet elementsOutOfSynchWithBuffers = new HashSet(11);
/*
* A HashSet that contains the IJavaProject whose classpath is being
@@ -450,7 +450,7 @@
/**
* Returns the set of elements which are out of synch with their buffers.
*/
- protected Map getElementsOutOfSynchWithBuffers() {
+ protected HashSet getElementsOutOfSynchWithBuffers() {
return this.elementsOutOfSynchWithBuffers;
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java 2006-12-15 15:40:46 UTC (rev 1713)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -511,7 +511,7 @@
* @see IOpenable#isConsistent()
*/
public boolean isConsistent() {
- return RubyModelManager.getRubyModelManager().getElementsOutOfSynchWithBuffers().get(this) == null;
+ return !RubyModelManager.getRubyModelManager().getElementsOutOfSynchWithBuffers().contains(this);
}
/**
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java 2006-12-15 15:40:46 UTC (rev 1713)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -111,6 +111,7 @@
CreateRubyScriptOperation op= new CreateRubyScriptOperation(this, name, contents, force);
op.runOperation(monitor);
IFile file = ((IContainer) getResource()).getFile(new Path(name));
+ // TODO Strip off .rb extensions?
return new RubyScript(this, file, name, DefaultWorkingCopyOwner.PRIMARY);
}
@@ -200,10 +201,7 @@
if (!org.rubypeople.rdt.internal.core.util.Util.isRubyLikeFileName(name)) {
throw new IllegalArgumentException(Messages.convention_unit_notJavaName);
}
- IPath path = this.getResource().getFullPath();
- path.append(name);
- path.addFileExtension(".rb");
- IFile file = ((IContainer) getResource()).getFile(path);
+ IFile file = ((IContainer) getResource()).getFile(new Path(name));
return new RubyScript(this, file, name, DefaultWorkingCopyOwner.PRIMARY);
}
Modified: trunk/org.rubypeople.rdt.ui/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.xml 2006-12-15 15:40:46 UTC (rev 1713)
+++ trunk/org.rubypeople.rdt.ui/plugin.xml 2006-12-15 21:55:07 UTC (rev 1714)
@@ -256,7 +256,7 @@
name="%NewWizardRubyClass.name"
icon="icons/full/etool16/newclass_wiz.gif"
category="org.rubypeople.rdt.ui"
- class="org.rubypeople.rdt.ui.wizards.RubyNewClassWizard"
+ class="org.rubypeople.rdt.internal.ui.wizards.NewClassCreationWizard"
preferredPerspectives="org.rubypeople.rdt.ui.PerspectiveRuby"
id="org.rubypeople.rdt.ui.wizards.RubyNewClassWizard">
<description>
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/IUIConstants.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/IUIConstants.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/IUIConstants.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -0,0 +1,7 @@
+package org.rubypeople.rdt.internal.ui;
+
+import org.rubypeople.rdt.ui.RubyUI;
+
+public interface IUIConstants {
+ public static final String DIALOGSTORE_TYPECOMMENT_DEPRECATED= RubyUI.ID_PLUGIN + ".typecomment.deprecated"; //$NON-NLS-1$
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.java 2006-12-15 15:40:46 UTC (rev 1713)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -46,7 +46,7 @@
}
public static String getFormattedString(String key, String[] args) {
- return MessageFormat.format(getString(key), args);
+ return MessageFormat.format(getString(key), (Object[])args);
}
public static ResourceBundle getResourceBundle() {
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewClassCreationWizard.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewClassCreationWizard.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewClassCreationWizard.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * 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.ui.wizards;
+
+import org.eclipse.core.resources.IFile;
+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.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.RubyPluginImages;
+import org.rubypeople.rdt.ui.wizards.NewClassWizardPage;
+
+public class NewClassCreationWizard extends NewElementWizard {
+
+ private NewClassWizardPage fPage;
+
+ public NewClassCreationWizard(NewClassWizardPage page) {
+ setDefaultPageImageDescriptor(RubyPluginImages.DESC_WIZBAN_NEWCLASS);
+ setDialogSettings(RubyPlugin.getDefault().getDialogSettings());
+ setWindowTitle(NewWizardMessages.NewClassCreationWizard_title);
+
+ fPage= page;
+ }
+
+ public NewClassCreationWizard() {
+ this(null);
+ }
+
+ /*
+ * @see Wizard#createPages
+ */
+ public void addPages() {
+ super.addPages();
+ if (fPage == null) {
+ fPage= new NewClassWizardPage();
+ fPage.init(getSelection());
+ }
+ addPage(fPage);
+ }
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
+ fPage.createType(monitor); // use the full progress monitor
+ }
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.jface.wizard.IWizard#performFinish()
+ */
+ public boolean performFinish() {
+ warnAboutTypeCommentDeprecation();
+ boolean res= super.performFinish();
+ if (res) {
+ IResource resource= fPage.getModifiedResource();
+ if (resource != null) {
+ selectAndReveal(resource);
+ openResource((IFile) resource);
+ }
+ }
+ return res;
+ }
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#getCreatedElement()
+ */
+ public IRubyElement getCreatedElement() {
+ return fPage.getCreatedType();
+ }
+
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewClassWizardAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewClassWizardAction.java 2006-12-15 15:40:46 UTC (rev 1713)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewClassWizardAction.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -4,7 +4,6 @@
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.PlatformUI;
import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
-import org.rubypeople.rdt.ui.wizards.RubyNewClassWizard;
public class NewClassWizardAction extends AbstractOpenWizardAction {
@@ -20,7 +19,7 @@
}
protected Wizard createWizard() throws CoreException {
- return new RubyNewClassWizard();
+ return new NewClassCreationWizard();
}
}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewElementWizard.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewElementWizard.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewElementWizard.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * 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.ui.wizards;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.text.templates.persistence.TemplateStore;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.internal.ui.IUIConstants;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.actions.WorkbenchRunnableAdapter;
+import org.rubypeople.rdt.internal.ui.dialogs.OptionalMessageDialog;
+import org.rubypeople.rdt.internal.ui.util.ExceptionHandler;
+
+public abstract class NewElementWizard extends Wizard implements INewWizard {
+
+ private IWorkbench fWorkbench;
+ private IStructuredSelection fSelection;
+
+ public NewElementWizard() {
+ setNeedsProgressMonitor(true);
+ }
+
+ protected void openResource(final IFile resource) {
+ final IWorkbenchPage activePage= RubyPlugin.getActivePage();
+ if (activePage != null) {
+ final Display display= getShell().getDisplay();
+ if (display != null) {
+ display.asyncExec(new Runnable() {
+ public void run() {
+ try {
+ IDE.openEditor(activePage, resource, true);
+ } catch (PartInitException e) {
+ RubyPlugin.log(e);
+ }
+ }
+ });
+ }
+ }
+ }
+
+ /**
+ * Subclasses should override to perform the actions of the wizard.
+ * This method is run in the wizard container's context as a workspace runnable.
+ * @param monitor
+ * @throws InterruptedException
+ * @throws CoreException
+ */
+ protected abstract void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException;
+
+ /**
+ * Returns the scheduling rule for creating the element.
+ */
+ protected ISchedulingRule getSchedulingRule() {
+ return ResourcesPlugin.getWorkspace().getRoot(); // look all by default
+ }
+
+
+ protected boolean canRunForked() {
+ return true;
+ }
+
+ public abstract IRubyElement getCreatedElement();
+
+ protected void handleFinishException(Shell shell, InvocationTargetException e) {
+ String title= NewWizardMessages.NewElementWizard_op_error_title;
+ String message= NewWizardMessages.NewElementWizard_op_error_message;
+ ExceptionHandler.handle(e, shell, title, message);
+ }
+
+ /*
+ * @see Wizard#performFinish
+ */
+ public boolean performFinish() {
+ IWorkspaceRunnable op= new IWorkspaceRunnable() {
+ public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
+ try {
+ finishPage(monitor);
+ } catch (InterruptedException e) {
+ throw new OperationCanceledException(e.getMessage());
+ }
+ }
+ };
+ try {
+ ISchedulingRule rule= null;
+ Job job= Platform.getJobManager().currentJob();
+ if (job != null)
+ rule= job.getRule();
+ IRunnableWithProgress runnable= null;
+ if (rule != null)
+ runnable= new WorkbenchRunnableAdapter(op, rule, true);
+ else
+ runnable= new WorkbenchRunnableAdapter(op, getSchedulingRule());
+ getContainer().run(canRunForked(), true, runnable);
+ } catch (InvocationTargetException e) {
+ handleFinishException(getShell(), e);
+ return false;
+ } catch (InterruptedException e) {
+ return false;
+ }
+ return true;
+ }
+
+ protected void warnAboutTypeCommentDeprecation() {
+ String key= IUIConstants.DIALOGSTORE_TYPECOMMENT_DEPRECATED;
+ if (OptionalMessageDialog.isDialogEnabled(key)) {
+ TemplateStore templates= RubyPlugin.getDefault().getTemplateStore();
+ boolean isOldWorkspace= templates.findTemplate("filecomment") != null && templates.findTemplate("typecomment") != null; //$NON-NLS-1$ //$NON-NLS-2$
+ if (!isOldWorkspace) {
+ OptionalMessageDialog.setDialogEnabled(key, false);
+ }
+ String title= NewWizardMessages.NewElementWizard_typecomment_deprecated_title;
+ String message= NewWizardMessages.NewElementWizard_typecomment_deprecated_message;
+ OptionalMessageDialog.open(key, getShell(), title, null, message, MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0);
+ }
+ }
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
+ fWorkbench= workbench;
+ fSelection= currentSelection;
+ }
+
+ public IStructuredSelection getSelection() {
+ return fSelection;
+ }
+
+ public IWorkbench getWorkbench() {
+ return fWorkbench;
+ }
+
+ protected void selectAndReveal(IResource newResource) {
+ BasicNewResourceWizard.selectAndReveal(newResource, fWorkbench.getActiveWorkbenchWindow());
+ }
+
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.java 2006-12-15 15:40:46 UTC (rev 1713)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -51,6 +51,14 @@
public static String NewTypeWizardPage_operationdesc;
public static String NewElementWizard_op_error_title;
public static String NewElementWizard_op_error_message;
+ public static String NewElementWizard_typecomment_deprecated_title;
+ public static String NewElementWizard_typecomment_deprecated_message;
+ public static String NewClassCreationWizard_title;
+ public static String NewClassWizardPage_title;
+ public static String NewClassWizardPage_description;
+ public static String NewClassWizardPage_methods_main;
+ public static String NewClassWizardPage_methods_constructors;
+ public static String NewClassWizardPage_methods_label;
static {
NLS.initializeMessages(BUNDLE_NAME, NewWizardMessages.class);
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.properties 2006-12-15 15:40:46 UTC (rev 1713)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.properties 2006-12-15 21:55:07 UTC (rev 1714)
@@ -45,4 +45,16 @@
NewTypeWizardPage_InterfacesDialog_class_title= Implemented Interfaces Selection
NewTypeWizardPage_error_EnterTypeName=Type name is empty.
+
+# ------- NewClassWizardPage -------
+
+NewClassCreationWizard_title=New Ruby Class
+
+NewClassWizardPage_title=Ruby Class
+NewClassWizardPage_description=Create a new Ruby class.
+
+NewClassWizardPage_methods_label=Which method stubs would you like to create?
+
+NewClassWizardPage_methods_main=public static void main(Strin&g[] args)
+NewClassWizardPage_methods_constructors=&Constructors from superclass
\ No newline at end of file
Deleted: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/RubyNewClassWizardPage.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/RubyNewClassWizardPage.java 2006-12-15 15:40:46 UTC (rev 1713)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/RubyNewClassWizardPage.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -1,245 +0,0 @@
-package org.rubypeople.rdt.internal.ui.wizards;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.dialogs.IDialogPage;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.dialogs.ContainerSelectionDialog;
-import org.eclipse.ui.dialogs.ElementListSelectionDialog;
-import org.rubypeople.rdt.core.IRubyElement;
-import org.rubypeople.rdt.ui.wizards.RubyClassSelectionDialog;
-
-/**
- * The "New" wizard page allows setting the container for the new file as well
- * as the file name. The page will only accept file name without the extension
- * OR with the extension that matches the expected one (mpe).
- */
-
-public class RubyNewClassWizardPage extends WizardPage {
-
- private Text containerText;
-
- private Text classText;
-
- private Text superclassText;
-
- private ISelection selection;
-
- /**
- * Constructor for SampleNewWizardPage.
- *
- * @param pageName
- */
- public RubyNewClassWizardPage(ISelection selection) {
- super("wizardPage");
- setTitle("New Ruby Class");
- setDescription("This wizard creates a new Ruby file with *.rb extension.");
- this.selection = selection;
- }
-
- /**
- * @see IDialogPage#createControl(Composite)
- */
- public void createControl(Composite parent) {
- Composite container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- layout.numColumns = 3;
- layout.verticalSpacing = 9;
- Label label = new Label(container, SWT.NULL);
- label.setText("&Container:");
-
- containerText = new Text(container, SWT.BORDER | SWT.SINGLE);
- GridData gd = new GridData(GridData.FILL_HORIZONTAL);
- containerText.setLayoutData(gd);
- containerText.addModifyListener(new ModifyListener() {
-
- public void modifyText(ModifyEvent e) {
- dialogChanged();
- }
- });
-
- Button button = new Button(container, SWT.PUSH);
- button.setText("Browse...");
- button.addSelectionListener(new SelectionAdapter() {
-
- public void widgetSelected(SelectionEvent e) {
- handleBrowse();
- }
- });
-
- label = new Label(container, SWT.NULL);
- label.setText("&Superclass:");
-
- superclassText = new Text(container, SWT.BORDER | SWT.SINGLE);
- gd = new GridData(GridData.FILL_HORIZONTAL);
- superclassText.setLayoutData(gd);
- superclassText.addModifyListener(new ModifyListener() {
-
- public void modifyText(ModifyEvent e) {
- dialogChanged();
- }
- });
- button = new Button(container, SWT.PUSH);
- button.setText("Browse...");
- button.addSelectionListener(new SelectionAdapter() {
-
- public void widgetSelected(SelectionEvent e) {
- handleSuperClassBrowse();
- }
- });
-
- label = new Label(container, SWT.NULL);
- label.setText("Class &name:");
-
- classText = new Text(container, SWT.BORDER | SWT.SINGLE);
- gd = new GridData(GridData.FILL_HORIZONTAL);
- classText.setLayoutData(gd);
- classText.addModifyListener(new ModifyListener() {
-
- public void modifyText(ModifyEvent e) {
- dialogChanged();
- }
- });
-
- initialize();
- dialogChanged();
- setControl(container);
- }
-
- /**
- * Tests if the current workbench selection is a suitable container to use.
- */
- private void initialize() {
- if (selection != null && selection.isEmpty() == false
- && selection instanceof IStructuredSelection) {
- IStructuredSelection ssel = (IStructuredSelection) selection;
- if (ssel.size() > 1) return;
- Object obj = ssel.getFirstElement();
- if (obj instanceof IResource) {
- IContainer container;
- if (obj instanceof IContainer)
- container = (IContainer) obj;
- else
- container = ((IResource) obj).getParent();
- containerText.setText(container.getFullPath().toString());
- }
- }
- classText.setText("MyNewClass");
- superclassText.setText("Object");
- }
-
- /**
- * Uses the standard container selection dialog to choose the new value for
- * the container field.
- */
-
- private void handleSuperClassBrowse() {
- ElementListSelectionDialog dialog = new RubyClassSelectionDialog(getShell());
- if (dialog.open() == Window.OK) {
- superclassText.setText(((IRubyElement) dialog.getFirstResult()).getElementName());
- }
- }
-
- /**
- * Uses the standard container selection dialog to choose the new value for
- * the container field.
- */
- private void handleBrowse() {
- ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), ResourcesPlugin
- .getWorkspace().getRoot(), false, "Select new file container");
- if (dialog.open() == ContainerSelectionDialog.OK) {
- Object[] result = dialog.getResult();
- if (result.length == 1) {
- containerText.setText(((Path) result[0]).toString());
- }
- }
- }
-
- /**
- * Ensures that both text fields are set.
- */
-
- private void dialogChanged() {
- IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(
- new Path(getContainerName()));
- String className = getClassName();
- String superclassName = getSuperclassName();
-
- if (getContainerName().length() == 0) {
- updateStatus("File container must be specified");
- return;
- }
- if (container == null
- || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
- updateStatus("File container must exist");
- return;
- }
- if (!container.isAccessible()) {
- updateStatus("Project must be writable");
- return;
- }
- if (className.length() == 0) {
- updateStatus("Class name must be specified");
- return;
- }
- if (!isConstant(className)) {
- updateStatus("Class name must be a constant. It must begin with a capital letter, and contain only letters, digits, or underscores.");
- return;
- }
- // TODO Verify superclass exists in workspace?
- if (superclassName != null && superclassName.length() > 0 && !isConstant(superclassName)) {
- updateStatus("Superclass name must be a constant. It must begin with a capital letter, and contain only letters, digits, or underscores.");
- return;
- }
- updateStatus(null);
- }
-
- private boolean isConstant(String className) {
- if (className == null || className.length() == 0) return false;
- if (!Character.isLowerCase(className.charAt(0)) && !Character.isLetter(className.charAt(0)))
- return false;
- int namespaceDelimeterIndex = className.indexOf("::");
- if (namespaceDelimeterIndex != -1) {
- return isConstant(className.substring(0, namespaceDelimeterIndex)) && isConstant(className.substring(namespaceDelimeterIndex+2));
- }
- for (int i = 0; i < className.length(); i++) {
- char c = className.charAt(i);
- if (!Character.isLetterOrDigit(c) && c != '_') return false;
- }
- return true;
- }
-
- private void updateStatus(String message) {
- setErrorMessage(message);
- setPageComplete(message == null);
- }
-
- public String getContainerName() {
- return containerText.getText();
- }
-
- public String getClassName() {
- return classText.getText();
- }
-
- public String getSuperclassName() {
- return superclassText.getText();
- }
-}
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/dialogfields/SelectionButtonDialogFieldGroup.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/dialogfields/SelectionButtonDialogFieldGroup.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/dialogfields/SelectionButtonDialogFieldGroup.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -0,0 +1,275 @@
+/*******************************************************************************
+ * 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.ui.wizards.dialogfields;
+
+import org.eclipse.core.runtime.Assert;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+
+
+/**
+ * Dialog field describing a group with buttons (Checkboxes, radio buttons..)
+ */
+public class SelectionButtonDialogFieldGroup extends DialogField {
+
+ private Composite fButtonComposite;
+
+ private Button[] fButtons;
+ private String[] fButtonNames;
+ private boolean[] fButtonsSelected;
+ private boolean[] fButtonsEnabled;
+
+ private int fGroupBorderStyle;
+ private int fGroupNumberOfColumns;
+ private int fButtonsStyle;
+
+ /**
+ * Creates a group without border.
+ */
+ public SelectionButtonDialogFieldGroup(int buttonsStyle, String[] buttonNames, int nColumns) {
+ this(buttonsStyle, buttonNames, nColumns, SWT.NONE);
+ }
+
+
+ /**
+ * Creates a group with border (label in border).
+ * Accepted button styles are: SWT.RADIO, SWT.CHECK, SWT.TOGGLE
+ * For border styles see <code>Group</code>
+ */
+ public SelectionButtonDialogFieldGroup(int buttonsStyle, String[] buttonNames, int nColumns, int borderStyle) {
+ super();
+
+ Assert.isTrue(buttonsStyle == SWT.RADIO || buttonsStyle == SWT.CHECK || buttonsStyle == SWT.TOGGLE);
+ fButtonNames= buttonNames;
+ fButtonsStyle= buttonsStyle;
+
+ int nButtons= buttonNames.length;
+ fButtonsSelected= new boolean[nButtons];
+ fButtonsEnabled= new boolean[nButtons];
+ for (int i= 0; i < nButtons; i++) {
+ fButtonsSelected[i]= false;
+ fButtonsEnabled[i]= true;
+ }
+ if (buttonsStyle == SWT.RADIO) {
+ fButtonsSelected[0]= true;
+ }
+
+ fGroupBorderStyle= borderStyle;
+ fGroupNumberOfColumns= (nColumns <= 0) ? nButtons : nColumns;
+
+
+
+ }
+
+ // ------- layout helpers
+
+ /*
+ * @see DialogField#doFillIntoGrid
+ */
+ public Control[] doFillIntoGrid(Composite parent, int nColumns) {
+ assertEnoughColumns(nColumns);
+
+ if (fGroupBorderStyle == SWT.NONE) {
+ Label label= getLabelControl(parent);
+ label.setLayoutData(gridDataForLabel(1));
+
+ Composite buttonsgroup= getSelectionButtonsGroup(parent);
+ GridData gd= new GridData();
+ gd.horizontalSpan= nColumns - 1;
+ buttonsgroup.setLayoutData(gd);
+
+ return new Control[] { label, buttonsgroup };
+ } else {
+ Composite buttonsgroup= getSelectionButtonsGroup(parent);
+ GridData gd= new GridData();
+ gd.horizontalSpan= nColumns;
+ buttonsgroup.setLayoutData(gd);
+
+ return new Control[] { buttonsgroup };
+ }
+ }
+
+ /*
+ * @see DialogField#doFillIntoGrid
+ */
+ public int getNumberOfControls() {
+ return (fGroupBorderStyle == SWT.NONE) ? 2 : 1;
+ }
+
+ // ------- ui creation
+
+ private Button createSelectionButton(int index, Composite group, SelectionListener listener) {
+ Button button= new Button(group, fButtonsStyle | SWT.LEFT);
+ button.setFont(group.getFont());
+ button.setText(fButtonNames[index]);
+ button.setEnabled(isEnabled() && fButtonsEnabled[index]);
+ button.setSelection(fButtonsSelected[index]);
+ button.addSelectionListener(listener);
+ button.setLayoutData(new GridData());
+ return button;
+ }
+
+ /**
+ * Returns the group widget. When called the first time, the widget will be created.
+ * @param parent The parent composite when called the first time, or <code>null</code>
+ * after.
+ */
+ public Composite getSelectionButtonsGroup(Composite parent) {
+ if (fButtonComposite == null) {
+ assertCompositeNotNull(parent);
+
+ GridLayout layout= new GridLayout();
+ layout.makeColumnsEqualWidth= true;
+ layout.numColumns= fGroupNumberOfColumns;
+
+ if (fGroupBorderStyle != SWT.NONE) {
+ Group group= new Group(parent, fGroupBorderStyle);
+ group.setFont(parent.getFont());
+ if (fLabelText != null && fLabelText.length() > 0) {
+ group.setText(fLabelText);
+ }
+ fButtonComposite= group;
+ } else {
+ fButtonComposite= new Composite(parent, SWT.NONE);
+ fButtonComposite.setFont(parent.getFont());
+ layout.marginHeight= 0;
+ layout.marginWidth= 0;
+ }
+
+ fButtonComposite.setLayout(layout);
+
+ SelectionListener listener= new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ doWidgetSelected(e);
+ }
+ public void widgetSelected(SelectionEvent e) {
+ doWidgetSelected(e);
+ }
+ };
+ int nButtons= fButtonNames.length;
+ fButtons= new Button[nButtons];
+ for (int i= 0; i < nButtons; i++) {
+ fButtons[i]= createSelectionButton(i, fButtonComposite, listener);
+ }
+ int nRows= nButtons / fGroupNumberOfColumns;
+ int nFillElements= nRows * fGroupNumberOfColumns - nButtons;
+ for (int i= 0; i < nFillElements; i++) {
+ createEmptySpace(fButtonComposite);
+ }
+ }
+ return fButtonComposite;
+ }
+
+ /**
+ * Returns a button from the group or <code>null</code> if not yet created.
+ */
+ public Button getSelectionButton(int index) {
+ if (index >= 0 && index < fButtons.length) {
+ return fButtons[index];
+ }
+ return null;
+ }
+
+ private void doWidgetSelected(SelectionEvent e) {
+ Button button= (Button)e.widget;
+ for (int i= 0; i < fButtons.length; i++) {
+ if (fButtons[i] == button) {
+ fButtonsSelected[i]= button.getSelection();
+ dialogFieldChanged();
+ return;
+ }
+ }
+ }
+
+ // ------ model access
+
+ /**
+ * Returns the selection state of a button contained in the group.
+ * @param index The index of the button
+ */
+ public boolean isSelected(int index) {
+ if (index >= 0 && index < fButtonsSelected.length) {
+ return fButtonsSelected[index];
+ }
+ return false;
+ }
+
+ /**
+ * Sets the selection state of a button contained in the group.
+ */
+ public void setSelection(int index, boolean selected) {
+ if (index >= 0 && index < fButtonsSelected.length) {
+ if (fButtonsSelected[index] != selected) {
+ fButtonsSelected[index]= selected;
+ if (fButtons != null) {
+ Button button= fButtons[index];
+ if (isOkToUse(button)) {
+ button.setSelection(selected);
+ }
+ }
+ }
+ }
+ }
+
+ // ------ enable / disable management
+
+ protected void updateEnableState() {
+ super.updateEnableState();
+ if (fButtons != null) {
+ boolean enabled= isEnabled();
+ for (int i= 0; i < fButtons.length; i++) {
+ Button button= fButtons[i];
+ if (isOkToUse(button)) {
+ button.setEnabled(enabled && fButtonsEnabled[i]);
+ }
+ }
+ }
+ }
+
+ /**
+ * Sets the enable state of a button contained in the group.
+ */
+ public void enableSelectionButton(int index, boolean enable) {
+ if (index >= 0 && index < fButtonsEnabled.length) {
+ fButtonsEnabled[index]= enable;
+ if (fButtons != null) {
+ Button button= fButtons[index];
+ if (isOkToUse(button)) {
+ button.setEnabled(isEnabled() && enable);
+ }
+ }
+ }
+ }
+
+
+ /*(non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField#refresh()
+ */
+ public void refresh() {
+ super.refresh();
+ for (int i= 0; i < fButtons.length; i++) {
+ Button button= fButtons[i];
+ if (isOkToUse(button)) {
+ button.setSelection(fButtonsSelected[i]);
+ }
+ }
+ }
+
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewClassWizardPage.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewClassWizardPage.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewClassWizardPage.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -0,0 +1,254 @@
+/*******************************************************************************
+ * 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.ui.wizards;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.DialogField;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.LayoutUtil;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFieldGroup;
+
+
+/**
+ * Wizard page to create a new class.
+ * <p>
+ * Note: This class is not intended to be subclassed, but clients can instantiate.
+ * To implement a different kind of a new class wizard page, extend <code>NewTypeWizardPage</code>.
+ * </p>
+ *
+ * @since 2.0
+ */
+public class NewClassWizardPage extends NewTypeWizardPage {
+
+ private final static String PAGE_NAME= "NewClassWizardPage"; //$NON-NLS-1$
+
+ private final static String SETTINGS_CREATEMAIN= "create_main"; //$NON-NLS-1$
+ private final static String SETTINGS_CREATECONSTR= "create_constructor"; //$NON-NLS-1$
+
+ private SelectionButtonDialogFieldGroup fMethodStubsButtons;
+
+ /**
+ * Creates a new <code>NewClassWizardPage</code>
+ */
+ public NewClassWizardPage() {
+ super(true, PAGE_NAME);
+
+ setTitle(NewWizardMessages.NewClassWizardPage_title);
+ setDescription(NewWizardMessages.NewClassWizardPage_description);
+
+ String[] buttonNames3= new String[] {
+ NewWizardMessages.NewClassWizardPage_methods_main, NewWizardMessages.NewClassWizardPage_methods_constructors
+ };
+ fMethodStubsButtons= new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames3, 1);
+ fMethodStubsButtons.setLabelText(NewWizardMessages.NewClassWizardPage_methods_label);
+ }
+
+ // -------- Initialization ---------
+
+ /**
+ * The wizard owning this page is responsible for calling this method with the
+ * current selection. The selection is used to initialize the fields of the wizard
+ * page.
+ *
+ * @param selection used to initialize the fields
+ */
+ public void init(IStructuredSelection selection) {
+ IRubyElement jelem= getInitialRubyElement(selection);
+ initContainerPage(jelem);
+ initTypePage(jelem);
+ doStatusUpdate();
+
+ boolean createMain= false;
+ boolean createConstructors= false;
+ boolean createUnimplemented= true;
+ IDialogSettings dialogSettings= getDialogSettings();
+ if (dialogSettings != null) {
+ IDialogSettings section= dialogSettings.getSection(PAGE_NAME);
+ if (section != null) {
+ createMain= section.getBoolean(SETTINGS_CREATEMAIN);
+ createConstructors= section.getBoolean(SETTINGS_CREATECONSTR);
+ }
+ }
+
+ setMethodStubSelection(createMain, createConstructors, true);
+ }
+
+ // ------ validation --------
+ private void doStatusUpdate() {
+ // status of all used components
+ IStatus[] status= new IStatus[] {
+ fContainerStatus,
+ fTypeNameStatus,
+ fSuperClassStatus,
+ fSuperInterfacesStatus
+ };
+
+ // the mode severe status will be displayed and the OK button enabled/disabled.
+ updateStatus(status);
+ }
+
+
+ /*
+ * @see NewContainerWizardPage#handleFieldChanged
+ */
+ protected void handleFieldChanged(String fieldName) {
+ super.handleFieldChanged(fieldName);
+
+ doStatusUpdate();
+ }
+
+
+ // ------ UI --------
+
+ /*
+ * @see WizardPage#createControl
+ */
+ public void createControl(Composite parent) {
+ initializeDialogUnits(parent);
+
+ Composite composite= new Composite(parent, SWT.NONE);
+ composite.setFont(parent.getFont());
+
+ int nColumns= 4;
+
+ GridLayout layout= new GridLayout();
+ layout.numColumns= nColumns;
+ composite.setLayout(layout);
+
+ // pick & choose the wanted UI components
+
+ createContainerControls(composite, nColumns);
+// createPackageControls(composite, nColumns);
+// createEnclosingTypeControls(composite, nColumns);
+
+ createSeparator(composite, nColumns);
+
+ createTypeNameControls(composite, nColumns);
+// createModifierControls(composite, nColumns);
+
+ createSuperClassControls(composite, nColumns);
+// createSuperInterfacesControls(composite, nColumns);
+
+ createMethodStubSelectionControls(composite, nColumns);
+
+// createCommentControls(composite, nColumns);
+// enableCommentControl(true);
+
+ setControl(composite);
+
+ Dialog.applyDialogFont(composite);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IRubyHelpContextIds.NEW_CLASS_WIZARD_PAGE);
+ }
+
+ /*
+ * @see WizardPage#becomesVisible
+ */
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ if (visible) {
+ setFocus();
+ } else {
+ IDialogSettings dialogSettings= getDialogSettings();
+ if (dialogSettings != null) {
+ IDialogSettings section= dialogSettings.getSection(PAGE_NAME);
+ if (section == null) {
+ section= dialogSettings.addNewSection(PAGE_NAME);
+ }
+ section.put(SETTINGS_CREATEMAIN, isCreateMain());
+ section.put(SETTINGS_CREATECONSTR, isCreateConstructors());
+ }
+ }
+ }
+
+ private void createMethodStubSelectionControls(Composite composite, int nColumns) {
+ Control labelControl= fMethodStubsButtons.getLabelControl(composite);
+ LayoutUtil.setHorizontalSpan(labelControl, nColumns);
+
+ DialogField.createEmptySpace(composite);
+
+ Control buttonGroup= fMethodStubsButtons.getSelectionButtonsGroup(composite);
+ LayoutUtil.setHorizontalSpan(buttonGroup, nColumns - 1);
+ }
+
+ /**
+ * Returns the current selection state of the 'Create Main' checkbox.
+ *
+ * @return the selection state of the 'Create Main' checkbox
+ */
+ public boolean isCreateMain() {
+ return fMethodStubsButtons.isSelected(0);
+ }
+
+ /**
+ * Returns the current selection state of the 'Create Constructors' checkbox.
+ *
+ * @return the selection state of the 'Create Constructors' checkbox
+ */
+ public boolean isCreateConstructors() {
+ return fMethodStubsButtons.isSelected(1);
+ }
+
+ /**
+ * Sets the selection state of the method stub checkboxes.
+ *
+ * @param createMain initial selection state of the 'Create Main' checkbox.
+ * @param createConstructors initial selection state of the 'Create Constructors' checkbox.
+ * @param canBeModified if <code>true</code> the method stub checkboxes can be changed by
+ * the user. If <code>false</code> the buttons are "read-only"
+ */
+ public void setMethodStubSelection(boolean createMain, boolean createConstructors, boolean canBeModified) {
+ fMethodStubsButtons.setSelection(0, createMain);
+ fMethodStubsButtons.setSelection(1, createConstructors);
+
+ fMethodStubsButtons.setEnabled(canBeModified);
+ }
+
+ // ---- creation ----------------
+
+ /*
+ * @see NewTypeWizardPage#createTypeMembers
+ */
+ protected void createTypeMembers(IType type, IProgressMonitor monitor) throws CoreException {
+// boolean doMain= isCreateMain();
+ // TODO Create a main method?!
+ boolean doConstr= isCreateConstructors();
+
+ if (doConstr) {
+ StringBuffer buf= new StringBuffer();
+ final String lineDelim= "\n"; // OK, since content is formatted afterwards //$NON-NLS-1$
+ buf.append("def initialize"); //$NON-NLS-1$
+ buf.append(lineDelim);
+ buf.append("super");
+ buf.append(lineDelim);
+ buf.append("end"); //$NON-NLS-1$
+ buf.append(lineDelim);
+ type.createMethod(buf.toString(), null, false, null);
+ }
+
+ if (monitor != null) {
+ monitor.done();
+ }
+ }
+
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewContainerWizardPage.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewContainerWizardPage.java 2006-12-15 15:40:46 UTC (rev 1713)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewContainerWizardPage.java 2006-12-15 21:55:07 UTC (rev 1714)
@@ -10,12 +10,15 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.views.contentoutline.ContentOutline;
@@ -28,7 +31,6 @@
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.dialogs.StatusUtil;
import org.rubypeople.rdt.internal.ui.viewsupport.IViewPartInputProvider;
import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
import org.rubypeople.rdt.internal.ui.wizards.TypedElementSelectionValidator;
@@ -42,7 +44,7 @@
import org.rubypeople.rdt.ui.RubyElementSorter;
import org.rubypeople.rdt.u...
[truncated message content] |