|
From: <caw...@us...> - 2007-05-01 15:30:33
|
Revision: 2408
http://svn.sourceforge.net/rubyeclipse/?rev=2408&view=rev
Author: cawilliams
Date: 2007-05-01 08:30:23 -0700 (Tue, 01 May 2007)
Log Message:
-----------
change our wizards to use new type selection dialogs,
remove unused RubyModuleSelectionDialog,
fix class stub creation to take superclass into account,
make test case creation use proper line delimeters so Eclipse doesn't complain.
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchEngine.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/wizards/RubyNewTestCaseWizardPage.java
trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPlugin.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/internal/ui/wizards/dialogfields/ListDialogField.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewTypeWizardPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/RubyClassSelectionDialog.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/SuperModuleSelectionDialog.java
Removed Paths:
-------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/RubyModuleSelectionDialog.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchEngine.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchEngine.java 2007-05-01 14:54:54 UTC (rev 2407)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchEngine.java 2007-05-01 15:30:23 UTC (rev 2408)
@@ -1,6 +1,7 @@
package org.rubypeople.rdt.core.search;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.core.WorkingCopyOwner;
import org.rubypeople.rdt.internal.core.search.BasicSearchEngine;
@@ -95,4 +96,8 @@
this.basicEngine.searchAllTypeNames(packageName, typeName, matchRule, searchFor, scope, nameRequestor, waitingPolicy, progressMonitor);
}
+ public static IRubySearchScope createRubySearchScope(IRubyElement[] elements) {
+ return BasicSearchEngine.createRubySearchScope(elements);
+ }
+
}
Modified: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/wizards/RubyNewTestCaseWizardPage.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/wizards/RubyNewTestCaseWizardPage.java 2007-05-01 14:54:54 UTC (rev 2407)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/wizards/RubyNewTestCaseWizardPage.java 2007-05-01 15:30:23 UTC (rev 2408)
@@ -26,13 +26,17 @@
import org.rubypeople.rdt.core.IType;
import org.rubypeople.rdt.core.RubyConventions;
import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.core.search.IRubySearchConstants;
+import org.rubypeople.rdt.core.search.IRubySearchScope;
+import org.rubypeople.rdt.core.search.SearchEngine;
+import org.rubypeople.rdt.internal.corext.codemanipulation.StubUtility;
import org.rubypeople.rdt.internal.corext.util.Messages;
import org.rubypeople.rdt.internal.testunit.util.LayoutUtil;
import org.rubypeople.rdt.internal.testunit.util.TestUnitStatus;
import org.rubypeople.rdt.internal.testunit.wizards.MethodStubsSelectionButtonGroup;
import org.rubypeople.rdt.internal.testunit.wizards.WizardMessages;
+import org.rubypeople.rdt.internal.ui.dialogs.TypeSelectionDialog2;
import org.rubypeople.rdt.ui.wizards.NewTypeWizardPage;
-import org.rubypeople.rdt.ui.wizards.RubyClassSelectionDialog;
public class RubyNewTestCaseWizardPage extends NewTypeWizardPage {
@@ -127,47 +131,58 @@
/* (non-Javadoc)
* @see org.eclipse.jdt.ui.wizards.NewTypeWizardPage#createTypeMembers(org.eclipse.jdt.core.IType, org.eclipse.jdt.ui.wizards.NewTypeWizardPage.ImportsManager, org.eclipse.core.runtime.IProgressMonitor)
*/
- protected void createTypeMembers(IType type, IProgressMonitor monitor) throws CoreException {
+ protected void createTypeMembers(IType type, IProgressMonitor monitor) throws CoreException {
+ String lineDelimiter= StubUtility.getLineDelimiterUsed(type.getRubyProject());
+
if (fMethodStubsButtons.isSelected(IDX_CONSTRUCTOR)) {
- createConstructor(type);
+ createConstructor(type, lineDelimiter);
}
if (fMethodStubsButtons.isSelected(IDX_SETUP)) {
- createSetUp(type);
+ createSetUp(type, lineDelimiter);
}
if (fMethodStubsButtons.isSelected(IDX_TEARDOWN)) {
- createTearDown(type);
+ createTearDown(type, lineDelimiter);
}
if (fClassUnderTest != null) {
- createTestMethodStubs(type);
+ createTestMethodStubs(type, lineDelimiter);
}
}
- private void createConstructor(IType type) throws CoreException {
- StringBuffer content = new StringBuffer("def initialize\n");
- content.append(" super\n");
- content.append("end\n");
+ private void createConstructor(IType type, String lineDelimiter) throws CoreException {
+ StringBuffer content = new StringBuffer("def initialize");
+ content.append(lineDelimiter);
+ content.append(" super");
+ content.append(lineDelimiter);
+ content.append("end");
+ content.append(lineDelimiter);
type.createMethod(content.toString(), null, true, null);
}
- private void createSetUp(IType type) throws CoreException {
- StringBuffer content = new StringBuffer("def setup\n");
- content.append(" super\n");
- content.append("end\n");
+ private void createSetUp(IType type, String lineDelimiter) throws CoreException {
+ StringBuffer content = new StringBuffer("def setup");
+ content.append(lineDelimiter);
+ content.append(" super");
+ content.append(lineDelimiter);
+ content.append("end");
+ content.append(lineDelimiter);
type.createMethod(content.toString(), null, true, null);
}
- private void createTearDown(IType type) throws CoreException {
- StringBuffer content = new StringBuffer("def teardown\n");
- content.append(" super\n");
- content.append("end\n");
+ private void createTearDown(IType type, String lineDelimiter) throws CoreException {
+ StringBuffer content = new StringBuffer("def teardown");
+ content.append(lineDelimiter);
+ content.append(" super");
+ content.append(lineDelimiter);
+ content.append("end");
+ content.append(lineDelimiter);
type.createMethod(content.toString(), null, true, null);
}
- private void createTestMethodStubs(IType type) throws CoreException {
+ private void createTestMethodStubs(IType type, String lineDelimiter) throws CoreException {
// StringBuffer content = new StringBuffer("def setup");
// content.append(" super\n");
// content.append("end\n");
@@ -238,21 +253,21 @@
private IType chooseClassToTestType() {
ISourceFolderRoot root= getSourceFolderRoot();
- if (root == null)
+ if (root == null) {
return null;
+ }
+
+ IRubyElement[] elements= new IRubyElement[] { root.getRubyProject() };
+ IRubySearchScope scope= SearchEngine.createRubySearchScope(elements);
-// IRubyElement[] elements= new IRubyElement[] { root.getRubyProject() };
+ TypeSelectionDialog2 dialog= new TypeSelectionDialog2(getShell(), false,
+ getWizard().getContainer(), scope, IRubySearchConstants.CLASS);
+ dialog.setTitle(WizardMessages.NewTestCaseWizardPage_class_to_test_dialog_title);
+ dialog.setMessage(WizardMessages.NewTestCaseWizardPage_class_to_test_dialog_message);
-
- RubyClassSelectionDialog dialog = new RubyClassSelectionDialog(getShell());
- dialog.setTitle(WizardMessages.NewTestCaseWizardPage_class_to_test_dialog_title);
- dialog.setMessage(WizardMessages.NewTestCaseWizardPage_class_to_test_dialog_message);
- if (dialog.open() == Window.OK) {
- Object[] resultArray= dialog.getResult();
- if (resultArray != null && resultArray.length > 0)
- return (IType) resultArray[0];
- }
-
+ if (dialog.open() == Window.OK) {
+ return (IType) dialog.getFirstResult();
+ }
return null;
}
Modified: trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF 2007-05-01 14:54:54 UTC (rev 2407)
+++ trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF 2007-05-01 15:30:23 UTC (rev 2408)
@@ -8,6 +8,7 @@
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.rubypeople.rdt.internal.corext,
+ org.rubypeople.rdt.internal.corext.codemanipulation,
org.rubypeople.rdt.internal.corext.util,
org.rubypeople.rdt.internal.ui,
org.rubypeople.rdt.internal.ui.actions,
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPlugin.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPlugin.java 2007-05-01 14:54:54 UTC (rev 2407)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPlugin.java 2007-05-01 15:30:23 UTC (rev 2408)
@@ -27,6 +27,7 @@
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.text.templates.ContextTypeRegistry;
@@ -566,5 +567,21 @@
if (fTypeFilter == null)
fTypeFilter= new TypeFilter();
return fTypeFilter;
+ }
+
+ /**
+ * Returns a section in the Ruby plugin's dialog settings. If the section doesn't exist yet, it is created.
+ *
+ * @param name the name of the section
+ * @return the section of the given name
+ * @since 1.0
+ */
+ public IDialogSettings getDialogSettingsSection(String name) {
+ IDialogSettings dialogSettings= getDialogSettings();
+ IDialogSettings section= dialogSettings.getSection(name);
+ if (section == null) {
+ section= dialogSettings.addNewSection(name);
+ }
+ return section;
}
}
\ No newline at end of file
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 2007-05-01 14:54:54 UTC (rev 2407)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.java 2007-05-01 15:30:23 UTC (rev 2408)
@@ -363,6 +363,11 @@
public static String RubyCapabilityConfigurationPage_description;
public static String RubyCapabilityConfigurationPage_op_desc_java;
public static String LoadPathDetector_operation_description;
+ public static String NewTypeWizardPage_SuperClassDialog_message;
+ public static String NewTypeWizardPage_SuperClassDialog_title;
+ public static String SuperModuleSelectionDialog_addButton_label;
+ public static String SuperModuleSelectionDialog_interfaceadded_info;
+ public static String SuperModuleSelectionDialog_interfacealreadyadded_info;
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 2007-05-01 14:54:54 UTC (rev 2407)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.properties 2007-05-01 15:30:23 UTC (rev 2408)
@@ -49,6 +49,9 @@
NewTypeWizardPage_error_EnterTypeName=Type name is empty.
+NewTypeWizardPage_SuperClassDialog_title=Superclass Selection
+NewTypeWizardPage_SuperClassDialog_message=&Choose a type:
+
NewTypeWizardPage_package_button=Bro&wse...
NewTypeWizardPage_package_label=Folder:
NewTypeWizardPage_ChoosePackageDialog_title=Package Selection
@@ -57,6 +60,12 @@
NewTypeWizardPage_error_InvalidPackageName=Package name is not valid. {0}
NewTypeWizardPage_warning_DiscouragedPackageName=This package name is discouraged. {0}
+# ------- SuperModuleSelectionDialog -----
+
+SuperModuleSelectionDialog_addButton_label=&Add
+SuperModuleSelectionDialog_interfaceadded_info=''{0}'' added.
+SuperModuleSelectionDialog_interfacealreadyadded_info=''{0}'' already in list.
+
# ------- NewClassWizardPage -------
NewClassCreationWizard_title=New Ruby Class
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/SuperModuleSelectionDialog.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/SuperModuleSelectionDialog.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/SuperModuleSelectionDialog.java 2007-05-01 15:30:23 UTC (rev 2408)
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * 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.ui.wizards;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.search.IRubySearchConstants;
+import org.rubypeople.rdt.core.search.IRubySearchScope;
+import org.rubypeople.rdt.core.search.SearchEngine;
+import org.rubypeople.rdt.internal.corext.util.Messages;
+import org.rubypeople.rdt.internal.corext.util.TypeInfo;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.dialogs.StatusInfo;
+import org.rubypeople.rdt.internal.ui.dialogs.TypeSelectionDialog2;
+import org.rubypeople.rdt.ui.wizards.NewTypeWizardPage;
+
+public class SuperModuleSelectionDialog extends TypeSelectionDialog2 {
+
+ private static final int ADD_ID= IDialogConstants.CLIENT_ID + 1;
+
+ private NewTypeWizardPage fTypeWizardPage;
+ private List fOldContent;
+
+ public SuperModuleSelectionDialog(Shell parent, IRunnableContext context, NewTypeWizardPage page, IRubyProject p) {
+ super(parent, true, context, createSearchScope(p), IRubySearchConstants.MODULE);
+ fTypeWizardPage= page;
+ // to restore the content of the dialog field if the dialog is canceled
+ fOldContent= fTypeWizardPage.getSuperModules();
+ setStatusLineAboveButtons(true);
+ }
+
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, ADD_ID, NewWizardMessages.SuperModuleSelectionDialog_addButton_label, true);
+ super.createButtonsForButtonBar(parent);
+ }
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
+ */
+ protected IDialogSettings getDialogBoundsSettings() {
+ return RubyPlugin.getDefault().getDialogSettingsSection("DialogBounds_SuperModuleSelectionDialog"); //$NON-NLS-1$
+ }
+
+ protected void updateButtonsEnableState(IStatus status) {
+ super.updateButtonsEnableState(status);
+ Button addButton = getButton(ADD_ID);
+ if (addButton != null && !addButton.isDisposed())
+ addButton.setEnabled(!status.matches(IStatus.ERROR));
+ }
+
+ protected void handleShellCloseEvent() {
+ super.handleShellCloseEvent();
+ // Handle the closing of the shell by selecting the close icon
+ fTypeWizardPage.setSuperModules(fOldContent, true);
+ }
+
+ protected void cancelPressed() {
+ fTypeWizardPage.setSuperModules(fOldContent, true);
+ super.cancelPressed();
+ }
+
+ protected void buttonPressed(int buttonId) {
+ if (buttonId == ADD_ID){
+ addSelectedInterface();
+ }
+ super.buttonPressed(buttonId);
+ }
+
+ protected void okPressed() {
+ addSelectedInterface();
+ super.okPressed();
+ }
+
+ private void addSelectedInterface() {
+ TypeInfo[] selection= getSelectedTypes();
+ if (selection == null)
+ return;
+ for (int i= 0; i < selection.length; i++) {
+ TypeInfo type= selection[i];
+ String qualifiedName= type.getFullyQualifiedName();
+ String message;
+ if (fTypeWizardPage.addSuperModule(qualifiedName)) {
+ message= Messages.format(NewWizardMessages.SuperModuleSelectionDialog_interfaceadded_info, qualifiedName);
+ } else {
+ message= Messages.format(NewWizardMessages.SuperModuleSelectionDialog_interfacealreadyadded_info, qualifiedName);
+ }
+ updateStatus(new StatusInfo(IStatus.INFO, message));
+ }
+ }
+
+ private static IRubySearchScope createSearchScope(IRubyProject p) {
+ return SearchEngine.createRubySearchScope(new IRubyProject[] { p });
+ }
+
+ protected void handleDefaultSelected(TypeInfo[] selection) {
+ if (selection.length > 0)
+ buttonPressed(ADD_ID);
+ }
+
+ protected void handleWidgetSelected(TypeInfo[] selection) {
+ super.handleWidgetSelected(selection);
+ getButton(ADD_ID).setEnabled(selection.length > 0);
+ }
+
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IRubyHelpContextIds.SUPER_INTERFACE_SELECTION_DIALOG);
+ }
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/dialogfields/ListDialogField.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/dialogfields/ListDialogField.java 2007-05-01 14:54:54 UTC (rev 2407)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/dialogfields/ListDialogField.java 2007-05-01 15:30:23 UTC (rev 2408)
@@ -604,16 +604,16 @@
/**
* Adds an element at the end of the list.
*/
- public void addElement(Object element) {
- addElement(element, fElements.size());
+ public boolean addElement(Object element) {
+ return addElement(element, fElements.size());
}
/**
* Adds an element at a position.
*/
- public void addElement(Object element, int index) {
+ public boolean addElement(Object element, int index) {
if (fElements.contains(element)) {
- return;
+ return false;
}
fElements.add(index, element);
if (isOkToUse(fTableControl)) {
@@ -622,6 +622,7 @@
}
dialogFieldChanged();
+ return true;
}
/**
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewTypeWizardPage.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewTypeWizardPage.java 2007-05-01 14:54:54 UTC (rev 2407)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewTypeWizardPage.java 2007-05-01 15:30:23 UTC (rev 2408)
@@ -1,6 +1,7 @@
package org.rubypeople.rdt.ui.wizards;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.core.resources.IResource;
@@ -31,6 +32,9 @@
import org.rubypeople.rdt.core.RubyConventions;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.core.formatter.CodeFormatter;
+import org.rubypeople.rdt.core.search.IRubySearchConstants;
+import org.rubypeople.rdt.core.search.IRubySearchScope;
+import org.rubypeople.rdt.core.search.SearchEngine;
import org.rubypeople.rdt.internal.core.RubyProject;
import org.rubypeople.rdt.internal.corext.codemanipulation.StubUtility;
import org.rubypeople.rdt.internal.corext.util.CodeFormatterUtil;
@@ -39,7 +43,9 @@
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.RubyPluginImages;
import org.rubypeople.rdt.internal.ui.dialogs.StatusInfo;
+import org.rubypeople.rdt.internal.ui.dialogs.TypeSelectionDialog2;
import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
+import org.rubypeople.rdt.internal.ui.wizards.SuperModuleSelectionDialog;
import org.rubypeople.rdt.internal.ui.wizards.dialogfields.DialogField;
import org.rubypeople.rdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
import org.rubypeople.rdt.internal.ui.wizards.dialogfields.IListAdapter;
@@ -110,13 +116,13 @@
private StringButtonStatusDialogField fPackageDialogField;
private StringButtonDialogField fSuperClassDialogField;
- private ListDialogField fSuperInterfacesDialogField;
+ private ListDialogField fSuperModulesDialogField;
private IType fCreatedType;
protected IStatus fTypeNameStatus;
protected IStatus fSuperClassStatus;
- protected IStatus fSuperInterfacesStatus;
+ protected IStatus fSuperModulesStatus;
private int fTypeKind;
private ISourceFolder fCurrSourceFolder;
@@ -182,15 +188,15 @@
/* 1 */ null,
NewWizardMessages.NewTypeWizardPage_interfaces_remove
};
- fSuperInterfacesDialogField= new ListDialogField(adapter, addButtons, new InterfacesListLabelProvider());
- fSuperInterfacesDialogField.setDialogFieldListener(adapter);
- fSuperInterfacesDialogField.setTableColumns(new ListDialogField.ColumnsDescription(1, false));
- fSuperInterfacesDialogField.setLabelText(getSuperInterfacesLabel());
- fSuperInterfacesDialogField.setRemoveButtonIndex(2);
+ fSuperModulesDialogField= new ListDialogField(adapter, addButtons, new InterfacesListLabelProvider());
+ fSuperModulesDialogField.setDialogFieldListener(adapter);
+ fSuperModulesDialogField.setTableColumns(new ListDialogField.ColumnsDescription(1, false));
+ fSuperModulesDialogField.setLabelText(getSuperModulesLabel());
+ fSuperModulesDialogField.setRemoveButtonIndex(2);
fTypeNameStatus= new StatusInfo();
fSuperClassStatus= new StatusInfo();
- fSuperInterfacesStatus= new StatusInfo();
+ fSuperModulesStatus= new StatusInfo();
}
/**
@@ -316,7 +322,7 @@
* @return the label that is used for the super interfaces input field.
* @since 3.2
*/
- protected String getSuperInterfacesLabel() {
+ protected String getSuperModulesLabel() {
if (fTypeKind != INTERFACE_TYPE)
return NewWizardMessages.NewTypeWizardPage_interfaces_class_label;
return NewWizardMessages.NewTypeWizardPage_interfaces_ifc_label;
@@ -472,12 +478,12 @@
}
private void typePageCustomButtonPressed(DialogField field, int index) {
- if (field == fSuperInterfacesDialogField) {
- chooseSuperInterfaces();
- List interfaces= fSuperInterfacesDialogField.getElements();
+ if (field == fSuperModulesDialogField) {
+ chooseSuperModules();
+ List interfaces= fSuperModulesDialogField.getElements();
if (!interfaces.isEmpty()) {
Object element= interfaces.get(interfaces.size() - 1);
- fSuperInterfacesDialogField.editElement(element);
+ fSuperModulesDialogField.editElement(element);
}
}
}
@@ -681,6 +687,11 @@
private String constructSimpleTypeStub(String lineDelimiter) {
StringBuffer buf= new StringBuffer("class "); //$NON-NLS-1$
buf.append(getTypeName());
+ String superclass = getSuperClass();
+ if (superclass != null && superclass.trim().length() > 0 && !superclass.trim().equals("Object") ) {
+ buf.append(" < ");
+ buf.append(superclass.trim());
+ }
buf.append(lineDelimiter);
buf.append("end"); //$NON-NLS-1$
return buf.toString();
@@ -688,27 +699,73 @@
/**
* Opens a selection dialog that allows to select the super interfaces. The selected interfaces are
- * directly added to the wizard page using {@link #addSuperInterface(String)}.
+ * directly added to the wizard page using {@link #addSuperModule(String)}.
*
* <p>
* Clients can override this method if they want to offer a different dialog.
* </p>
*
- * @since 3.2
+ * @since 1.0
*/
- protected void chooseSuperInterfaces() {
+ protected void chooseSuperModules() {
ISourceFolderRoot root= getSourceFolderRoot();
if (root == null) {
return;
}
- RubyModuleSelectionDialog dialog = new RubyModuleSelectionDialog(getShell());
- dialog.setTitle(getInterfaceDialogTitle());
+ IRubyProject project= root.getRubyProject();
+ SuperModuleSelectionDialog dialog= new SuperModuleSelectionDialog(getShell(), getWizard().getContainer(), this, project);
+ dialog.setTitle(getModuleDialogTitle());
dialog.setMessage(NewWizardMessages.NewTypeWizardPage_InterfacesDialog_message);
- dialog.open();
+ dialog.open();
}
- private String getInterfaceDialogTitle() {
+ /**
+ * Sets the super interfaces.
+ *
+ * @param interfacesNames a list of super interface. The method requires that
+ * the list's elements are of type <code>String</code>
+ * @param canBeModified if <code>true</code> the super interface field is
+ * editable; otherwise it is read-only.
+ */
+ public void setSuperModules(List interfacesNames, boolean canBeModified) {
+ ArrayList interfaces= new ArrayList(interfacesNames.size());
+ for (Iterator iter= interfacesNames.iterator(); iter.hasNext();) {
+ interfaces.add(new InterfaceWrapper((String) iter.next()));
+ }
+ fSuperModulesDialogField.setElements(interfaces);
+ fSuperModulesDialogField.setEnabled(canBeModified);
+ }
+
+ /**
+ * Returns the chosen super interfaces.
+ *
+ * @return a list of chosen super interfaces. The list's elements
+ * are of type <code>String</code>
+ */
+ public List getSuperModules() {
+ List interfaces= fSuperModulesDialogField.getElements();
+ ArrayList result= new ArrayList(interfaces.size());
+ for (Iterator iter= interfaces.iterator(); iter.hasNext();) {
+ InterfaceWrapper wrapper= (InterfaceWrapper) iter.next();
+ result.add(wrapper.interfaceName);
+ }
+ return result;
+ }
+
+ /**
+ * Adds a super interface to the end of the list and selects it if it is not in the list yet.
+ *
+ * @param superInterface the fully qualified type name of the interface.
+ * @return returns <code>true</code>if the interfaces has been added, <code>false</code>
+ * if the interface already is in the list.
+ * @since 1.0
+ */
+ public boolean addSuperModule(String superInterface) {
+ return fSuperModulesDialogField.addElement(new InterfaceWrapper(superInterface));
+ }
+
+ private String getModuleDialogTitle() {
if (fTypeKind == INTERFACE_TYPE)
return NewWizardMessages.NewTypeWizardPage_InterfacesDialog_interface_title;
return NewWizardMessages.NewTypeWizardPage_InterfacesDialog_class_title;
@@ -741,8 +798,8 @@
} else if (field == fSuperClassDialogField) {
fSuperClassStatus= superClassChanged();
fieldName= SUPER;
- } else if (field == fSuperInterfacesDialogField) {
- fSuperInterfacesStatus= superInterfacesChanged();
+ } else if (field == fSuperModulesDialogField) {
+ fSuperModulesStatus= superInterfacesChanged();
fieldName= INTERFACES;
} else {
fieldName= METHODS;
@@ -820,7 +877,7 @@
fContainerStatus,
fTypeNameStatus,
fSuperClassStatus,
- fSuperInterfacesStatus
+ fSuperModulesStatus
};
// the mode severe status will be displayed and the OK button enabled/disabled.
@@ -932,10 +989,10 @@
StatusInfo status= new StatusInfo();
ISourceFolderRoot root= getSourceFolderRoot();
- fSuperInterfacesDialogField.enableButton(0, root != null);
+ fSuperModulesDialogField.enableButton(0, root != null);
if (root != null) {
- List elements= fSuperInterfacesDialogField.getElements();
+ List elements= fSuperModulesDialogField.getElements();
int nElements= elements.size();
for (int i= 0; i < nElements; i++) {
// TODO Check to make sure each interface exists and is valid
@@ -961,15 +1018,23 @@
* different dialog.
* </p>
*
- * @since 3.2
+ * @since 0.9
*/
protected IType chooseSuperClass() {
ISourceFolderRoot root= getSourceFolderRoot();
if (root == null) {
return null;
- }
+ }
- RubyClassSelectionDialog dialog = new RubyClassSelectionDialog(getShell());
+ IRubyElement[] elements= new IRubyElement[] { root.getRubyProject() };
+ IRubySearchScope scope= SearchEngine.createRubySearchScope(elements);
+
+ TypeSelectionDialog2 dialog= new TypeSelectionDialog2(getShell(), false,
+ getWizard().getContainer(), scope, IRubySearchConstants.CLASS);
+ dialog.setTitle(NewWizardMessages.NewTypeWizardPage_SuperClassDialog_title);
+ dialog.setMessage(NewWizardMessages.NewTypeWizardPage_SuperClassDialog_message);
+ dialog.setFilter(getSuperClass());
+
if (dialog.open() == Window.OK) {
return (IType) dialog.getFirstResult();
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/RubyClassSelectionDialog.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/RubyClassSelectionDialog.java 2007-05-01 14:54:54 UTC (rev 2407)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/RubyClassSelectionDialog.java 2007-05-01 15:30:23 UTC (rev 2408)
@@ -6,9 +6,16 @@
import org.eclipse.swt.widgets.Shell;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.internal.ui.dialogs.TypeSelectionDialog2;
+/**
+ *
+ * @author Chris Williams
+ * @deprecated Please use {@link TypeSelectionDialog2}
+ */
public class RubyClassSelectionDialog extends RubyTypeSelectionDialog {
-
+// XXX Remve all references to this and remove it and its parent!
+
public RubyClassSelectionDialog(Shell parent) {
super(parent);
}
Deleted: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/RubyModuleSelectionDialog.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/RubyModuleSelectionDialog.java 2007-05-01 14:54:54 UTC (rev 2407)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/RubyModuleSelectionDialog.java 2007-05-01 15:30:23 UTC (rev 2408)
@@ -1,28 +0,0 @@
-package org.rubypeople.rdt.ui.wizards;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.swt.widgets.Shell;
-import org.rubypeople.rdt.core.IRubyElement;
-import org.rubypeople.rdt.core.IType;
-
-public class RubyModuleSelectionDialog extends RubyTypeSelectionDialog {
-
- public RubyModuleSelectionDialog(Shell parent) {
- super(parent);
- }
-
- protected Object[] getElements() {
- Object[] types = super.getElements();
- List classes = new ArrayList();
- for (int i = 0; i < types.length; i++) {
- IType type = (IType) types[i];
- if (type.isModule()) classes.add(types[i]);
- }
- IRubyElement[] elements = new IRubyElement[classes.size()];
- System.arraycopy(classes.toArray(), 0, elements, 0, elements.length);
- return elements;
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|