You can subscribe to this list here.
| 2005 |
Jan
|
Feb
|
Mar
(41) |
Apr
(9) |
May
|
Jun
|
Jul
(39) |
Aug
(38) |
Sep
(135) |
Oct
(220) |
Nov
(75) |
Dec
(74) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2006 |
Jan
(44) |
Feb
(160) |
Mar
(49) |
Apr
(69) |
May
(40) |
Jun
(52) |
Jul
(47) |
Aug
(51) |
Sep
(19) |
Oct
(22) |
Nov
(36) |
Dec
(76) |
| 2007 |
Jan
(154) |
Feb
(165) |
Mar
(186) |
Apr
(143) |
May
(175) |
Jun
(133) |
Jul
(203) |
Aug
(177) |
Sep
(136) |
Oct
|
Nov
|
Dec
|
|
From: <caw...@us...> - 2006-12-21 19:32:59
|
Revision: 1722
http://svn.sourceforge.net/rubyeclipse/?rev=1722&view=rev
Author: cawilliams
Date: 2006-12-21 11:32:55 -0800 (Thu, 21 Dec 2006)
Log Message:
-----------
ignore unpacked directories for docbook
Property Changed:
----------------
trunk/org.rubypeople.rdt.doc.user/docbook/
Property changes on: trunk/org.rubypeople.rdt.doc.user/docbook
___________________________________________________________________
Name: svn:ignore
+ docbook-xsl
dtd
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-21 19:32:18
|
Revision: 1721
http://svn.sourceforge.net/rubyeclipse/?rev=1721&view=rev
Author: cawilliams
Date: 2006-12-21 11:32:17 -0800 (Thu, 21 Dec 2006)
Log Message:
-----------
apply murphee's patch for the file so it works under JRuby
Modified Paths:
--------------
trunk/org.rubypeople.rdt.launching/ruby/eclipseDebug.rb
Modified: trunk/org.rubypeople.rdt.launching/ruby/eclipseDebug.rb
===================================================================
--- trunk/org.rubypeople.rdt.launching/ruby/eclipseDebug.rb 2006-12-21 19:31:34 UTC (rev 1720)
+++ trunk/org.rubypeople.rdt.launching/ruby/eclipseDebug.rb 2006-12-21 19:32:17 UTC (rev 1721)
@@ -548,7 +548,7 @@
stdout.print "Trace off.\n"
end
- when /^\s*b(?:reak)?\s+(?:(add|remove)\s+)?((?:.*?+:)?.+)$/
+ when /^\s*b(?:reak)?\s+(?:(add|remove)\s+)?((?:.*?:)?.+)$/
if $1 then
mode = $1
else
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-21 19:31:35
|
Revision: 1720
http://svn.sourceforge.net/rubyeclipse/?rev=1720&view=rev
Author: cawilliams
Date: 2006-12-21 11:31:34 -0800 (Thu, 21 Dec 2006)
Log Message:
-----------
try to fix this plugin so it doesn't mangle Eclipse's configuration when users install RDT
Modified Paths:
--------------
trunk/org.rubypeople.rdt.doc.user/build.properties
trunk/org.rubypeople.rdt.doc.user/build.xml
trunk/org.rubypeople.rdt.doc.user/plugin.xml
Added Paths:
-----------
trunk/org.rubypeople.rdt.doc.user/META-INF/
trunk/org.rubypeople.rdt.doc.user/META-INF/MANIFEST.MF
trunk/org.rubypeople.rdt.doc.user/index/
Added: trunk/org.rubypeople.rdt.doc.user/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.rubypeople.rdt.doc.user/META-INF/MANIFEST.MF (rev 0)
+++ trunk/org.rubypeople.rdt.doc.user/META-INF/MANIFEST.MF 2006-12-21 19:31:34 UTC (rev 1720)
@@ -0,0 +1,7 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Plugin.name
+Bundle-SymbolicName: org.rubypeople.rdt.doc.user;singleton:=true
+Bundle-Version: 0.0.0
+Bundle-Vendor: RubyPeople, Inc.
+Bundle-Localization: plugin
Modified: trunk/org.rubypeople.rdt.doc.user/build.properties
===================================================================
--- trunk/org.rubypeople.rdt.doc.user/build.properties 2006-12-21 18:57:05 UTC (rev 1719)
+++ trunk/org.rubypeople.rdt.doc.user/build.properties 2006-12-21 19:31:34 UTC (rev 1720)
@@ -1,7 +1,8 @@
bin.includes = plugin.xml,\
toc.xml,\
html/,\
- images/
+ images/,\
+ META-INF/
bin.excludes = build.xml
src.includes = docbook.xml,\
plugin.xml
Modified: trunk/org.rubypeople.rdt.doc.user/build.xml
===================================================================
--- trunk/org.rubypeople.rdt.doc.user/build.xml 2006-12-21 18:57:05 UTC (rev 1719)
+++ trunk/org.rubypeople.rdt.doc.user/build.xml 2006-12-21 19:31:34 UTC (rev 1720)
@@ -12,7 +12,7 @@
<property name="javacSource" value="1.3"/>
<property name="javacTarget" value="1.2"/>
<property name="compilerArg" value=""/>
- <property name="featureVersion" value="0.6.0"/>
+ <property name="featureVersion" value="0.9.0"/>
<!-- featureVersion might also be set from outside -->
<echo message="Using featureVersion=${featureVersion}"/>
Modified: trunk/org.rubypeople.rdt.doc.user/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.doc.user/plugin.xml 2006-12-21 18:57:05 UTC (rev 1719)
+++ trunk/org.rubypeople.rdt.doc.user/plugin.xml 2006-12-21 19:31:34 UTC (rev 1720)
@@ -1,8 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
-<plugin
- id="org.rubypeople.rdt.doc.user"
- name="%Plugin.name"
- version="0.0.0"
- provider-name="RubyPeople, Inc.">
+<plugin>
+
+<!-- ============================================================================= -->
+<!-- Define primary TOC -->
+<!-- ============================================================================= -->
+
+ <extension point="org.eclipse.help.toc">
+ <toc file="toc.xml" primary="true" />
+ </extension>
+
</plugin>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-21 18:57:09
|
Revision: 1719
http://svn.sourceforge.net/rubyeclipse/?rev=1719&view=rev
Author: cawilliams
Date: 2006-12-21 10:57:05 -0800 (Thu, 21 Dec 2006)
Log Message:
-----------
add ruby nature to this plugin (so we can edit the eclipseDebug.rb scripts)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.launching/.project
Modified: trunk/org.rubypeople.rdt.launching/.project
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-21 18:03:00
|
Revision: 1718
http://svn.sourceforge.net/rubyeclipse/?rev=1718&view=rev
Author: cawilliams
Date: 2006-12-21 10:02:58 -0800 (Thu, 21 Dec 2006)
Log Message:
-----------
Add a menu item/action to "Add a Ruby nature" to an existing project. This is useful for existing Java projects where we'd like to use some ruby scripts. (So a lot of JRuby projects and also our own plugins).
This fixes problems where opening a ruby script inside a Java project made RDT throw runtime exceptions (because it did a check for Ruby nature on the project).
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/plugin.xml
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/AddRubyNatureAction.java
Modified: trunk/org.rubypeople.rdt.ui/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.xml 2006-12-21 16:35:14 UTC (rev 1717)
+++ trunk/org.rubypeople.rdt.ui/plugin.xml 2006-12-21 18:02:58 UTC (rev 1718)
@@ -580,6 +580,14 @@
id="exportRdoc">
</action>
<action
+ definitionId="org.rubypeople.rdt.ui.add.rubynature"
+ label="Add Ruby Nature"
+ helpContextId="org.rubypeople.rdt.ui.add_ruby_nature_action"
+ class="org.rubypeople.rdt.internal.ui.actions.AddRubyNatureAction"
+ menubarPath="project/additions"
+ id="addRubyNature">
+ </action>
+ <action
definitionId="org.rubypeople.rdt.ui.edit.text.ruby.uncomment"
label="%UncommentAction.label"
menubarPath="org.rubypeople.rdt.ui.ruby.menu/editGroup"
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/AddRubyNatureAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/AddRubyNatureAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/AddRubyNatureAction.java 2006-12-21 18:02:58 UTC (rev 1718)
@@ -0,0 +1,89 @@
+package org.rubypeople.rdt.internal.ui.actions;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+
+public class AddRubyNatureAction implements IWorkbenchWindowActionDelegate {
+
+ private Shell fCurrentShell;
+
+ private ISelection fSelection;
+
+ public void dispose() {
+ }
+
+ public void init(IWorkbenchWindow window) {
+ fCurrentShell = window.getShell();
+ }
+
+ public void run(IAction action) {
+ IResource resource = findSelectedResource();
+ if (resource == null) {
+ MessageDialog
+ .openInformation(
+ fCurrentShell.getShell(),
+ "No project selected",
+ "Please select a project or resource for the addition of a ruby nature to the enclosing project.");
+ return;
+ }
+ try {
+ RubyCore.addRubyNature(resource.getProject(), null);
+ } catch (CoreException e) {
+ MessageDialog.openInformation(fCurrentShell.getShell(),
+ "Unable to add ruby nature", e.getMessage());
+ }
+ }
+
+ private IResource findSelectedResource() {
+ // the first shot is the selection
+ if (fSelection instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection) fSelection;
+ Object first = selection.getFirstElement();
+ if (first instanceof IResource) {
+ return ((IResource) first);
+ }
+ }
+
+ // the second is to check the active editor
+ // this behaviour is similar to the RubyApplicationShortcut, which also
+ // takes a selection in the navigator or the active editor to determine
+ // which
+ // ruby file to launch
+ IWorkbenchPage page = RubyPlugin.getActivePage();
+ if (page == null) {
+ return null;
+ }
+ IEditorPart editor = page.getActiveEditor();
+ if (editor == null) {
+ return null;
+ }
+ IEditorInput input = editor.getEditorInput();
+ if (input == null) {
+ return null;
+ }
+ IRubyElement rubyElement = (IRubyElement) input
+ .getAdapter(IRubyElement.class);
+ if (rubyElement == null) {
+ return null;
+ }
+ return rubyElement.getResource();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ fSelection = selection;
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-21 16:35:17
|
Revision: 1717
http://svn.sourceforge.net/rubyeclipse/?rev=1717&view=rev
Author: cawilliams
Date: 2006-12-21 08:35:14 -0800 (Thu, 21 Dec 2006)
Log Message:
-----------
extract an IInterpreter interface for RubyInterpreter (and try to use that everywhere possible).
Fix the annopying (and simple to fix) bug where users complained that their interpreter preferences weren't being persisted - setInstalledInterpreters wasn't calling saveRuntimeConfiguration. So if a user set up new interpreters (but didn't chnage the selected one) the changes weren't persisted.
Modified Paths:
--------------
trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_DebuggerLaunch.java
trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/launcher/RubyEnvironmentTab.java
trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/EditInterpreterDialog.java
trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/RubyInterpreterLabelProvider.java
trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/RubyInterpreterPreferencePage.java
trunk/org.rubypeople.rdt.debug.ui.tests/src/org/rubypeople/rdt/internal/debug/ui/launcher/TC_RubyApplicationShortcut.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunner.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunnerConfiguration.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyInterpreter.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyRuntime.java
trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyInterpreter.java
trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/infoviews/RIView.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rdocexport/RDocUtility.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RiDocHoverProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/PreferenceConstants.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IInterpreter.java
Modified: trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_DebuggerLaunch.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_DebuggerLaunch.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_DebuggerLaunch.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -19,6 +19,7 @@
import org.rubypeople.rdt.internal.launching.RubyInterpreter;
import org.rubypeople.rdt.internal.launching.RubyLaunchConfigurationAttribute;
import org.rubypeople.rdt.internal.launching.RubyRuntime;
+import org.rubypeople.rdt.launching.IInterpreter;
/*
*
@@ -35,7 +36,7 @@
// to be set accordingly
String rubyInterpreterPath = FTC_ClassicDebuggerCommunicationTest.RUBY_INTERPRETER ;
System.out.println("Using interpreter: " + rubyInterpreterPath) ;
- RubyInterpreter rubyInterpreter = new RubyInterpreter("RubyInterpreter", new Path(rubyInterpreterPath));
+ IInterpreter rubyInterpreter = new RubyInterpreter("RubyInterpreter", new Path(rubyInterpreterPath));
RubyRuntime.getDefault().addInstalledInterpreter(rubyInterpreter) ;
}
Modified: trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/launcher/RubyEnvironmentTab.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/launcher/RubyEnvironmentTab.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/launcher/RubyEnvironmentTab.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -35,6 +35,7 @@
import org.rubypeople.rdt.internal.launching.RubyLaunchConfigurationAttribute;
import org.rubypeople.rdt.internal.launching.RubyRuntime;
import org.rubypeople.rdt.internal.ui.RubyPluginImages;
+import org.rubypeople.rdt.launching.IInterpreter;
public class RubyEnvironmentTab extends AbstractLaunchConfigurationTab {
protected ListViewer loadPathListViewer;
@@ -115,7 +116,7 @@
interpreterAddButton.setText(RdtDebugUiMessages.getString("LaunchConfigurationTab.RubyEnvironment.interpreterAddButton.label"));
interpreterAddButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
- RubyInterpreter newInterpreter = new RubyInterpreter(null, null);
+ IInterpreter newInterpreter = new RubyInterpreter(null, null);
EditInterpreterDialog editor = new EditInterpreterDialog(getShell(), RdtDebugUiMessages.getString("LaunchConfigurationTab.RubyEnvironment.editInterpreterDialog.title"));
editor.create();
editor.setInterpreterToEdit(newInterpreter);
@@ -148,7 +149,7 @@
}
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
- RubyInterpreter defaultInterpreter = RubyRuntime.getDefault().getSelectedInterpreter();
+ IInterpreter defaultInterpreter = RubyRuntime.getDefault().getSelectedInterpreter();
if (defaultInterpreter != null) {
configuration.setAttribute(RubyLaunchConfigurationAttribute.SELECTED_INTERPRETER, defaultInterpreter.getName());
}
@@ -201,12 +202,12 @@
String[] interpreterNames = new String[installedInterpretersWorkingCopy.size()];
for (int interpreterIndex = 0; interpreterIndex < installedInterpretersWorkingCopy.size(); interpreterIndex++) {
- RubyInterpreter interpreter = (RubyInterpreter) installedInterpretersWorkingCopy.get(interpreterIndex);
+ IInterpreter interpreter = (IInterpreter) installedInterpretersWorkingCopy.get(interpreterIndex);
interpreterNames[interpreterIndex] = interpreter.getName();
}
interpreterCombo.setItems(interpreterNames);
- RubyInterpreter selectedInterpreter = RubyRuntime.getDefault().getSelectedInterpreter();
+ IInterpreter selectedInterpreter = RubyRuntime.getDefault().getSelectedInterpreter();
if (selectedInterpreter != null)
interpreterCombo.select(interpreterCombo.indexOf(selectedInterpreter.getName()));
}
Modified: trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/EditInterpreterDialog.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/EditInterpreterDialog.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/EditInterpreterDialog.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -26,9 +26,10 @@
import org.rubypeople.rdt.internal.debug.ui.RdtDebugUiPlugin;
import org.rubypeople.rdt.internal.launching.RubyInterpreter;
import org.rubypeople.rdt.internal.ui.dialogs.StatusDialog;
+import org.rubypeople.rdt.launching.IInterpreter;
public class EditInterpreterDialog extends StatusDialog {
- protected RubyInterpreter interpreterToEdit;
+ protected IInterpreter interpreterToEdit;
protected Text interpreterNameText, interpreterLocationText;
protected IStatus[] allStatus = new IStatus[2];
@@ -37,7 +38,7 @@
setTitle(aDialogTitle);
}
- public void setInterpreterToEdit(RubyInterpreter anInterpreter) {
+ public void setInterpreterToEdit(IInterpreter anInterpreter) {
interpreterToEdit = anInterpreter;
String interpreterName = interpreterToEdit.getName();
Modified: trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/RubyInterpreterLabelProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/RubyInterpreterLabelProvider.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/RubyInterpreterLabelProvider.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -4,7 +4,7 @@
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;
-import org.rubypeople.rdt.internal.launching.RubyInterpreter;
+import org.rubypeople.rdt.launching.IInterpreter;
public class RubyInterpreterLabelProvider implements ITableLabelProvider {
@@ -17,7 +17,7 @@
}
public String getColumnText(Object element, int columnIndex) {
- RubyInterpreter interpreter = (RubyInterpreter) element;
+ IInterpreter interpreter = (IInterpreter) element;
switch (columnIndex) {
case 0 :
return interpreter.getName();
Modified: trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/RubyInterpreterPreferencePage.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/RubyInterpreterPreferencePage.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/RubyInterpreterPreferencePage.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -28,6 +28,7 @@
import org.rubypeople.rdt.internal.debug.ui.RdtDebugUiMessages;
import org.rubypeople.rdt.internal.launching.RubyInterpreter;
import org.rubypeople.rdt.internal.launching.RubyRuntime;
+import org.rubypeople.rdt.launching.IInterpreter;
public class RubyInterpreterPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
protected CheckboxTableViewer tableViewer;
@@ -48,7 +49,7 @@
createButtonGroup(composite);
tableViewer.setInput(RubyRuntime.getDefault().getInstalledInterpreters());
- RubyInterpreter selectedInterpreter = RubyRuntime.getDefault().getSelectedInterpreter();
+ IInterpreter selectedInterpreter = RubyRuntime.getDefault().getSelectedInterpreter();
if (selectedInterpreter != null)
tableViewer.setChecked(selectedInterpreter, true);
@@ -146,7 +147,7 @@
}
protected void addInterpreter() {
- RubyInterpreter newInterpreter = new RubyInterpreter(null, null);
+ IInterpreter newInterpreter = new RubyInterpreter(null, null);
EditInterpreterDialog editor = new EditInterpreterDialog(getShell(), RdtDebugUiMessages.getString("RubyInterpreterPreferencePage.EditInterpreterDialog.addInterpreter.title")); //$NON-NLS-1$
editor.create();
editor.setInterpreterToEdit(newInterpreter);
@@ -186,15 +187,15 @@
EditInterpreterDialog editor = new EditInterpreterDialog(getShell(), RdtDebugUiMessages.getString("RubyInterpreterPreferencePage.EditInterpreterDialog.editInterpreter.title")); //$NON-NLS-1$
editor.create();
- RubyInterpreter anInterpreter = getSelectedInterpreter();
+ IInterpreter anInterpreter = getSelectedInterpreter();
editor.setInterpreterToEdit(anInterpreter);
if (EditInterpreterDialog.OK == editor.open())
tableViewer.update(anInterpreter, null);
}
- protected RubyInterpreter getSelectedInterpreter() {
+ protected IInterpreter getSelectedInterpreter() {
IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
- return (RubyInterpreter) selection.getFirstElement();
+ return (IInterpreter) selection.getFirstElement();
}
public boolean performOk() {
@@ -206,7 +207,7 @@
Object[] checkedElements = tableViewer.getCheckedElements();
if (checkedElements.length > 0)
- RubyRuntime.getDefault().setSelectedInterpreter((RubyInterpreter) checkedElements[0]);
+ RubyRuntime.getDefault().setSelectedInterpreter((IInterpreter) checkedElements[0]);
return super.performOk();
}
Modified: trunk/org.rubypeople.rdt.debug.ui.tests/src/org/rubypeople/rdt/internal/debug/ui/launcher/TC_RubyApplicationShortcut.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.ui.tests/src/org/rubypeople/rdt/internal/debug/ui/launcher/TC_RubyApplicationShortcut.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.debug.ui.tests/src/org/rubypeople/rdt/internal/debug/ui/launcher/TC_RubyApplicationShortcut.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -29,6 +29,7 @@
import org.rubypeople.rdt.internal.launching.RubyInterpreter;
import org.rubypeople.rdt.internal.launching.RubyLaunchConfigurationAttribute;
import org.rubypeople.rdt.internal.launching.RubyRuntime;
+import org.rubypeople.rdt.launching.IInterpreter;
import org.rubypeople.rdt.ui.IRubyConstants;
public class TC_RubyApplicationShortcut extends TestCase {
@@ -97,14 +98,14 @@
Assert.assertEquals("All configurations deleted.", 0, this.getLaunchConfigurations().length);
ShamApplicationLaunchConfigurationDelegate.resetLaunches();
- RubyInterpreter interpreterOne = new RubyInterpreter("InterpreterOne", new Path("C:/RubyInstallRootOne"));
- RubyRuntime.getDefault().setInstalledInterpreters(Arrays.asList(new Object[] { interpreterOne}));
+ IInterpreter interpreterOne = new RubyInterpreter("InterpreterOne", new Path("C:/RubyInstallRootOne"));
+ RubyRuntime.getDefault().setInstalledInterpreters(Arrays.asList(new IInterpreter[] { interpreterOne}));
}
public void testNoInterpreterInstalled() throws Exception {
- RubyRuntime.getDefault().setInstalledInterpreters(Arrays.asList(new Object[] { }));
+ RubyRuntime.getDefault().setInstalledInterpreters(Arrays.asList(new IInterpreter[] { }));
ISelection selection = new StructuredSelection(rubyFile);
shortcut.launch(selection, ILaunchManager.RUN_MODE);
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunner.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunner.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunner.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -10,6 +10,7 @@
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IProcess;
+import org.rubypeople.rdt.launching.IInterpreter;
public class InterpreterRunner {
@@ -19,7 +20,7 @@
List commandLine = renderCommandLine(configuration);
File workingDirectory = configuration.getAbsoluteWorkingDirectory();
- RubyInterpreter interpreter = convertInterpreter(configuration.getInterpreter()) ;
+ IInterpreter interpreter = convertInterpreter(configuration.getInterpreter());
Process nativeRubyProcess = interpreter.exec(commandLine, workingDirectory);
Map defaultAttributes = new HashMap();
defaultAttributes.put(IProcess.ATTR_PROCESS_TYPE, "ruby");
@@ -28,15 +29,15 @@
return process ;
}
- protected RubyInterpreter convertInterpreter(RubyInterpreter rubyInterpreter) {
- return rubyInterpreter ;
+ protected IInterpreter convertInterpreter(IInterpreter rubyInterpreter) {
+ return rubyInterpreter;
}
protected String renderLabel(InterpreterRunnerConfiguration configuration) {
StringBuffer buffer = new StringBuffer();
try {
- RubyInterpreter interpreter = configuration.getInterpreter();
+ IInterpreter interpreter = configuration.getInterpreter();
buffer.append("Ruby ");
buffer.append(interpreter.getCommand());
buffer.append(" : ");
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunnerConfiguration.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunnerConfiguration.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunnerConfiguration.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -11,6 +11,7 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.rubypeople.rdt.internal.core.RubyProject;
+import org.rubypeople.rdt.launching.IInterpreter;
public class InterpreterRunnerConfiguration {
protected ILaunchConfiguration configuration;
@@ -90,7 +91,7 @@
return "";
}
- public RubyInterpreter getInterpreter() {
+ public IInterpreter getInterpreter() {
String selectedInterpreter = null;
try {
selectedInterpreter = configuration.getAttribute(RubyLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyInterpreter.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyInterpreter.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyInterpreter.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -10,8 +10,9 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.rubypeople.rdt.launching.IInterpreter;
-public class RubyInterpreter {
+public class RubyInterpreter implements IInterpreter {
public static final String END_OF_OPTIONS_DELIMITER = "--";
protected IPath installLocation;
@@ -29,18 +30,30 @@
this.commandExecutor = commandExecutor;
}
+ /* (non-Javadoc)
+ * @see org.rubypeople.rdt.internal.launching.IInterpreter#getInstallLocation()
+ */
public IPath getInstallLocation() {
return installLocation;
}
+ /* (non-Javadoc)
+ * @see org.rubypeople.rdt.internal.launching.IInterpreter#setInstallLocation(org.eclipse.core.runtime.IPath)
+ */
public void setInstallLocation(IPath validInstallLocation) {
installLocation = validInstallLocation;
}
+ /* (non-Javadoc)
+ * @see org.rubypeople.rdt.internal.launching.IInterpreter#getName()
+ */
public String getName() {
return name;
}
+ /* (non-Javadoc)
+ * @see org.rubypeople.rdt.internal.launching.IInterpreter#setName(java.lang.String)
+ */
public void setName(String newName) {
name = newName;
}
@@ -54,7 +67,6 @@
}
public Process exec(List args, File workingDirectory) throws CoreException {
-
try {
RdtLaunchingPlugin.debug("Launching: " + args) ;
RdtLaunchingPlugin.debug("Working Dir: " + workingDirectory) ;
@@ -76,7 +88,7 @@
public boolean equals(Object other) {
if (other instanceof RubyInterpreter) {
- RubyInterpreter otherInterpreter = (RubyInterpreter) other;
+ IInterpreter otherInterpreter = (IInterpreter) other;
if (name.equals(otherInterpreter.getName()))
return installLocation.equals(otherInterpreter.getInstallLocation());
}
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyRuntime.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyRuntime.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyRuntime.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -19,6 +19,7 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
+import org.rubypeople.rdt.launching.IInterpreter;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
@@ -27,11 +28,16 @@
import org.xml.sax.XMLReader;
public class RubyRuntime {
+ private static final String TAG_INTERPRETER = "interpreter";
+ private static final String ATTR_PATH = "path";
+ private static final String ATTR_NAME = "name";
+ private static final String ATTR_SELECTED = "selected";
+
protected static RubyRuntime runtime;
- protected List installedInterpreters;
- protected RubyInterpreter selectedInterpreter;
- private List listeners = new ArrayList();
+ protected List<IInterpreter> installedInterpreters;
+ protected IInterpreter selectedInterpreter;
+ private List<Listener> listeners = new ArrayList<Listener>();
public static interface Listener {
void selectedInterpreterChanged();
@@ -56,17 +62,17 @@
listeners.remove(listener);
}
- public RubyInterpreter getSelectedInterpreter() {
+ public IInterpreter getSelectedInterpreter() {
if (selectedInterpreter == null) {
loadRuntimeConfiguration();
}
return selectedInterpreter;
}
- public RubyInterpreter getInterpreter(String name) {
+ public IInterpreter getInterpreter(String name) {
Iterator interpreters = getInstalledInterpreters().iterator();
while(interpreters.hasNext()) {
- RubyInterpreter each = (RubyInterpreter) interpreters.next();
+ IInterpreter each = (IInterpreter) interpreters.next();
if (each.getName().equals(name))
return each;
}
@@ -74,7 +80,7 @@
return getSelectedInterpreter();
}
- public void setSelectedInterpreter(RubyInterpreter anInterpreter) {
+ public void setSelectedInterpreter(IInterpreter anInterpreter) {
if (selectedInterpreter == anInterpreter) return;
selectedInterpreter = anInterpreter;
saveRuntimeConfiguration();
@@ -84,26 +90,27 @@
}
}
- public void addInstalledInterpreter(RubyInterpreter anInterpreter) {
+ public void addInstalledInterpreter(IInterpreter anInterpreter) {
getInstalledInterpreters().add(anInterpreter);
if (getInstalledInterpreters().size() == 1)
setSelectedInterpreter((RubyInterpreter) getInstalledInterpreters().get(0));
-
- saveRuntimeConfiguration();
+ else
+ saveRuntimeConfiguration();
}
- public List getInstalledInterpreters() {
+ public List<IInterpreter> getInstalledInterpreters() {
if (installedInterpreters == null)
loadRuntimeConfiguration();
return installedInterpreters;
}
- public void setInstalledInterpreters(List newInstalledInterpreters) {
+ public void setInstalledInterpreters(List<IInterpreter> newInstalledInterpreters) {
installedInterpreters = newInstalledInterpreters;
if (installedInterpreters.size() > 0)
- setSelectedInterpreter((RubyInterpreter)installedInterpreters.get(0));
+ setSelectedInterpreter((IInterpreter)installedInterpreters.get(0));
else
setSelectedInterpreter(null);
+ saveRuntimeConfiguration();
}
protected void saveRuntimeConfiguration() {
@@ -120,7 +127,7 @@
}
protected void loadRuntimeConfiguration() {
- installedInterpreters = new ArrayList();
+ installedInterpreters = new ArrayList<IInterpreter>();
try {
XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
reader.setContentHandler(getRuntimeConfigurationContentHandler());
@@ -143,7 +150,7 @@
} else {
path = new Path("/usr/local/bin/ruby");
}
- RubyInterpreter interpreter = new RubyInterpreter("Default Ruby Interpreter", path);
+ IInterpreter interpreter = new RubyInterpreter("Default Ruby Interpreter", path);
installedInterpreters.add(interpreter);
selectedInterpreter = interpreter;
}
@@ -161,15 +168,24 @@
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><runtimeconfig>");
Iterator interpretersIterator = installedInterpreters.iterator();
while (interpretersIterator.hasNext()) {
- writer.write("<interpreter name=\"");
+ writer.write("<");
+ writer.write(TAG_INTERPRETER);
+ writer.write(" ");
+ writer.write(ATTR_NAME);
+ writer.write("=\"");
- RubyInterpreter entry = (RubyInterpreter) interpretersIterator.next();
+ IInterpreter entry = (IInterpreter) interpretersIterator.next();
writer.write(entry.getName());
- writer.write("\" path=\"");
+ writer.write("\" ");
+ writer.write(ATTR_PATH);
+ writer.write("=\"");
writer.write(entry.getInstallLocation().toString());
writer.write("\"");
- if (entry.equals(selectedInterpreter))
- writer.write(" selected=\"true\"");
+ if (entry.equals(selectedInterpreter)) {
+ writer.write(" ");
+ writer.write(ATTR_SELECTED);
+ writer.write("=\"true\"");
+ }
writer.write("/>");
}
@@ -188,12 +204,12 @@
public void startPrefixMapping(String prefix, String uri) throws SAXException {}
public void endPrefixMapping(String prefix) throws SAXException {}
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
- if ("interpreter".equals(qName)) {
- String interpreterName = atts.getValue("name");
- IPath installLocation = new Path(atts.getValue("path"));
- RubyInterpreter interpreter = new RubyInterpreter(interpreterName, installLocation);
+ if (TAG_INTERPRETER.equals(qName)) {
+ String interpreterName = atts.getValue(ATTR_NAME);
+ IPath installLocation = new Path(atts.getValue(ATTR_PATH));
+ IInterpreter interpreter = new RubyInterpreter(interpreterName, installLocation);
installedInterpreters.add(interpreter);
- if (atts.getValue("selected") != null)
+ if (atts.getValue(ATTR_SELECTED) != null)
selectedInterpreter = interpreter;
}
}
Added: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IInterpreter.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IInterpreter.java (rev 0)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IInterpreter.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -0,0 +1,24 @@
+package org.rubypeople.rdt.launching;
+
+import java.io.File;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.rubypeople.rdt.internal.launching.IllegalCommandException;
+
+public interface IInterpreter {
+
+ public IPath getInstallLocation();
+
+ public void setInstallLocation(IPath validInstallLocation);
+
+ public String getName();
+
+ public void setName(String newName);
+
+ public String getCommand() throws IllegalCommandException;
+
+ public Process exec(List commandLine, File workingDirectory) throws CoreException;
+
+}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyInterpreter.java
===================================================================
--- trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyInterpreter.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyInterpreter.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -14,6 +14,7 @@
import org.rubypeople.rdt.internal.launching.CommandExecutor;
import org.rubypeople.rdt.internal.launching.IllegalCommandException;
import org.rubypeople.rdt.internal.launching.RubyInterpreter;
+import org.rubypeople.rdt.launching.IInterpreter;
public class TC_RubyInterpreter extends TestCase {
@@ -21,11 +22,11 @@
private static final File WORKING_DIR = new File("/testDir");
public void testEquals() {
- RubyInterpreter interpreterOne = new RubyInterpreter("InterpreterOne", new Path("/InterpreterOnePath"));
- RubyInterpreter similarInterpreterOne = new RubyInterpreter("InterpreterOne", new Path("/InterpreterOnePath"));
+ IInterpreter interpreterOne = new RubyInterpreter("InterpreterOne", new Path("/InterpreterOnePath"));
+ IInterpreter similarInterpreterOne = new RubyInterpreter("InterpreterOne", new Path("/InterpreterOnePath"));
assertTrue("Interpreters should be equal.", interpreterOne.equals(similarInterpreterOne));
- RubyInterpreter interpreterTwo = new RubyInterpreter("InterpreterTwo", new Path("/InterpreterTwoPath"));
+ IInterpreter interpreterTwo = new RubyInterpreter("InterpreterTwo", new Path("/InterpreterTwoPath"));
assertTrue("Interpreters should not be equal.", !interpreterOne.equals(interpreterTwo));
}
Modified: trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java
===================================================================
--- trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -32,6 +32,7 @@
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.rubypeople.rdt.internal.launching.RubyInterpreter;
import org.rubypeople.rdt.internal.launching.RubyRuntime;
+import org.rubypeople.rdt.launching.IInterpreter;
public class TC_RubyRuntime extends TestCase {
protected StringWriter runtimeConfigurationWriter = new StringWriter();
@@ -42,8 +43,8 @@
public void testGetInstalledInterpreters() {
ShamRubyRuntime runtime = new ShamRubyRuntime();
- RubyInterpreter interpreterOne = new RubyInterpreter("InterpreterOne", new Path("C:/RubyInstallRootOne"));
- RubyInterpreter interpreterTwo = new RubyInterpreter("InterpreterTwo", new Path("C:/RubyInstallRootTwo"));
+ IInterpreter interpreterOne = new RubyInterpreter("InterpreterOne", new Path("C:/RubyInstallRootOne"));
+ IInterpreter interpreterTwo = new RubyInterpreter("InterpreterTwo", new Path("C:/RubyInstallRootTwo"));
assertTrue("Runtime should contain all interpreters.", runtime.getInstalledInterpreters().containsAll(Arrays.asList(new Object[] { interpreterOne, interpreterTwo })));
assertTrue("interpreterTwo should be selected interpreter.", runtime.getSelectedInterpreter().equals(interpreterTwo));
@@ -52,18 +53,15 @@
ShamRubyRuntime runtime = new ShamRubyRuntime();
- RubyInterpreter interpreterOne = new RubyInterpreter("InterpreterOne", new Path("C:/RubyInstallRootOne"));
- runtime.setInstalledInterpreters(Arrays.asList(new Object[] { interpreterOne }));
- runtime.saveRuntimeConfiguration() ;
+ IInterpreter interpreterOne = new RubyInterpreter("InterpreterOne", new Path("C:/RubyInstallRootOne"));
+ runtime.setInstalledInterpreters(Arrays.asList(new IInterpreter[] { interpreterOne }));
assertEquals("XML should indicate only one interpreter with it being the selected.", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><runtimeconfig><interpreter name=\"InterpreterOne\" path=\"C:/RubyInstallRootOne\" selected=\"true\"/></runtimeconfig>", runtimeConfigurationWriter.toString());
RubyInterpreter interpreterTwo = new RubyInterpreter("InterpreterTwo", new Path("C:/RubyInstallRootTwo"));
- runtime.setInstalledInterpreters(Arrays.asList(new Object[] { interpreterOne, interpreterTwo }));
- runtime.saveRuntimeConfiguration() ;
+ runtime.setInstalledInterpreters(Arrays.asList(new IInterpreter[] { interpreterOne, interpreterTwo }));
assertEquals("XML should indicate both interpreters with the first one being selected.", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><runtimeconfig><interpreter name=\"InterpreterOne\" path=\"C:/RubyInstallRootOne\" selected=\"true\"/><interpreter name=\"InterpreterTwo\" path=\"C:/RubyInstallRootTwo\"/></runtimeconfig>", runtimeConfigurationWriter.toString());
runtime.setSelectedInterpreter(interpreterTwo);
- runtime.saveRuntimeConfiguration() ;
assertEquals("XML should indicate selected interpreter change.", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><runtimeconfig><interpreter name=\"InterpreterOne\" path=\"C:/RubyInstallRootOne\"/><interpreter name=\"InterpreterTwo\" path=\"C:/RubyInstallRootTwo\" selected=\"true\"/></runtimeconfig>", runtimeConfigurationWriter.toString());
}
protected class ShamRubyRuntime extends RubyRuntime {
@@ -77,7 +75,7 @@
protected Writer getRuntimeConfigurationWriter() {
return runtimeConfigurationWriter;
}
- public void setInstalledInterpreters(List newInstalledInterpreters) {
+ public void setInstalledInterpreters(List<IInterpreter> newInstalledInterpreters) {
super.setInstalledInterpreters(newInstalledInterpreters);
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/infoviews/RIView.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/infoviews/RIView.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/infoviews/RIView.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -40,12 +40,12 @@
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.PageBook;
import org.eclipse.ui.part.ViewPart;
-import org.rubypeople.rdt.internal.launching.RubyInterpreter;
import org.rubypeople.rdt.internal.launching.RubyRuntime;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.RubyPluginImages;
import org.rubypeople.rdt.internal.ui.rdocexport.RDocUtility;
import org.rubypeople.rdt.internal.ui.rdocexport.RdocListener;
+import org.rubypeople.rdt.launching.IInterpreter;
import org.rubypeople.rdt.ui.PreferenceConstants;
public class RIView extends ViewPart implements RdocListener {
@@ -171,7 +171,7 @@
}
private void updatePage() {
- RubyInterpreter interpreter = RubyRuntime.getDefault().getSelectedInterpreter();
+ IInterpreter interpreter = RubyRuntime.getDefault().getSelectedInterpreter();
if (interpreter != null) {
initSearchList();
if( riFound ){
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rdocexport/RDocUtility.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rdocexport/RDocUtility.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rdocexport/RDocUtility.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -17,11 +17,11 @@
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.rubypeople.rdt.internal.launching.RdtLaunchingMessages;
-import org.rubypeople.rdt.internal.launching.RubyInterpreter;
import org.rubypeople.rdt.internal.launching.RubyRuntime;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.RubyUIMessages;
import org.rubypeople.rdt.internal.ui.dialogs.StatusInfo;
+import org.rubypeople.rdt.launching.IInterpreter;
import org.rubypeople.rdt.ui.PreferenceConstants;
/**
@@ -86,7 +86,7 @@
log("Generating RDoc for " + resource.getName());
RdtLaunchingMessages.getString("RdtLaunchingPlugin.noInterpreterSelected");
- RubyInterpreter interpreter = RubyRuntime.getDefault().getSelectedInterpreter();
+ IInterpreter interpreter = RubyRuntime.getDefault().getSelectedInterpreter();
if (interpreter == null) {
MessageDialog.openInformation(RubyPlugin.getActiveWorkbenchShell(), RdtLaunchingMessages.getString("RdtLaunchingPlugin.noInterpreterSelectedTitle"), RdtLaunchingMessages.getString("RdtLaunchingPlugin.noInterpreterSelected"));
return ;
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RiDocHoverProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RiDocHoverProvider.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RiDocHoverProvider.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -12,9 +12,9 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
-import org.rubypeople.rdt.internal.launching.RubyInterpreter;
import org.rubypeople.rdt.internal.launching.RubyRuntime;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.launching.IInterpreter;
import org.rubypeople.rdt.ui.PreferenceConstants;
import org.rubypeople.rdt.ui.extensions.ITextHoverProvider;
@@ -33,7 +33,7 @@
try {
String symbol = textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength());
args.add(symbol);
- RubyInterpreter selectedInterpreter = RubyRuntime.getDefault().getSelectedInterpreter();
+ IInterpreter selectedInterpreter = RubyRuntime.getDefault().getSelectedInterpreter();
if (selectedInterpreter == null) return null;
Process p = selectedInterpreter.exec(args, null);
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/PreferenceConstants.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/PreferenceConstants.java 2006-12-18 13:30:32 UTC (rev 1716)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/PreferenceConstants.java 2006-12-21 16:35:14 UTC (rev 1717)
@@ -4,10 +4,10 @@
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.swt.graphics.RGB;
-import org.rubypeople.rdt.internal.launching.RubyInterpreter;
import org.rubypeople.rdt.internal.launching.RubyRuntime;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.preferences.formatter.ProfileManager;
+import org.rubypeople.rdt.launching.IInterpreter;
public class PreferenceConstants {
@@ -652,7 +652,7 @@
}
private static String getDefaultPath(String programName) {
- RubyInterpreter interpreter = RubyRuntime.getDefault().getSelectedInterpreter();
+ IInterpreter interpreter = RubyRuntime.getDefault().getSelectedInterpreter();
if (interpreter == null) { return programName; }
IPath path = interpreter.getInstallLocation();
path = path.uptoSegment(path.segmentCount() - 1).append(programName);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-18 13:30:38
|
Revision: 1716
http://svn.sourceforge.net/rubyeclipse/?rev=1716&view=rev
Author: cawilliams
Date: 2006-12-18 05:30:32 -0800 (Mon, 18 Dec 2006)
Log Message:
-----------
apply Kyle's patch for "Textmate like template expansion"
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubySourceViewer.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCompletionProcessor.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ILinkedModeEditStrategy.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAutoEditStrategy.java
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ILinkedModeEditStrategy.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ILinkedModeEditStrategy.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ILinkedModeEditStrategy.java 2006-12-18 13:30:32 UTC (rev 1716)
@@ -0,0 +1,19 @@
+package org.rubypeople.rdt.internal.ui.rubyeditor;
+
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.link.LinkedPosition;
+
+/**
+ * Interface for linked mode edit strategies.
+ */
+public interface ILinkedModeEditStrategy extends IAutoEditStrategy {
+
+ /**
+ * Returns the linked positions to use for the most recently processed
+ * document command.
+ *
+ * @return An array of linked positions to use in linked mode, or
+ * <code>null</code> if no linked mode should be set up
+ */
+ public LinkedPosition[] getLinkedPositions();
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAutoEditStrategy.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAutoEditStrategy.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAutoEditStrategy.java 2006-12-18 13:30:32 UTC (rev 1716)
@@ -0,0 +1,176 @@
+package org.rubypeople.rdt.internal.ui.rubyeditor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.link.LinkedPosition;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.templates.DocumentTemplateContext;
+import org.eclipse.jface.text.templates.Template;
+import org.eclipse.jface.text.templates.TemplateBuffer;
+import org.eclipse.jface.text.templates.TemplateContext;
+import org.eclipse.jface.text.templates.TemplateContextType;
+import org.eclipse.jface.text.templates.TemplateException;
+import org.eclipse.jface.text.templates.TemplateVariable;
+import org.rubypeople.rdt.internal.ui.text.ruby.RubyCompletionProcessor;
+
+public class RubyAutoEditStrategy implements ILinkedModeEditStrategy {
+
+ private RubyCompletionProcessor fRubyCp;
+
+ private ISourceViewer fViewer;
+
+ /** The linked position list */
+ protected final List fPositionList = new ArrayList();
+
+ public RubyAutoEditStrategy(String partition, ISourceViewer viewer,
+ RubyCompletionProcessor rhtmlCp) {
+ fViewer = viewer;
+ fRubyCp = rhtmlCp;
+ }
+
+ public void customizeDocumentCommand(IDocument document,
+ DocumentCommand command) {
+ fPositionList.clear();
+ if (command.text.length() == 1) {
+ if (command.text.charAt(0) == '\t') {
+ try {
+ int length = 0;
+ while ((command.offset - length > 0)
+ && Pattern.matches("\\w", document.get(
+ command.offset - length - 1, 1))) {
+ length++;
+ }
+ String prefix = document.get(command.offset - length,
+ length);
+ Region region = new Region(
+ command.offset - prefix.length(), prefix.length());
+ if (prefix.length() > 0) {
+ Template[] templates = fRubyCp
+ .getTemplates("ruby");
+ for (int i = 0; i < templates.length; i++) {
+ Template template = templates[i];
+ if (template.getName().equals(prefix)) {
+ final int offset = command.offset
+ - prefix.length();
+ TemplateContextType contextType = fRubyCp
+ .getContextType(fViewer, region);
+ TemplateContext context = new DocumentTemplateContext(
+ contextType, document, region
+ .getOffset(), region
+ .getLength());
+
+ context.setReadOnly(false);
+ TemplateBuffer templateBuffer;
+ try {
+ templateBuffer = context.evaluate(template);
+ } catch (TemplateException e1) {
+ return;
+ }
+
+ int start = getReplaceOffset(context, region);
+ int end = Math.max(getReplaceEndOffset(context,
+ region), offset);
+
+ // insert template string
+ String templateString = templateBuffer
+ .getString();
+
+ command.text = templateString;
+ command.offset = start;
+ command.length = end - start;
+
+ fPositionList.add(new LinkedPosition(document,
+ offset + templateString.length(), 0));
+
+ // translate positions
+ TemplateVariable[] variables = templateBuffer
+ .getVariables();
+ for (int z = 0; z != variables.length; z++) {
+ TemplateVariable variable = variables[z];
+
+ if (variable.isUnambiguous())
+ continue;
+
+ int[] offsets = variable.getOffsets();
+ int variablelength = variable.getLength();
+
+ for (int j = 0; j != offsets.length; j++)
+ fPositionList.add(new LinkedPosition(
+ document, offsets[j] + start,
+ variablelength));
+ }
+
+ break;
+ }
+
+ }
+ }
+ } catch (BadLocationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public LinkedPosition[] getLinkedPositions() {
+ final int size = fPositionList.size();
+ if (size > 0) {
+
+ final LinkedPosition[] positions = new LinkedPosition[size];
+ fPositionList.toArray(positions);
+
+ return positions;
+ }
+ return null;
+ }
+
+ /**
+ * Returns the offset of the range in the document that will be replaced by
+ * applying this template.
+ *
+ * @return the offset of the range in the document that will be replaced by
+ * applying this template
+ * @since 3.1
+ */
+ protected final int getReplaceOffset(TemplateContext context, Region region) {
+ int start;
+ if (context instanceof DocumentTemplateContext) {
+ DocumentTemplateContext docContext = (DocumentTemplateContext) context;
+ start = docContext.getStart();
+ } else {
+ start = region.getOffset();
+ }
+ return start;
+ }
+
+ /**
+ * Returns the end offset of the range in the document that will be replaced
+ * by applying this template.
+ *
+ * @return the end offset of the range in the document that will be replaced
+ * by applying this template
+ * @since 3.1
+ */
+ protected final int getReplaceEndOffset(TemplateContext context,
+ Region region) {
+ int end;
+ if (context instanceof DocumentTemplateContext) {
+ DocumentTemplateContext docContext = (DocumentTemplateContext) context;
+ end = docContext.getEnd();
+ } else {
+ end = region.getOffset() + region.getLength();
+ }
+ return end;
+ }
+
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubySourceViewer.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubySourceViewer.java 2006-12-15 22:02:36 UTC (rev 1715)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubySourceViewer.java 2006-12-18 13:30:32 UTC (rev 1716)
@@ -6,14 +6,35 @@
*/
package org.rubypeople.rdt.internal.ui.rubyeditor;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IPositionUpdater;
+import org.eclipse.jface.text.link.ILinkedModeListener;
+import org.eclipse.jface.text.link.InclusivePositionUpdater;
+import org.eclipse.jface.text.link.LinkedModeModel;
+import org.eclipse.jface.text.link.LinkedModeUI;
+import org.eclipse.jface.text.link.LinkedPosition;
+import org.eclipse.jface.text.link.LinkedPositionGroup;
import org.eclipse.jface.text.source.IOverviewRuler;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
@@ -26,6 +47,9 @@
private boolean fIgnoreTextConverters = false;
+ /** The linked position list for code auto edit */
+ protected final LinkedList fPositionList = new LinkedList();
+
/**
* This viewer's foreground color.
* @since 0.8.0
@@ -60,11 +84,19 @@
* @since 0.8.0
*/
private boolean fIsConfigured;
+
+ /** The auto edit category */
+ protected static final String CATEGORY_AUTO_EDIT = "org.rubypeople.rdt.ui.RubyEditor"
+ + ".auto.edit." + System.currentTimeMillis(); //$NON-NLS-1$
+ /** The position updater for auto edit */
+ protected final IPositionUpdater fAutoEditUpdater;
+
public RubySourceViewer(Composite composite, IVerticalRuler verticalRuler,
IOverviewRuler overviewRuler, boolean overviewRulerVisible, int styles, IPreferenceStore store) {
super(composite, verticalRuler, overviewRuler, overviewRulerVisible, styles);
setPreferenceStore(store);
+ fAutoEditUpdater = new InclusivePositionUpdater(CATEGORY_AUTO_EDIT);
}
/**
@@ -239,4 +271,155 @@
if (getTextWidget() == null || !redraws()) { return; }
super.doOperation(operation);
}
+
+ /*
+ * @see org.eclipse.jface.text.TextViewer#handleVisibleDocumentChanged(org.eclipse.jface.text.DocumentEvent)
+ */
+ protected final void handleVisibleDocumentChanged(final DocumentEvent event) {
+ super.handleVisibleDocumentChanged(event);
+
+ if (!fPositionList.isEmpty()) {
+
+ try {
+
+ final IDocument document = event.getDocument();
+ final LinkedModeModel model = new LinkedModeModel();
+
+ final String category = CATEGORY_AUTO_EDIT;
+ if (!document.containsPositionCategory(category)) {
+
+ document.addPositionCategory(category);
+ document.addPositionUpdater(fAutoEditUpdater);
+
+ model.addLinkingListener(new ILinkedModeListener() {
+
+ public final void left(final LinkedModeModel dummy,
+ final int flags) {
+
+ if (document.containsPositionCategory(category)) {
+
+ try {
+ document.removePositionCategory(category);
+ } catch (BadPositionCategoryException exception) {
+ // Do nothing
+ }
+ document
+ .removePositionUpdater(fAutoEditUpdater);
+ }
+ }
+
+ public final void resume(final LinkedModeModel dummy,
+ final int flags) {
+ }
+
+ public final void suspend(final LinkedModeModel dummy) {
+ }
+ });
+ }
+
+ LinkedPosition position = null;
+ LinkedPositionGroup group = null;
+
+ for (final Iterator iterator = fPositionList.iterator(); iterator
+ .hasNext();) {
+
+ position = (LinkedPosition) iterator.next();
+
+ group = new LinkedPositionGroup();
+ group.addPosition(position);
+
+ model.addGroup(group);
+ }
+ model.forceInstall();
+
+ final LinkedModeUI handler = new LinkedModeUI(model, this);
+
+ final LinkedPosition exit = (LinkedPosition) fPositionList
+ .getFirst();
+ final LinkedPosition entry = (LinkedPosition) fPositionList
+ .getLast();
+
+ addSelectionChangedListener(new ISelectionChangedListener() {
+
+ private boolean fHandled = false;
+
+ public final void selectionChanged(
+ final SelectionChangedEvent dummy) {
+
+ if (!fHandled) {
+
+ fHandled = true;
+
+ removeSelectionChangedListener(this);
+ }
+ }
+ });
+
+ addPostSelectionChangedListener(new ISelectionChangedListener() {
+
+ private boolean fHandled = false;
+
+ public final void selectionChanged(
+ final SelectionChangedEvent dummy) {
+
+ if (!fHandled) {
+ setSelectedRange(entry.offset, entry.length);
+
+ invalidateTextPresentation(entry.offset, 0);
+
+ fHandled = true;
+
+ removePostSelectionChangedListener(this);
+ }
+ }
+ });
+
+ handler
+ .setExitPosition(this, exit.offset, 0,
+ LinkedPositionGroup.NO_STOP);
+
+ handler.enter();
+
+ } catch (BadLocationException exception) {
+ // Do nothing
+ } finally {
+ fPositionList.clear();
+ }
+ }
+ }
+
+ protected void customizeDocumentCommand(DocumentCommand command) {
+ if (isIgnoringAutoEditStrategies())
+ return;
+
+ List strategies = (List) selectContentTypePlugin(command.offset,
+ fAutoIndentStrategies);
+ if (strategies == null)
+ return;
+
+ IDocument document = getDocument();
+ if (!strategies.isEmpty()) {
+
+ fPositionList.clear();
+ String originalCommandText = command.text;
+
+ LinkedPosition[] result = null;
+ IAutoEditStrategy strategy = null;
+
+ for (final Iterator iterator = new ArrayList(strategies).iterator(); iterator
+ .hasNext();) {
+
+ strategy = (IAutoEditStrategy) iterator.next();
+ strategy.customizeDocumentCommand(document, command);
+
+ if ((strategy instanceof ILinkedModeEditStrategy) && originalCommandText.equals("\t")) {
+ result = ((ILinkedModeEditStrategy) strategy)
+ .getLinkedPositions();
+ if (result != null && result.length > 0)
+ fPositionList.addAll(Arrays.asList(result));
+ }
+ }
+ }
+ }
+
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCompletionProcessor.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCompletionProcessor.java 2006-12-15 22:02:36 UTC (rev 1715)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCompletionProcessor.java 2006-12-18 13:30:32 UTC (rev 1716)
@@ -168,7 +168,7 @@
* @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getContextType(org.eclipse.jface.text.ITextViewer,
* org.eclipse.jface.text.IRegion)
*/
- protected TemplateContextType getContextType(ITextViewer textViewer,
+ public TemplateContextType getContextType(ITextViewer textViewer,
IRegion region) {
return RubyTemplateAccess.getDefault().getContextTypeRegistry()
.getContextType(RubyContextType.NAME);
@@ -356,7 +356,7 @@
*
* @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getTemplates(java.lang.String)
*/
- protected Template[] getTemplates(String contextTypeId) {
+ public Template[] getTemplates(String contextTypeId) {
return RubyTemplateAccess.getDefault().getTemplateStore()
.getTemplates();
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2006-12-15 22:02:36 UTC (rev 1715)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2006-12-18 13:30:32 UTC (rev 1716)
@@ -42,6 +42,7 @@
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.rubyeditor.IRubyScriptDocumentProvider;
import org.rubypeople.rdt.internal.ui.rubyeditor.RubyAbstractEditor;
+import org.rubypeople.rdt.internal.ui.rubyeditor.RubyAutoEditStrategy;
import org.rubypeople.rdt.internal.ui.text.ContentAssistPreference;
import org.rubypeople.rdt.internal.ui.text.HTMLTextPresenter;
import org.rubypeople.rdt.internal.ui.text.IRubyColorConstants;
@@ -63,341 +64,384 @@
import org.rubypeople.rdt.internal.ui.text.ruby.hover.RubyCodeTextHover;
import org.rubypeople.rdt.ui.text.hyperlinks.RubyHyperLinkDetector;
-public class RubySourceViewerConfiguration extends TextSourceViewerConfiguration {
+public class RubySourceViewerConfiguration extends
+ TextSourceViewerConfiguration {
- protected RubyTextTools textTools;
- protected ITextEditor fTextEditor;
- private RubyCodeTextHover fRubyTextHover;
+ protected RubyTextTools textTools;
+ protected ITextEditor fTextEditor;
+ private RubyCodeTextHover fRubyTextHover;
- /**
- * The document partitioning.
- *
- * @since 0.8.0
- */
- private String fDocumentPartitioning;
+ /**
+ * The document partitioning.
+ *
+ * @since 0.8.0
+ */
+ private String fDocumentPartitioning;
- /**
- * The color manager.
- *
- * @since 0.8.0
- */
- private IColorManager fColorManager;
+ /**
+ * The color manager.
+ *
+ * @since 0.8.0
+ */
+ private IColorManager fColorManager;
- protected AbstractRubyScanner fCodeScanner;
- protected AbstractRubyScanner fMultilineCommentScanner, fSinglelineCommentScanner,
- fStringScanner;
- private SingleTokenRubyCodeScanner fRegexpScanner;
- private SingleTokenRubyCodeScanner fCommandScanner;
- private RubyDoubleClickSelector fRubyDoubleClickSelector;
+ protected AbstractRubyScanner fCodeScanner;
- /**
- * Creates a new Ruby source viewer configuration for viewers in the given
- * editor using the given preference store, the color manager and the
- * specified document partitioning.
- * <p>
- * Creates a Ruby source viewer configuration in the new setup without text
- * tools. Clients are allowed to call
- * {@link RubySourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}
- * and disallowed to call
- * {@link RubySourceViewerConfiguration#getPreferenceStore()} on the
- * resulting Ruby source viewer configuration.
- * </p>
- *
- * @param colorManager
- * the color manager
- * @param preferenceStore
- * the preference store, can be read-only
- * @param editor
- * the editor in which the configured viewer(s) will reside, or
- * <code>null</code> if none
- * @param partitioning
- * the document partitioning for this configuration, or
- * <code>null</code> for the default partitioning
- * @since 3.0
- */
- public RubySourceViewerConfiguration(IColorManager colorManager,
- IPreferenceStore preferenceStore, ITextEditor editor, String partitioning) {
- super(preferenceStore);
- fColorManager = colorManager;
- fTextEditor = editor;
- fDocumentPartitioning = partitioning;
- initializeScanners();
- }
-
- /*
- * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
- */
- public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
- final MultiPassContentFormatter formatter= new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IDocument.DEFAULT_CONTENT_TYPE);
+ protected AbstractRubyScanner fMultilineCommentScanner, fSinglelineCommentScanner, fStringScanner;
+ private SingleTokenRubyCodeScanner fRegexpScanner;
+ private SingleTokenRubyCodeScanner fCommandScanner;
+ private RubyDoubleClickSelector fRubyDoubleClickSelector;
+ private RubyCompletionProcessor fRubyCp;
+
+ /**
+ * Creates a new Ruby source viewer configuration for viewers in the given
+ * editor using the given preference store, the color manager and the
+ * specified document partitioning.
+ * <p>
+ * Creates a Ruby source viewer configuration in the new setup without text
+ * tools. Clients are allowed to call
+ * {@link RubySourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}
+ * and disallowed to call
+ * {@link RubySourceViewerConfiguration#getPreferenceStore()} on the
+ * resulting Ruby source viewer configuration.
+ * </p>
+ *
+ * @param colorManager
+ * the color manager
+ * @param preferenceStore
+ * the preference store, can be read-only
+ * @param editor
+ * the editor in which the configured viewer(s) will reside, or
+ * <code>null</code> if none
+ * @param partitioning
+ * the document partitioning for this configuration, or
+ * <code>null</code> for the default partitioning
+ * @since 3.0
+ */
+ public RubySourceViewerConfiguration(IColorManager colorManager,
+ IPreferenceStore preferenceStore, ITextEditor editor,
+ String partitioning) {
+ super(preferenceStore);
+ fColorManager = colorManager;
+ fTextEditor = editor;
+ fDocumentPartitioning = partitioning;
+ initializeScanners();
+ }
- formatter.setMasterStrategy(new RubyFormattingStrategy());
- formatter.setSlaveStrategy(new CommentFormattingStrategy(), IRubyPartitions.RUBY_DOC);
- formatter.setSlaveStrategy(new CommentFormattingStrategy(), IRubyPartitions.RUBY_SINGLE_LINE_COMMENT);
- formatter.setSlaveStrategy(new CommentFormattingStrategy(), IRubyPartitions.RUBY_MULTI_LINE_COMMENT);
+ /*
+ * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
+ */
+ public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
+ final MultiPassContentFormatter formatter = new MultiPassContentFormatter(
+ getConfiguredDocumentPartitioning(sourceViewer),
+ IDocument.DEFAULT_CONTENT_TYPE);
- return formatter;
- }
-
- @Override
- public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
- if (!fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
+ formatter.setMasterStrategy(new RubyFormattingStrategy());
+ formatter.setSlaveStrategy(new CommentFormattingStrategy(),
+ IRubyPartitions.RUBY_DOC);
+ formatter.setSlaveStrategy(new CommentFormattingStrategy(),
+ IRubyPartitions.RUBY_SINGLE_LINE_COMMENT);
+ formatter.setSlaveStrategy(new CommentFormattingStrategy(),
+ IRubyPartitions.RUBY_MULTI_LINE_COMMENT);
+
+ return formatter;
+ }
+
+ @Override
+ public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
+ if (!fPreferenceStore
+ .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
return null;
- IHyperlinkDetector[] inheritedDetectors= super.getHyperlinkDetectors(sourceViewer);
+ IHyperlinkDetector[] inheritedDetectors = super
+ .getHyperlinkDetectors(sourceViewer);
if (fTextEditor == null)
return inheritedDetectors;
- int inheritedDetectorsLength= inheritedDetectors != null ? inheritedDetectors.length : 0;
- IHyperlinkDetector[] detectors= new IHyperlinkDetector[inheritedDetectorsLength + 1];
- detectors[0]= new RubyHyperLinkDetector(fTextEditor.getEditorInput());
- for (int i= 0; i < inheritedDetectorsLength; i++)
- detectors[i+1]= inheritedDetectors[i];
+ int inheritedDetectorsLength = inheritedDetectors != null ? inheritedDetectors.length
+ : 0;
+ IHyperlinkDetector[] detectors = new IHyperlinkDetector[inheritedDetectorsLength + 1];
+ detectors[0] = new RubyHyperLinkDetector(fTextEditor.getEditorInput());
+ for (int i = 0; i < inheritedDetectorsLength; i++)
+ detectors[i + 1] = inheritedDetectors[i];
return detectors;
- }
+ }
- /**
- * Determines whether the preference change encoded by the given event
- * changes the behavior of one of its contained components.
- *
- * @param event
- * the event to be investigated
- * @return <code>true</code> if event causes a behavioral change
- * @since 0.8.0
- */
- public boolean affectsTextPresentation(PropertyChangeEvent event) {
- return fCodeScanner.affectsBehavior(event)
- || fMultilineCommentScanner.affectsBehavior(event)
- || fSinglelineCommentScanner.affectsBehavior(event)
- || fStringScanner.affectsBehavior(event) || fRegexpScanner.affectsBehavior(event)
- || fCommandScanner.affectsBehavior(event);
- }
-
- /**
- * Adapts the behavior of the contained components to the change
- * encoded in the given event.
- * <p>
- * Clients are not allowed to call this method if the old setup with
- * text tools is in use.
- * </p>
- *
- * @param event the event to which to adapt
- * @see RubySourceViewerConfiguration#RubySourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)
- * @since 0.8.0
- */
- public void handlePropertyChangeEvent(PropertyChangeEvent event) {
- Assert.isTrue(isNewSetup());
- if (fCodeScanner.affectsBehavior(event))
- fCodeScanner.adaptToPreferenceChange(event);
- if (fMultilineCommentScanner.affectsBehavior(event))
- fMultilineCommentScanner.adaptToPreferenceChange(event);
- if (fSinglelineCommentScanner.affectsBehavior(event))
- fSinglelineCommentScanner.adaptToPreferenceChange(event);
- if (fStringScanner.affectsBehavior(event))
- fStringScanner.adaptToPreferenceChange(event);
- if (fRegexpScanner.affectsBehavior(event))
- fRegexpScanner.adaptToPreferenceChange(event);
- if (fCommandScanner.affectsBehavior(event))
- fCommandScanner.adaptToPreferenceChange(event);
- }
+ /**
+ * Determines whether the preference change encoded by the given event
+ * changes the behavior of one of its contained components.
+ *
+ * @param event
+ * the event to be investigated
+ * @return <code>true</code> if event causes a behavioral change
+ * @since 0.8.0
+ */
+ public boolean affectsTextPresentation(PropertyChangeEvent event) {
+ return fCodeScanner.affectsBehavior(event)
+ || fMultilineCommentScanner.affectsBehavior(event)
+ || fSinglelineCommentScanner.affectsBehavior(event)
+ || fStringScanner.affectsBehavior(event)
+ || fRegexpScanner.affectsBehavior(event)
+ || fCommandScanner.affectsBehavior(event);
+ }
+ /**
+ * Adapts the behavior of the contained components to the change encoded in
+ * the given event.
+ * <p>
+ * Clients are not allowed to call this method if the old setup with text
+ * tools is in use.
+ * </p>
+ *
+ * @param event
+ * the event to which to adapt
+ * @see RubySourceViewerConfiguration#RubySourceViewerConfiguration(IColorManager,
+ * IPreferenceStore, ITextEditor, String)
+ * @since 0.8.0
+ */
+ public void handlePropertyChangeEvent(PropertyChangeEvent event) {
+ Assert.isTrue(isNewSetup());
+ if (fCodeScanner.affectsBehavior(event))
+ fCodeScanner.adaptToPreferenceChange(event);
+ if (fMultilineCommentScanner.affectsBehavior(event))
+ fMultilineCommentScanner.adaptToPreferenceChange(event);
+ if (fSinglelineCommentScanner.affectsBehavior(event))
+ fSinglelineCommentScanner.adaptToPreferenceChange(event);
+ if (fStringScanner.affectsBehavior(event))
+ fStringScanner.adaptToPreferenceChange(event);
+ if (fRegexpScanner.affectsBehavior(event))
+ fRegexpScanner.adaptToPreferenceChange(event);
+ if (fCommandScanner.affectsBehavior(event))
+ fCommandScanner.adaptToPreferenceChange(event);
+ }
- /**
- * Creates and returns a preference store which combines the preference
- * stores from the text tools and which is read-only.
- *
- * @param rubyTextTools
- * the Ruby text tools
- * @return the combined read-only preference store
- * @since 0.8.0
- */
- private static final IPreferenceStore createPreferenceStore(RubyTextTools rubyTextTools) {
- Assert.isNotNull(rubyTextTools);
- IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
- if (rubyTextTools.getCorePreferenceStore() == null)
- return new ChainedPreferenceStore(new IPreferenceStore[] {
- rubyTextTools.getPreferenceStore(), generalTextStore});
+ /**
+ * Creates and returns a preference store which combines the preference
+ * stores from the text tools and which is read-only.
+ *
+ * @param rubyTextTools
+ * the Ruby text tools
+ * @return the combined read-only preference store
+ * @since 0.8.0
+ */
+ private static final IPreferenceStore createPreferenceStore(
+ RubyTextTools rubyTextTools) {
+ Assert.isNotNull(rubyTextTools);
+ IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
+ if (rubyTextTools.getCorePreferenceStore() == null)
+ return new ChainedPreferenceStore(new IPreferenceStore[] {
+ rubyTextTools.getPreferenceStore(), generalTextStore });
- return new ChainedPreferenceStore(new IPreferenceStore[] {
- rubyTextTools.getPreferenceStore(),
- new PreferencesAdapter(rubyTextTools.getCorePreferenceStore()), generalTextStore});
- }
+ return new ChainedPreferenceStore(new IPreferenceStore[] {
+ rubyTextTools.getPreferenceStore(),
+ new PreferencesAdapter(rubyTextTools.getCorePreferenceStore()),
+ generalTextStore });
+ }
- /**
- * Initializes the scanners.
- *
- * @since 3.0
- */
- private void initializeScanners() {
- Assert.isTrue(isNewSetup());
- fCodeScanner = new RubyCodeScanner(getColorManager(), fPreferenceStore);
- fMultilineCommentScanner = new RubyCommentScanner(getColorManager(), fPreferenceStore,
- IRubyColorConstants.RUBY_MULTI_LINE_COMMENT);
- fSinglelineCommentScanner = new RubyCommentScanner(getColorManager(), fPreferenceStore,
- IRubyColorConstants.RUBY_SINGLE_LINE_COMMENT);
- fStringScanner = new SingleTokenRubyCodeScanner(getColorManager(), fPreferenceStore,
- IRubyColorConstants.RUBY_STRING);
- fRegexpScanner = new SingleTokenRubyCodeScanner(getColorManager(), fPreferenceStore,
- IRubyColorConstants.RUBY_REGEXP);
- fCommandScanner = new SingleTokenRubyCodeScanner(getColorManager(), fPreferenceStore,
- IRubyColorConstants.RUBY_COMMAND);
- }
+ /**
+ * Initializes the scanners.
+ *
+ * @since 3.0
+ */
+ private void initializeScanners() {
+ Assert.isTrue(isNewSetup());
+ fCodeScanner = new RubyCodeScanner(getColorManager(), fPreferenceStore);
+ fMultilineCommentScanner = new RubyCommentScanner(getColorManager(),
+ fPreferenceStore, IRubyColorConstants.RUBY_MULTI_LINE_COMMENT);
+ fSinglelineCommentScanner = new RubyCommentScanner(getColorManager(),
+ fPreferenceStore, IRubyColorConstants.RUBY_SINGLE_LINE_COMMENT);
+ fStringScanner = new SingleTokenRubyCodeScanner(getColorManager(),
+ fPreferenceStore, IRubyColorConstants.RUBY_STRING);
+ fRegexpScanner = new SingleTokenRubyCodeScanner(getColorManager(),
+ fPreferenceStore, IRubyColorConstants.RUBY_REGEXP);
+ fCommandScanner = new SingleTokenRubyCodeScanner(getColorManager(),
+ fPreferenceStore, IRubyColorConstants.RUBY_COMMAND);
+ }
- /**
- * @return <code>true</code> iff the new setup without text tools is in
- * use.
- *
- * @since 3.0
- */
- private boolean isNewSetup() {
- return textTools == null;
- }
+ /**
+ * @return <code>true</code> iff the new setup without text tools is in
+ * use.
+ *
+ * @since 3.0
+ */
+ private boolean isNewSetup() {
+ return textTools == null;
+ }
- /**
- * Returns the color manager for this configuration.
- *
- * @return the color manager
- */
- protected IColorManager getColorManager() {
- return fColorManager;
- }
+ /**
+ * Returns the color manager for this configuration.
+ *
+ * @return the color manager
+ */
+ protected IColorManager getColorManager() {
+ return fColorManager;
+ }
- public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
- PresentationReconciler reconciler = new PresentationReconciler();
- reconciler.setDocumentPartitioning(IRubyPartitions.RUBY_PARTITIONING);
+ public IPresentationReconciler getPresentationReconciler(
+ ISourceViewer sourceViewer) {
+ PresentationReconciler reconciler = new PresentationReconciler();
+ reconciler.setDocumentPartitioning(IRubyPartitions.RUBY_PARTITIONING);
- DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getCodeScanner());
- reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
- reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getCodeScanner());
+ reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
- dr = new DefaultDamagerRepairer(getSinglelineCommentScanner());
- reconciler.setDamager(dr, RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT);
- reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT);
+ dr = new DefaultDamagerRepairer(getSinglelineCommentScanner());
+ reconciler
+ .setDamager(dr, RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT);
+ reconciler.setRepairer(dr,
+ RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT);
- dr = new DefaultDamagerRepairer(getMultilineCommentScanner());
- reconciler.setDamager(dr, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT);
- reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT);
+ dr = new DefaultDamagerRepairer(getMultilineCommentScanner());
+ reconciler.setDamager(dr, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT);
+ reconciler
+ .setRepairer(dr, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT);
- dr = new DefaultDamagerRepairer(getStringScanner());
- reconciler.setDamager(dr, RubyPartitionScanner.RUBY_STRING);
- reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_STRING);
+ dr = new DefaultDamagerRepairer(getStringScanner());
+ reconciler.setDamager(dr, RubyPartitionScanner.RUBY_STRING);
+ reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_STRING);
- dr = new DefaultDamagerRepairer(getRegexpScanner());
- reconciler.setDamager(dr, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION);
- reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION);
+ dr = new DefaultDamagerRepairer(getRegexpScanner());
+ reconciler.setDamager(dr, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION);
+ reconciler
+ .setRepairer(dr, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION);
- dr = new DefaultDamagerRepairer(getCommandScanner());
- reconciler.setDamager(dr, RubyPartitionScanner.RUBY_COMMAND);
- reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_COMMAND);
+ dr = new DefaultDamagerRepairer(getCommandScanner());
+ reconciler.setDamager(dr, RubyPartitionScanner.RUBY_COMMAND);
+ reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_COMMAND);
- return reconciler;
- }
+ return reconciler;
+ }
- private ITokenScanner getCommandScanner() {
- return fCommandScanner;
- }
+ private ITokenScanner getCommandScanner() {
+ return fCommandScanner;
+ }
- protected ITokenScanner getCodeScanner() {
- return fCodeScanner;
- }
+ protected ITokenScanner getCodeScanner() {
+ return fCodeScanner;
+ }
- protected ITokenScanner getMultilineCommentScanner() {
- return fMultilineCommentScanner;
- }
+ protected ITokenScanner getMultilineCommentScanner() {
+ return fMultilineCommentScanner;
+ }
- protected ITokenScanner getSinglelineCommentScanner() {
- return fSinglelineCommentScanner;
- }
+ protected ITokenScanner getSinglelineCommentScanner() {
+ return fSinglelineCommentScanner;
+ }
- protected ITokenScanner getStringScanner() {
- return fStringScanner;
- }
+ protected ITokenScanner getStringScanner() {
+ return fStringScanner;
+ }
- protected ITokenScanner getRegexpScanner() {
- return fRegexpScanner;
- }
+ protected ITokenScanner getRegexpScanner() {
+ return fRegexpScanner;
+ }
- public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
- return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
- RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT, RubyPartitionScanner.RUBY_STRING,
- RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT};
- }
-
- /*
- * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
- * @since 0.8.0
- */
- public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
- if (fDocumentPartitioning != null)
- return fDocumentPartitioning;
- return super.getConfiguredDocumentPartitioning(sourceViewer);
- }
+ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
+ return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
+ RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT,
+ RubyPartitionScanner.RUBY_STRING,
+ RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT };
+ }
- public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
- ContentAssistant contentAssistant = new ContentAssistant();
- contentAssistant.setContentAssistProcessor(new RubyCompletionProcessor(getEditor()),
- IDocument.DEFAULT_CONTENT_TYPE);
+ /*
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
+ * @since 0.8.0
+ */
+ public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
+ if (fDocumentPartitioning != null)
+ return fDocumentPartitioning;
+ return super.getConfiguredDocumentPartitioning(sourceViewer);
+ }
- contentAssistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
- contentAssistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
+ public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
+ fRubyCp = new RubyCompletionProcessor(getEditor());
- ContentAssistPreference.configure(contentAssistant, getPreferenceStore());
- return contentAssistant;
- }
+ ContentAssistant contentAssistant = new ContentAssistant();
+ contentAssistant.setContentAssistProcessor(fRubyCp,
+ IDocument.DEFAULT_CONTENT_TYPE);
- /*
- * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
- */
- public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
- return new RubyAnnotationHover(RubyAnnotationHover.VERTICAL_RULER_HOVER);
- }
-
- public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
- String partitioning= getConfiguredDocumentPartitioning(sourceViewer);
- if (IRubyPartitions.RUBY_SINGLE_LINE_COMMENT.equals(contentType))
- return new IAutoEditStrategy[] { new RubyCommentAutoIndentStrategy(partitioning) };
- else
+ contentAssistant
+ .setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
+ contentAssistant
+ .setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
+
+ ContentAssistPreference.configure(contentAssistant,
+ getPreferenceStore());
+ return contentAssistant;
+ }
+
+ /*
+ * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
+ */
+ public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
+ return new RubyAnnotationHover(RubyAnnotationHover.VERTICAL_RULER_HOVER);
+ }
+
+ public IAutoEditStrategy[] getAutoEditStrategies(
+ ISourceViewer sourceViewer, String contentType) {
+ String partitioning = getConfiguredDocumentPartitioning(sourceViewer);
+ if (IRubyPartitions.RUBY_SINGLE_LINE_COMMENT.equals(contentType)) {
+ return new IAutoEditStrategy[] { new RubyCommentAutoIndentStrategy(
+ partitioning) };
+ } else if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) {
+ IAutoEditStrategy[] strategies = super.getAutoEditStrategies(
+ sourceViewer, contentType);
+ IAutoEditStrategy[] newStrategies = new IAutoEditStrategy[strategies.length + 1];
+ System
+ .arraycopy(strategies, 0, newStrategies, 0,
+ strategies.length);
+ newStrategies[newStrategies.length - 1] = new RubyAutoEditStrategy(
+ partitioning, sourceViewer, fRubyCp);
+ strategies = newStrategies;
+ return strategies;
+ } else {
return super.getAutoEditStrategies(sourceViewer, contentType);
- }
+ }
+ }
- /*
- * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
- * @since 2.0
- */
- public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
- return new IInformationControlCreator() {
+ /*
+ * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
+ * @since 2.0
+ */
+ public IInformationControlCreator getInformationControlCreator(
+ ISourceViewer sourceViewer) {
+ return new IInformationControlCreator() {
- public IInformationControl createInformationControl(Shell parent) {
- return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true));
- }
- };
- }
+ public IInformationControl createInformationControl(Shell parent) {
+ return new DefaultInformationControl(parent, SWT.NONE,
+ new HTMLTextPresenter(true));
+ }
+ };
+ }
- /**
- * Returns the editor in which the configured viewer(s) will reside.
- *
- * @return the enclosing editor
- */
- protected ITextEditor getEditor() {
- return fTextEditor;
- }
+ /**
+ * Returns the editor in which the configured viewer(s) will reside.
+ *
+ * @return the enclosing editor
+ */
+ protected ITextEditor getEditor() {
+ return fTextEditor;
+ }
- protected IPreferenceStore getPreferenceStore() {
- return RubyPlugin.getDefault().getPreferenceStore();
- }
+ protected IPreferenceStore getPreferenceStore() {
+ return RubyPlugin.getDefault().getPreferenceStore();
+ }
- public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) {
- return new String[] { "#", ""};
- }
+ public String[] getDefaultPrefixes(ISourceViewer sourceViewer,
+ String contentType) {
+ return new String[] { "#", "" };
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer)
- */
- public IReconciler getReconciler(ISourceViewer sourceViewer) {
- final ITextEditor editor = getEditor();
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer)
+ */
+ public IReconciler getReconciler(ISourceViewer sourceViewer) {
+ final ITextEditor editor = getEditor();
if (editor != null && editor.isEditable()) {
RubyReconciler reconciler = new RubyReconciler(fTextEditor,
new RubyReconcilingStrategy(
@@ -409,19 +453,19 @@
return reconciler;
}
return null;
- }
-
- private IRubyProject getProject() {
- ITextEditor editor= getEditor();
+ }
+
+ private IRubyProject getProject() {
+ ITextEditor editor = getEditor();
if (editor == null)
return null;
- IRubyElement element= null;
- IEditorInput input= editor.getEditorInput();
- IDocumentProvider provider= editor.getDocumentProvider();
+ IRubyElement element = null;
+ IEditorInput input = editor.getEditorInput();
+ IDocumentProvider provider = editor.getDocumentProvider();
if (provider instanceof IRubyScriptDocumentProvider) {
- IRubyScriptDocumentProvider cudp= (IRubyScriptDocumentProvider) provider;
- element= cudp.getWorkingCopy(input);
+ IRubyScriptDocumentProvider cudp = (IRubyScriptDocumentProvider) provider;
+ element = cudp.getWorkingCopy(input);
}
if (element == null)
@@ -430,37 +474,43 @@
return element.getRubyProject();
}
- public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
+ public String[] getIndentPrefixes(ISourceViewer sourceViewer,
+ String contentType) {
- Vector vector= new Vector();
+ Vector vector = new Vector();
// prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
- IRubyProject project= getProject();
- final int tabWidth= CodeFormatterUtil.getTabWidth(project);
- final int indentWidth= CodeFormatterUtil.getIndentWidth(project);
- int spaceEquivalents= Math.min(tabWidth, indentWidth);
+ IRubyProject project = getProject();
+ final int tabWidth = CodeFormatterUtil.getTabWidth(project);
+ final int indentWidth = CodeFormatterUtil.getIndentWidth(project);
+ int spaceEquivalents = Math.min(tabWidth, indentWidth);
boolean useSpaces;
if (project == null)
- useSpaces= RubyCore.SPACE.equals(RubyCore.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR)) || tabWidth > indentWidth;
+ useSpaces = RubyCore.SPACE
+ .equals(RubyCore
+ .getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR))
+ || tabWidth > indentWidth;
else
- useSpaces= RubyCore.SPACE.equals(project.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, true)) || tabWidth > indentWidth;
+ useSpaces = RubyCore.SPACE.equals(project.getOption(
+ DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, true))
+ || tabWidth > indentWidth;
- for (int i= 0; i <= spaceEquivalents; i++) {
- StringBuffer prefix= new StringBuffer();
+ for (int i = 0; i <= spaceEquivalents; i++) {
+ StringBuffer prefix = new StringBuffer();
if (useSpaces) {
- for (int j= 0; j + i < spaceEquivalents; j++)
- prefix.append(' ');
+ for (int j = 0; j + i < spaceEquivalents; j++)
+ prefix.append(' ');
if (i != 0)
- prefix.append('\t');
+ prefix.append('\t');
} else {
- for (int j= 0; j < i; j++)
- prefix.append(' ');
+ for (int j = 0; j < i; j++)
+ prefix.append(' ');
if (i != spaceEquivalents)
- prefix.append('\t');
+ prefix.append('\t');
}
vector.add(prefix.toString());
@@ -469,16 +519,16 @@
vector.add(""); //$NON-NLS-1$
return (String[]) vector.toArray(new String[vector.size()]);
- }
+ }
- public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer,
- String contentType) {
- if (fRubyDoubleClickSelector == null) {
- fRubyDoubleClickSelector= new RubyDoubleClickSelector();
- }
- return fRubyDoubleClickSelector;
- }
-
+ public ITextDoubleClickStrategy getDoubleClickStrategy(
+ ISourceViewer sourceViewer, String contentType) {
+ if (fRubyDoubleClickSelector == null) {
+ fRubyDoubleClickSelector = new RubyDoubleClickSelector();
+ }
+ return fRubyDoubleClickSelector;
+ }
+
/*
* @see SourceViewerConfiguration#getTabWidth(ISourceViewer)
*/
@@ -486,11 +536,12 @@
return CodeFormatterUtil.getTabWidth(getProject());
}
- public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
- if (fRubyTextHover == null) {
- fRubyTextHover = new RubyCodeTextHover();
- }
- return fRubyTextHover;
- }
+ public ITextHover getTextHover(ISourceViewer sourceViewer,
+ String contentType) {
+ if (fRubyTextHover == null) {
+ fRubyTextHover = new RubyCodeTextHover();
+ }
+ return fRubyTextHover;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-15 22:02:37
|
Revision: 1715
http://svn.sourceforge.net/rubyeclipse/?rev=1715&view=rev
Author: cawilliams
Date: 2006-12-15 14:02:36 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
remove deprecated code
Modified Paths:
--------------
trunk/org.epic.regexp/src/org/epic/regexp/RegExpPlugin.java
Modified: trunk/org.epic.regexp/src/org/epic/regexp/RegExpPlugin.java
===================================================================
--- trunk/org.epic.regexp/src/org/epic/regexp/RegExpPlugin.java 2006-12-15 21:55:07 UTC (rev 1714)
+++ trunk/org.epic.regexp/src/org/epic/regexp/RegExpPlugin.java 2006-12-15 22:02:36 UTC (rev 1715)
@@ -70,7 +70,7 @@
try
{
- installURL = Platform.resolve(installURL);
+ installURL = FileLocator.resolve(installURL);
} catch (IOException e)
{
e.printStackTrace();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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] |
|
From: <caw...@us...> - 2006-12-15 15:40:46
|
Revision: 1713
http://svn.sourceforge.net/rubyeclipse/?rev=1713&view=rev
Author: cawilliams
Date: 2006-12-15 07:40:46 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
Added Paths:
-----------
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/launcher/TestUnitTabGroup.java
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/launcher/TestUnitTabGroup.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/launcher/TestUnitTabGroup.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/launcher/TestUnitTabGroup.java 2006-12-15 15:40:46 UTC (rev 1713)
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.testunit.launcher;
+
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
+import org.eclipse.debug.ui.CommonTab;
+import org.eclipse.debug.ui.ILaunchConfigurationDialog;
+import org.eclipse.debug.ui.ILaunchConfigurationTab;
+import org.eclipse.debug.ui.ILaunchConfigurationTabGroup;
+import org.rubypeople.rdt.internal.debug.ui.launcher.RubyEnvironmentTab;
+import org.rubypeople.rdt.testunit.launcher.TestUnitMainTab;
+
+public class TestUnitTabGroup extends AbstractLaunchConfigurationTabGroup {
+
+ /**
+ * @see ILaunchConfigurationTabGroup#createTabs(ILaunchConfigurationDialog,
+ * String)
+ */
+ public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
+ ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { new TestUnitMainTab(), new RubyEnvironmentTab(), new CommonTab()};
+ setTabs(tabs);
+ }
+
+ /**
+ * @see ILaunchConfigurationTabGroup#setDefaults(ILaunchConfigurationWorkingCopy)
+ */
+ public void setDefaults(ILaunchConfigurationWorkingCopy config) {
+ super.setDefaults(config);
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-15 15:40:28
|
Revision: 1712
http://svn.sourceforge.net/rubyeclipse/?rev=1712&view=rev
Author: cawilliams
Date: 2006-12-15 07:40:23 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
Added Paths:
-----------
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/runner/MessageIds.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/runner/TestUnitRunner.java
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/runner/MessageIds.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/runner/MessageIds.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/runner/MessageIds.java 2006-12-15 15:40:23 UTC (rev 1712)
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.testunit.runner;
+
+/**
+ * Message identifiers for messages sent by the
+ * RemoteTestRunner.
+ *
+ * @see RemoteTestRunner
+ */
+public class MessageIds {
+ /**
+ * The header length of a message, all messages
+ * have a fixed header length
+ */
+ public static final int MSG_HEADER_LENGTH= 8;
+
+ /**
+ * Notification that a test trace has started.
+ * The end of the trace is signaled by a TRACE_END
+ * message. In between the TRACE_START and TRACE_END
+ * the stack trace is submitted as multiple lines.
+ */
+ public static final String TRACE_START= "%TRACES "; //$NON-NLS-1$
+ /**
+ * Notification that a trace ends.
+ */
+ public static final String TRACE_END= "%TRACEE "; //$NON-NLS-1$
+ /**
+ * Notification that the expected result has started.
+ * The end of the expected result is signaled by a Trace_END.
+ */
+ public static final String EXPECTED_START= "%EXPECTS"; //$NON-NLS-1$
+ /**
+ * Notification that an expected result ends.
+ */
+ public static final String EXPECTED_END= "%EXPECTE"; //$NON-NLS-1$
+ /**
+ * Notification that the expected result has started.
+ * The end of the expected result is signaled by a Trace_END.
+ */
+ public static final String ACTUAL_START= "%ACTUALS"; //$NON-NLS-1$
+ /**
+ * Notification that an expected result ends.
+ */
+ public static final String ACTUAL_END= "%ACTUALE"; //$NON-NLS-1$
+ /**
+ * Notification that a trace for a reran test has started.
+ * The end of the trace is signaled by a RTrace_END
+ * message.
+ */
+ public static final String RTRACE_START= "%RTRACES"; //$NON-NLS-1$
+ /**
+ * Notification that a trace of a reran trace ends.
+ */
+ public static final String RTRACE_END= "%RTRACEE"; //$NON-NLS-1$
+ /**
+ * Notification that a test run has started.
+ * MessageIds.TEST_RUN_START+testCount.toString+" "+version
+ */
+ public static final String TEST_RUN_START= "%TESTC "; //$NON-NLS-1$
+ /**
+ * Notification that a test has started.
+ * MessageIds.TEST_START + testID + "," + testName
+ */
+ public static final String TEST_START= "%TESTS "; //$NON-NLS-1$
+ /**
+ * Notification that a test has started.
+ * TEST_END + testID + "," + testName
+ */
+ public static final String TEST_END= "%TESTE "; //$NON-NLS-1$
+ /**
+ * Notification that a test had a error.
+ * TEST_ERROR + testID + "," + testName.
+ * After the notification follows the stack trace.
+ */
+ public static final String TEST_ERROR= "%ERROR "; //$NON-NLS-1$
+ /**
+ * Notification that a test had a failure.
+ * TEST_FAILED + testID + "," + testName.
+ * After the notification follows the stack trace.
+ */
+ public static final String TEST_FAILED= "%FAILED "; //$NON-NLS-1$
+ /**
+ * Notification that a test run has ended.
+ * TEST_RUN_END+elapsedTime.toString().
+ */
+ public static final String TEST_RUN_END="%RUNTIME"; //$NON-NLS-1$
+ /**
+ * Notification that a test run was successfully stopped.
+ */
+ public static final String TEST_STOPPED="%TSTSTP "; //$NON-NLS-1$
+ /**
+ * Notification that a test was reran.
+ * TEST_RERAN+testId+" "+testClass+" "+testName+STATUS.
+ * Status = "OK" or "FAILURE".
+ */
+ public static final String TEST_RERAN= "%TSTRERN"; //$NON-NLS-1$
+ /**
+ * Notification about a test inside the test suite.
+ * TEST_TREE+ testId"," + testName","isSuite","testcount
+ * isSuite = "true" or "false"
+ */
+ public static final String TEST_TREE="%TSTTREE"; //$NON-NLS-1$
+ /**
+ * Request to stop the current test run.
+ */
+ public static final String TEST_STOP= ">STOP "; //$NON-NLS-1$
+ /**
+ * Request to rerun a test.
+ * TEST_RERUN+testId+" "+ClassName+" "+testName
+ */
+ public static final String TEST_RERUN= ">RERUN "; //$NON-NLS-1$
+}
+
+
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/runner/TestUnitRunner.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/runner/TestUnitRunner.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/runner/TestUnitRunner.java 2006-12-15 15:40:23 UTC (rev 1712)
@@ -0,0 +1,39 @@
+/*
+ * Author: C.Williams
+ *
+ * Copyright (c) 2004 RubyPeople.
+ *
+ * This file is part of the Ruby Development Tools (RDT) plugin for eclipse. You
+ * can get copy of the GPL along with further information about RubyPeople and
+ * third party software bundled with RDT in the file
+ * org.rubypeople.rdt.core_x.x.x/RDT.license or otherwise at
+ * http://www.rubypeople.org/RDT.license.
+ *
+ * RDT is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * RDT is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * RDT; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.rubypeople.rdt.internal.testunit.runner;
+
+import org.rubypeople.rdt.internal.launching.InterpreterRunner;
+
+/**
+ * @author Chris
+ *
+ */
+public class TestUnitRunner extends InterpreterRunner {
+
+ public TestUnitRunner() {
+ super();
+ }
+
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-15 15:39:50
|
Revision: 1711
http://svn.sourceforge.net/rubyeclipse/?rev=1711&view=rev
Author: cawilliams
Date: 2006-12-15 07:39:49 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
Added Paths:
-----------
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/CompareResultsAction.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/CopyTraceAction.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/CounterPanel.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/FailureTab.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/FailureTrace.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/ITestRunListener2.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/ITestRunListener3.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenEditorAtLineAction.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenLocationAction.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenSymbolAction.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/RemoteTestRunnerClient.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/RerunAction.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/ScrollLockAction.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TabFolderLayout.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestHierarchyTab.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestRunInfo.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestRunTab.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitMessages.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitMessages.properties
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitProgressBar.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitView.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestunitPlugin.java
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/CompareResultsAction.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/CompareResultsAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/CompareResultsAction.java 2006-12-15 15:39:49 UTC (rev 1711)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.testunit.ui;
+
+import org.eclipse.jface.action.Action;
+
+/**
+ * Action to enable/disable stack trace filtering.
+ */
+public class CompareResultsAction extends Action {
+
+
+ public CompareResultsAction(FailureTrace view) {
+ super(TestUnitMessages.getString("CompareResultsAction.label")); //$NON-NLS-1$
+ setDescription(TestUnitMessages.getString("CompareResultsAction.description")); //$NON-NLS-1$
+ setToolTipText(TestUnitMessages.getString("CompareResultsAction.tooltip")); //$NON-NLS-1$
+
+ setDisabledImageDescriptor(TestunitPlugin.getImageDescriptor("dlcl16/compare.gif")); //$NON-NLS-1$
+ setHoverImageDescriptor(TestunitPlugin.getImageDescriptor("elcl16/compare.gif")); //$NON-NLS-1$
+ setImageDescriptor(TestunitPlugin.getImageDescriptor("elcl16/compare.gif")); //$NON-NLS-1$
+ }
+
+ /*
+ * @see Action#actionPerformed
+ */
+ public void run() {
+ // TODO Allow comparison of results
+// CompareResultDialog dialog = new CompareResultDialog(fView.getShell(), fView.getFailedTest());
+// dialog.create();
+// dialog.open();
+ }
+}
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/CopyTraceAction.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/CopyTraceAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/CopyTraceAction.java 2006-12-15 15:39:49 UTC (rev 1711)
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.testunit.ui;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import org.eclipse.swt.SWTError;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.util.Assert;
+
+/**
+ * Copies a test failure stack trace to the clipboard.
+ */
+public class CopyTraceAction extends Action {
+ private FailureTrace fView;
+
+ private final Clipboard fClipboard;
+
+ /**
+ * Constructor for CopyTraceAction.
+ */
+ public CopyTraceAction(FailureTrace view, Clipboard clipboard) {
+ super(TestUnitMessages.getString("CopyTrace.action.label")); //$NON-NLS-1$
+ Assert.isNotNull(clipboard);
+ // TODO Show help!
+ //WorkbenchHelp.setHelp(this, ITestUnitHelpContextIds.COPYTRACE_ACTION);
+ fView= view;
+ fClipboard= clipboard;
+ }
+
+ /*
+ * @see IAction#run()
+ */
+ public void run() {
+ String trace= fView.getTrace();
+ if (trace == null)
+ trace= ""; //$NON-NLS-1$
+
+ TextTransfer plainTextTransfer = TextTransfer.getInstance();
+ try{
+ fClipboard.setContents(
+ new String[]{ convertLineTerminators(trace) },
+ new Transfer[]{ plainTextTransfer });
+ } catch (SWTError e){
+ if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD)
+ throw e;
+ if (MessageDialog.openQuestion(fView.getComposite().getShell(), TestUnitMessages.getString("CopyTraceAction.problem"), TestUnitMessages.getString("CopyTraceAction.clipboard_busy"))) //$NON-NLS-1$ //$NON-NLS-2$
+ run();
+ }
+ }
+
+ private String convertLineTerminators(String in) {
+ StringWriter stringWriter= new StringWriter();
+ PrintWriter printWriter= new PrintWriter(stringWriter);
+ StringReader stringReader= new StringReader(in);
+ BufferedReader bufferedReader= new BufferedReader(stringReader);
+ String line;
+ try {
+ while ((line= bufferedReader.readLine()) != null) {
+ printWriter.println(line);
+ }
+ } catch (IOException e) {
+ return in; // return the trace unfiltered
+ }
+ return stringWriter.toString();
+ }
+}
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/CounterPanel.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/CounterPanel.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/CounterPanel.java 2006-12-15 15:39:49 UTC (rev 1711)
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.testunit.ui;
+
+
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * A panel with counters for the number of Runs, Errors and Failures.
+ */
+public class CounterPanel extends Composite {
+ protected Text fNumberOfErrors;
+ protected Text fNumberOfFailures;
+ protected Text fNumberOfRuns;
+ protected int fTotal;
+
+ private final Image fErrorIcon= TestUnitView.createImage("ovr16/error_ovr.gif"); //$NON-NLS-1$
+ private final Image fFailureIcon= TestUnitView.createImage("ovr16/failed_ovr.gif"); //$NON-NLS-1$
+
+ public CounterPanel(Composite parent) {
+ super(parent, SWT.WRAP);
+ GridLayout gridLayout= new GridLayout();
+ gridLayout.numColumns= 9;
+ gridLayout.makeColumnsEqualWidth= false;
+ gridLayout.marginWidth= 0;
+ setLayout(gridLayout);
+
+ fNumberOfRuns= createLabel(TestUnitMessages.getString("CounterPanel.label.runs"), null, " 0/0 "); //$NON-NLS-1$ //$NON-NLS-2$
+ fNumberOfErrors= createLabel(TestUnitMessages.getString("CounterPanel.label.errors"), fErrorIcon, " 0 "); //$NON-NLS-1$ //$NON-NLS-2$
+ fNumberOfFailures= createLabel(TestUnitMessages.getString("CounterPanel.label.failures"), fFailureIcon, " 0 "); //$NON-NLS-1$ //$NON-NLS-2$
+
+ addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ disposeIcons();
+ }
+ });
+ }
+
+ private void disposeIcons() {
+ fErrorIcon.dispose();
+ fFailureIcon.dispose();
+ }
+
+ private Text createLabel(String name, Image image, String init) {
+ Label label= new Label(this, SWT.NONE);
+ if (image != null) {
+ image.setBackground(label.getBackground());
+ label.setImage(image);
+ }
+ label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
+
+ label= new Label(this, SWT.NONE);
+ label.setText(name);
+ label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
+ label.setFont(JFaceResources.getBannerFont());
+
+ Text value= new Text(this, SWT.READ_ONLY);
+ value.setText(init);
+ // bug: 39661 Junit test counters do not repaint correctly [JUnit]
+ value.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ value.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));
+ return value;
+ }
+
+ public void reset() {
+ setErrorValue(0);
+ setFailureValue(0);
+ setRunValue(0);
+ fTotal= 0;
+ }
+
+ public void setTotal(int value) {
+ fTotal= value;
+ }
+
+ public int getTotal(){
+ return fTotal;
+ }
+
+ public void setRunValue(int value) {
+ String runString= TestUnitMessages.getFormattedString("CounterPanel.runcount", new String[] { Integer.toString(value), Integer.toString(fTotal) }); //$NON-NLS-1$
+ fNumberOfRuns.setText(runString);
+
+ fNumberOfRuns.redraw();
+ redraw();
+ }
+
+ public void setErrorValue(int value) {
+ fNumberOfErrors.setText(Integer.toString(value));
+ redraw();
+ }
+
+ public void setFailureValue(int value) {
+ fNumberOfFailures.setText(Integer.toString(value));
+ redraw();
+ }
+}
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/FailureTab.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/FailureTab.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/FailureTab.java 2006-12-15 15:39:49 UTC (rev 1711)
@@ -0,0 +1,348 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.testunit.ui;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.internal.core.symbols.ISymbolFinder;
+import org.rubypeople.rdt.testunit.ITestRunListener;
+
+/**
+ * A tab presenting the failed tests in a table.
+ */
+public class FailureTab extends TestRunTab implements IMenuListener {
+
+ private Table fTable;
+ private TestUnitView fRunnerViewPart;
+ private boolean fMoveSelection = false;
+
+ private final Image fErrorIcon = TestUnitView.createImage("obj16/testerr.gif"); //$NON-NLS-1$
+ private final Image fFailureIcon = TestUnitView.createImage("obj16/testfail.gif"); //$NON-NLS-1$
+ private final Image fFailureTabIcon = TestUnitView.createImage("obj16/failures.gif"); //$NON-NLS-1$
+
+ public FailureTab() {}
+
+ public void createTabControl(CTabFolder tabFolder, Clipboard clipboard, TestUnitView runner) {
+ fRunnerViewPart = runner;
+
+ CTabItem failureTab = new CTabItem(tabFolder, SWT.NONE);
+ failureTab.setText(getName());
+ failureTab.setImage(fFailureTabIcon);
+
+ Composite composite = new Composite(tabFolder, SWT.NONE);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.marginHeight = 0;
+ gridLayout.marginWidth = 0;
+ composite.setLayout(gridLayout);
+
+ GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
+ composite.setLayoutData(gridData);
+
+ fTable = new Table(composite, SWT.NONE);
+ gridLayout = new GridLayout();
+ gridLayout.marginHeight = 0;
+ gridLayout.marginWidth = 0;
+ fTable.setLayout(gridLayout);
+
+ gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
+ fTable.setLayoutData(gridData);
+
+ failureTab.setControl(composite);
+ failureTab.setToolTipText(TestUnitMessages.getString("FailureRunView.tab.tooltip")); //$NON-NLS-1$
+
+ initMenu();
+ addListeners();
+ }
+
+ private void disposeIcons() {
+ fErrorIcon.dispose();
+ fFailureIcon.dispose();
+ fFailureTabIcon.dispose();
+ }
+
+ private void initMenu() {
+ MenuManager menuMgr = new MenuManager();
+ menuMgr.setRemoveAllWhenShown(true);
+ menuMgr.addMenuListener(this);
+ Menu menu = menuMgr.createContextMenu(fTable);
+ fTable.setMenu(menu);
+ }
+
+ public String getName() {
+ return TestUnitMessages.getString("FailureRunView.tab.title"); //$NON-NLS-1$
+ }
+
+ public String getSelectedTestId() {
+ int index = fTable.getSelectionIndex();
+ if (index == -1) return null;
+ return getTestInfo(fTable.getItem(index)).getTestId();
+ }
+
+ public String getAllFailedTestNames() {
+ StringBuffer trace = new StringBuffer();
+ String lineDelim = System.getProperty("line.separator", "\n"); //$NON-NLS-1$//$NON-NLS-2$
+ for (int i = 0; i < fTable.getItemCount(); i++) {
+ TestRunInfo testInfo = getTestInfo(fTable.getItem(i));
+ trace.append(testInfo.getTestName()).append(lineDelim);
+ String failureTrace = testInfo.getTrace();
+ if (failureTrace != null) {
+ StringReader stringReader = new StringReader(failureTrace);
+ BufferedReader bufferedReader = new BufferedReader(stringReader);
+ String line;
+ try {
+ while ((line = bufferedReader.readLine()) != null)
+ trace.append(line + lineDelim);
+ } catch (IOException e) {
+ trace.append(lineDelim);
+ }
+ }
+ }
+ return trace.toString();
+ }
+
+ private String getClassName() {
+ TableItem item = getSelectedItem();
+ TestRunInfo info = getTestInfo(item);
+ return info.getClassName();
+ }
+
+ private String getMethodName() {
+ TableItem item = getSelectedItem();
+ TestRunInfo info = getTestInfo(item);
+ return info.getTestMethodName();
+ }
+
+ public void menuAboutToShow(IMenuManager manager) {
+ if (fTable.getSelectionCount() > 0) {
+ String className = getClassName();
+ String methodName = getMethodName();
+ if (className != null) {
+ System.err.println("MethodName: " + methodName);
+ manager.add(OpenSymbolAction.forMethod(className, methodName, getSymbolFinder(), getShell()));
+ manager.add(new Separator());
+ manager.add(new RerunAction(fRunnerViewPart, getSelectedTestId(),
+ className, methodName, ILaunchManager.RUN_MODE));
+ manager.add(new RerunAction(fRunnerViewPart, getSelectedTestId(),
+ className, methodName, ILaunchManager.DEBUG_MODE));
+ manager.add(new Separator());
+ // TODO Add back the actions!
+ //manager.add(new CopyFailureListAction(fRunnerViewPart,
+ // FailureTab.this, fClipboard));
+ }
+ }
+ }
+
+ private ISymbolFinder getSymbolFinder() {
+ return RubyCore.getPlugin().getSymbolFinder();
+ }
+
+ private TableItem getSelectedItem() {
+ int index = fTable.getSelectionIndex();
+ if (index == -1) return null;
+ return fTable.getItem(index);
+ }
+
+ public void setSelectedTest(String testId) {
+ TableItem[] items = fTable.getItems();
+ for (int i = 0; i < items.length; i++) {
+ TableItem tableItem = items[i];
+ TestRunInfo info = getTestInfo(tableItem);
+ if (info.getTestId().equals(testId)) {
+ fTable.setSelection(new TableItem[] { tableItem});
+ fTable.showItem(tableItem);
+ return;
+ }
+ }
+ }
+
+ private TestRunInfo getTestInfo(TableItem item) {
+ return (TestRunInfo) item.getData();
+ }
+
+ public void setFocus() {
+ fTable.setFocus();
+ }
+
+ public void endTest(String testId) {
+ TestRunInfo testInfo = fRunnerViewPart.getTestInfo(testId);
+ if (testInfo == null || testInfo.getStatus() == ITestRunListener.STATUS_OK) return;
+
+ TableItem tableItem = new TableItem(fTable, SWT.NONE);
+ updateTableItem(testInfo, tableItem);
+ fTable.showItem(tableItem);
+ }
+
+ private void updateTableItem(TestRunInfo testInfo, TableItem tableItem) {
+ String label = TestUnitMessages.getFormattedString("FailureRunView.labelfmt", new String[] { testInfo.getTestMethodName(), testInfo.getClassName()}); //$NON-NLS-1$
+ tableItem.setText(label);
+ if (testInfo.getStatus() == ITestRunListener.STATUS_FAILURE)
+ tableItem.setImage(fFailureIcon);
+ else
+ tableItem.setImage(fErrorIcon);
+ tableItem.setData(testInfo);
+ }
+
+ private TableItem findItem(String testId) {
+ TableItem[] items = fTable.getItems();
+ for (int i = 0; i < items.length; i++) {
+ TestRunInfo info = getTestInfo(items[i]);
+ if (info.getTestId().equals(testId)) return items[i];
+ }
+ return null;
+ }
+
+ public void activate() {
+ fMoveSelection = false;
+ testSelected();
+ }
+
+ public void aboutToStart() {
+ fMoveSelection = false;
+ fTable.removeAll();
+ }
+
+ private void testSelected() {
+ fRunnerViewPart.handleTestSelected(getSelectedTestId());
+ }
+
+ private void addListeners() {
+ fTable.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(SelectionEvent e) {
+ activate();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ activate();
+ }
+ });
+
+ fTable.addDisposeListener(new DisposeListener() {
+
+ public void widgetDisposed(DisposeEvent e) {
+ disposeIcons();
+ }
+ });
+
+ fTable.addMouseListener(new MouseAdapter() {
+
+ public void mouseDoubleClick(MouseEvent e) {
+ handleDoubleClick(e);
+ }
+
+ public void mouseDown(MouseEvent e) {
+ activate();
+ }
+
+ public void mouseUp(MouseEvent e) {
+ activate();
+ }
+ });
+ }
+
+ void handleDoubleClick(MouseEvent e) {
+ if (fTable.getSelectionCount() > 0)
+ OpenSymbolAction.forMethod(getClassName(), getMethodName(), getSymbolFinder(), getShell()).run();
+ }
+
+ private Shell getShell() {
+ return fTable.getShell();
+ }
+
+ /*
+ * @see ITestRunView#testStatusChanged(TestRunInfo)
+ */
+ public void testStatusChanged(TestRunInfo info) {
+ TableItem item = findItem(info.getTestId());
+ if (item != null) {
+ if (info.getStatus() == ITestRunListener.STATUS_OK) {
+ item.dispose();
+ return;
+ }
+ updateTableItem(info, item);
+ }
+ if (item == null && info.getStatus() != ITestRunListener.STATUS_OK) {
+ item = new TableItem(fTable, SWT.NONE);
+ updateTableItem(info, item);
+ }
+ if (item != null) fTable.showItem(item);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jdt.internal.junit.ui.ITestRunView#selectNext()
+ */
+ public void selectNext() {
+ if (fTable.getItemCount() == 0) return;
+
+ int index = fTable.getSelectionIndex();
+ if (index == -1) index = 0;
+
+ if (fMoveSelection)
+ index = Math.min(fTable.getItemCount() - 1, index + 1);
+ else
+ fMoveSelection = true;
+
+ selectTest(index);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jdt.internal.junit.ui.ITestRunView#selectPrevious()
+ */
+ public void selectPrevious() {
+ if (fTable.getItemCount() == 0) return;
+
+ int index = fTable.getSelectionIndex();
+ if (index == -1) index = fTable.getItemCount() - 1;
+
+ if (fMoveSelection)
+ index = Math.max(0, index - 1);
+ else
+ fMoveSelection = true;
+
+ selectTest(index);
+ }
+
+ private void selectTest(int index) {
+ TableItem item = fTable.getItem(index);
+ TestRunInfo info = getTestInfo(item);
+ fRunnerViewPart.showTest(info);
+ }
+}
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/FailureTrace.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/FailureTrace.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/FailureTrace.java 2006-12-15 15:39:49 UTC (rev 1711)
@@ -0,0 +1,262 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Sebastian Davids: sd...@gm... bug 37333, 26653
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.testunit.ui;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.util.IOpenEventListener;
+import org.eclipse.jface.util.OpenStrategy;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.ToolBar;
+import org.rubypeople.rdt.internal.ui.util.StackTraceLine;
+
+/**
+ * A pane that shows a stack trace of a failed test.
+ */
+public class FailureTrace implements IMenuListener {
+ private final Image fStackIcon= TestUnitView.createImage("obj16/stkfrm_obj.gif"); //$NON-NLS-1$
+ private final Image fExceptionIcon= TestUnitView.createImage("obj16/exc_catch.gif"); //$NON-NLS-1$
+
+ private Table fTable;
+ private String fInputTrace;
+ private final Clipboard fClipboard;
+ private TestRunInfo fFailure;
+ private CompareResultsAction fCompareAction;
+
+
+ public FailureTrace(Composite parent, Clipboard clipboard, TestUnitView testRunner, ToolBar toolBar) {
+ Assert.isNotNull(clipboard);
+
+ // fill the failure trace viewer toolbar
+ ToolBarManager failureToolBarmanager= new ToolBarManager(toolBar);
+ // TODO Add the EnableStackFilterAction back
+ //failureToolBarmanager.add(new EnableStackFilterAction(this));
+ fCompareAction = new CompareResultsAction(this);
+ fCompareAction.setEnabled(false);
+ failureToolBarmanager.add(fCompareAction);
+ failureToolBarmanager.update(true);
+
+ fTable= new Table(parent, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
+ fClipboard= clipboard;
+
+ OpenStrategy handler = new OpenStrategy(fTable);
+ handler.addOpenListener(new IOpenEventListener() {
+ public void handleOpen(SelectionEvent e) {
+ if (fTable.getSelectionIndex() == 0 && fFailure.isComparisonFailure()) {
+ (new CompareResultsAction(FailureTrace.this)).run();
+ }
+ if (fTable.getSelection().length != 0) {
+ Action a = createOpenEditorAction(getSelectedText());
+ if (a != null)
+ a.run();
+ }
+ }
+ });
+
+ initMenu();
+ fTable.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(SelectionEvent e) {}
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ new StackTraceLine(getSelectedText()).openEditor();
+ }
+ });
+
+ parent.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ disposeIcons();
+ }
+ });
+ }
+
+ private void initMenu() {
+ MenuManager menuMgr= new MenuManager();
+ menuMgr.setRemoveAllWhenShown(true);
+ menuMgr.addMenuListener(this);
+ Menu menu= menuMgr.createContextMenu(fTable);
+ fTable.setMenu(menu);
+ }
+
+ public void menuAboutToShow(IMenuManager manager) {
+ if (fTable.getSelectionCount() > 0) {
+ Action a= createOpenEditorAction(getSelectedText());
+ if (a != null)
+ manager.add(a);
+ manager.add(new CopyTraceAction(FailureTrace.this, fClipboard));
+ }
+ // fix for bug 68058
+ if (fFailure != null && fFailure.isComparisonFailure())
+ manager.add(new CompareResultsAction(FailureTrace.this));
+ }
+
+ public String getTrace() {
+ return fInputTrace;
+ }
+
+ private String getSelectedText() {
+ return fTable.getSelection()[0].getText();
+ }
+
+ private Action createOpenEditorAction(String traceLine) {
+ return new OpenEditorAction(new StackTraceLine(traceLine));
+ }
+
+ private void disposeIcons(){
+ if (fExceptionIcon != null && !fExceptionIcon.isDisposed())
+ fExceptionIcon.dispose();
+ if (fStackIcon != null && !fStackIcon.isDisposed())
+ fStackIcon.dispose();
+ }
+
+ /**
+ * Returns the composite used to present the trace
+ */
+ public Composite getComposite(){
+ return fTable;
+ }
+
+ /**
+ * Refresh the table from the the trace.
+ */
+ public void refresh() {
+ updateTable(fInputTrace);
+ }
+
+ /**
+ * Shows a TestFailure
+ * @param failure the failed test
+ */
+ public void showFailure(TestRunInfo failure) {
+ fFailure= failure;
+ String trace= ""; //$NON-NLS-1$
+ updateEnablement(failure);
+ if (failure != null)
+ trace= failure.getTrace();
+ if (fInputTrace == trace)
+ return;
+ fInputTrace= trace;
+ updateTable(trace);
+ }
+
+ public void updateEnablement(TestRunInfo failure) {
+ fCompareAction.setEnabled(failure != null && failure.isComparisonFailure());
+ }
+
+ private void updateTable(String trace) {
+ if(trace == null || trace.trim().equals("")) { //$NON-NLS-1$
+ clear();
+ return;
+ }
+ trace= trace.trim();
+ fTable.setRedraw(false);
+ fTable.removeAll();
+ fillTable(filterStack(trace));
+ fTable.setRedraw(true);
+ }
+
+ private void fillTable(String trace) {
+ StringReader stringReader= new StringReader(trace);
+ BufferedReader bufferedReader= new BufferedReader(stringReader);
+ String line;
+
+ try {
+ // first line contains the thrown exception
+ line= bufferedReader.readLine();
+ if (line == null)
+ return;
+
+ TableItem tableItem= new TableItem(fTable, SWT.NONE);
+ String itemLabel= line.replace('\t', ' ');
+ tableItem.setText(itemLabel);
+ tableItem.setImage(fExceptionIcon);
+
+ // the stack frames of the trace
+ while ((line= bufferedReader.readLine()) != null) {
+ itemLabel= line.replace('\t', ' ');
+ tableItem= new TableItem(fTable, SWT.NONE);
+ // heuristic for detecting a stack frame - works for JDK
+ if ((itemLabel.indexOf(" at ") >= 0)) { //$NON-NLS-1$
+ tableItem.setImage(fStackIcon);
+ }
+ tableItem.setText(itemLabel);
+ }
+ } catch (IOException e) {
+ TableItem tableItem= new TableItem(fTable, SWT.NONE);
+ tableItem.setText(trace);
+ }
+ }
+
+ /**
+ * Shows other information than a stack trace.
+ * @param text the informational message to be shown
+ */
+ public void setInformation(String text) {
+ clear();
+ TableItem tableItem= new TableItem(fTable, SWT.NONE);
+ tableItem.setText(text);
+ }
+
+ /**
+ * Clears the non-stack trace info
+ */
+ public void clear() {
+ fTable.removeAll();
+ fInputTrace= null;
+ }
+
+ private String filterStack(String stackTrace) {
+ return stackTrace;
+ // TODO Filter the stack trace
+ }
+
+
+ public TestRunInfo getFailedTest() {
+ return fFailure;
+ }
+
+ public Shell getShell() {
+ return fTable.getShell();
+ }
+
+ private class OpenEditorAction extends Action {
+ private final StackTraceLine trace;
+
+ public OpenEditorAction(StackTraceLine trace) {
+ super(TestUnitMessages.getString("OpenEditor.action.label"));
+ this.trace = trace;
+ }
+
+ public void run() {
+ trace.openEditor();
+ }
+ }
+}
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/ITestRunListener2.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/ITestRunListener2.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/ITestRunListener2.java 2006-12-15 15:39:49 UTC (rev 1711)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.testunit.ui;
+
+import org.rubypeople.rdt.testunit.ITestRunListener;
+
+/**
+ * Extends ITestRunListener with a call back to trace the test contents
+ */
+public interface ITestRunListener2 extends ITestRunListener {
+
+ /**
+ * Information about a member of the test suite that is about to be run. The
+ * format of the string is:
+ *
+ * <pre>
+ *
+ * "testId","testName","isSuite","testcount"
+ *
+ * testId: a unique id for the test
+ * testName: the name of the test
+ * isSuite: true or false depending on whether the test is a suite
+ * testCount: an integer indicating the number of tests
+ *
+ * Example: "324968,testPass(junit.tests.MyTest),false,1"
+ *
+ * </pre>
+ *
+ * @param description
+ * a string describing a tree entry
+ */
+ public void testTreeEntry(String description);
+}
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/ITestRunListener3.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/ITestRunListener3.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/ITestRunListener3.java 2006-12-15 15:39:49 UTC (rev 1711)
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.testunit.ui;
+
+
+/**
+ * Extends ITestRunListener2 with a call back to trace the test contents
+ */
+public interface ITestRunListener3 extends ITestRunListener2 {
+
+ public void testFailed(int status, String testId, String testName, String trace, String expected, String actual);
+
+ public void testReran(String testId, String className, String testName, int statusCode, String trace, String expectedResult, String actualResult);
+}
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenEditorAtLineAction.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenEditorAtLineAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenEditorAtLineAction.java 2006-12-15 15:39:49 UTC (rev 1711)
@@ -0,0 +1,170 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Sebastian Davids: sd...@gm... bug 37333 Failure Trace cannot
+ * navigate to non-public class in CU throwing Exception
+
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.testunit.ui;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.ISourceLocator;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.internal.debug.ui.RubySourceLocator;
+
+/**
+ * Open a test in the Ruby editor and reveal a given line
+ */
+public class OpenEditorAtLineAction extends Action {
+
+ private int fLineNumber;
+ private String fileName;
+ private TestUnitView fTestRunner;
+
+ /**
+ * Constructor for OpenEditorAtLineAction.
+ */
+ public OpenEditorAtLineAction(TestUnitView testRunner, String fileName, int line) {
+ super(TestUnitMessages.getString("OpenEditorAction.action.label"));
+ // TODO Uncomment and fix!
+ // WorkbenchHelp.setHelp(this,
+ // IJUnitHelpContextIds.OPENEDITORATLINE_ACTION);
+ fLineNumber = line;
+ fTestRunner = testRunner;
+ this.fileName = fileName;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.rubypeople.rdt.internal.testunit.ui.OpenEditorAction#run()
+ */
+ public void run() {
+ try {
+ IEditorInput input = getInput();
+ if (input == null) {
+ if (TestunitPlugin.getDefault().isDebugging()) {
+ System.out
+ .println("Could not create editor input for stack trace: " + fileName);
+ }
+ // wrongly detected stack trace
+ return;
+ }
+ IEditorPart editorPart = getEditorPart(input);
+ setEditorToLine(editorPart, input);
+ } catch (CoreException e) {
+ TestunitPlugin.log(new Status(IStatus.ERROR, TestunitPlugin.PLUGIN_ID, 0,
+ "Could not open editor or set line in editor." + fileName, e));
+ }
+ }
+
+ /**
+ * @param input
+ * @return
+ * @throws PartInitException
+ */
+ private IEditorPart getEditorPart(IEditorInput input) throws PartInitException {
+ ISourceLocator sourceLocator = getSourceLocator();
+ if (!(sourceLocator instanceof RubySourceLocator)) { return null; }
+ RubySourceLocator rubySourceLocator = (RubySourceLocator) sourceLocator;
+
+ Object sourceElement = rubySourceLocator.getSourceElement(fileName);
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(
+ input, rubySourceLocator.getEditorId(input, sourceElement));
+ }
+
+ private void setEditorToLine(IEditorPart pEditorPart, IEditorInput pInput) throws CoreException {
+ if (!(pEditorPart instanceof ITextEditor)) { return; }
+ // documents start at 0
+ if (fLineNumber > 0) {
+ fLineNumber--;
+ }
+ if (fLineNumber == 0) { return; }
+ ITextEditor textEditor = (ITextEditor) pEditorPart;
+ IDocumentProvider provider = textEditor.getDocumentProvider();
+ provider.connect(pInput);
+ IDocument document = provider.getDocument(pInput);
+ try {
+ IRegion line = document.getLineInformation(fLineNumber);
+ textEditor.selectAndReveal(line.getOffset(), line.getLength());
+ } catch (BadLocationException e) {
+ if (TestunitPlugin.getDefault().isDebugging()) {
+ System.out.println("Could not set editor to line: " + fLineNumber);
+ }
+ }
+ provider.disconnect(pInput);
+ }
+
+ protected void reveal(ITextEditor textEditor) {
+ if (fLineNumber >= 0) {
+ try {
+ IDocument document = textEditor.getDocumentProvider().getDocument(
+ textEditor.getEditorInput());
+ textEditor.selectAndReveal(document.getLineOffset(fLineNumber - 1), document
+ .getLineLength(fLineNumber - 1));
+ } catch (BadLocationException x) {
+ // marker refers to invalid text position -> do nothing
+ }
+ }
+ }
+
+ protected IRubyElement findElement(IRubyProject project, String className) throws CoreException {
+ return project.findType(className);
+ }
+
+ public boolean isEnabled() {
+ return getInput() != null;
+ }
+
+ /**
+ * @return
+ */
+ private IEditorInput getInput() {
+ ISourceLocator sourceLocator = getSourceLocator();
+ if (!(sourceLocator instanceof RubySourceLocator)) { return null; }
+ RubySourceLocator rubySourceLocator = (RubySourceLocator) sourceLocator;
+
+ Object sourceElement = rubySourceLocator.getSourceElement(fileName);
+ IEditorInput input = rubySourceLocator.getEditorInput(sourceElement);
+ return input;
+ }
+
+ /**
+ * @return
+ */
+ private ISourceLocator getSourceLocator() {
+ ILaunch launch = fTestRunner.getLastLaunch();
+ if (launch == null) { return null; }
+ return launch.getSourceLocator();
+ }
+
+ protected Shell getShell() {
+ return fTestRunner.getSite().getShell();
+ }
+
+ protected IRubyProject getLaunchedProject() {
+ return fTestRunner.getLaunchedProject();
+ }
+
+}
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenLocationAction.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenLocationAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenLocationAction.java 2006-12-15 15:39:49 UTC (rev 1711)
@@ -0,0 +1,23 @@
+package org.rubypeople.rdt.internal.testunit.ui;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.rubypeople.rdt.internal.core.symbols.Location;
+import org.rubypeople.rdt.internal.ui.util.PositionBasedEditorOpener;
+
+
+public class OpenLocationAction extends Action implements IAction {
+
+ private final Location location;
+
+ public OpenLocationAction(Location location) {
+ super(location.getFilename());
+ this.location = location;
+ }
+
+ public void run() {
+ new PositionBasedEditorOpener(location.getFilename(), location.getPosition()).open();
+ }
+
+
+}
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenSymbolAction.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenSymbolAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenSymbolAction.java 2006-12-15 15:39:49 UTC (rev 1711)
@@ -0,0 +1,99 @@
+package org.rubypeople.rdt.internal.testunit.ui;
+
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Shell;
+import org.rubypeople.rdt.internal.core.symbols.ClassSymbol;
+import org.rubypeople.rdt.internal.core.symbols.ISymbolFinder;
+import org.rubypeople.rdt.internal.core.symbols.Location;
+import org.rubypeople.rdt.internal.core.symbols.MethodSymbol;
+import org.rubypeople.rdt.internal.core.symbols.Symbol;
+import org.rubypeople.rdt.internal.ui.RubyPluginImages;
+import org.rubypeople.rdt.internal.ui.dialogs.ElementListSelectionDialog;
+import org.rubypeople.rdt.internal.ui.util.PositionBasedEditorOpener;
+
+public class OpenSymbolAction extends Action implements IAction {
+
+ private final Symbol symbol;
+ private final ISymbolFinder finder;
+ private final Shell shell;
+ private String dialogTitle;
+
+ public static IAction forClass(String className, ISymbolFinder finder, Shell shell) {
+ return new OpenSymbolAction(new ClassSymbol(className), finder, shell, "Open Class");
+ }
+
+ public static IAction forMethod(String className, String testMethod,
+ ISymbolFinder finder, Shell shell) {
+ return new OpenSymbolAction(new MethodSymbol(className, testMethod), finder, shell, "Open Method");
+ }
+
+ public OpenSymbolAction(Symbol symbol, ISymbolFinder finder, Shell shell, String title) {
+ super(TestUnitMessages.getString("OpenEditor.action.label"));
+ this.shell = shell;
+ this.symbol = symbol;
+ this.finder = finder;
+ this.dialogTitle = title;
+ }
+
+
+ public void run() {
+ Set locations = finder.find(symbol);
+ if (locations.size() == 0)
+ return;
+
+ Location location;
+ if (locations.size() == 1) {
+ location = (Location) locations.iterator().next();
+ } else {
+ ElementListSelectionDialog selectionDialog
+ = new ElementListSelectionDialog(shell, new LocationLabel());
+ selectionDialog.setElements(locations.toArray());
+ selectionDialog.setMessage("Select a location");
+ selectionDialog.setTitle(dialogTitle);
+ selectionDialog.open();
+ if (selectionDialog.getReturnCode() == SWT.CANCEL)
+ return;
+ location= (Location) selectionDialog.getResult()[0];
+ }
+ PositionBasedEditorOpener editorOpener
+ = new PositionBasedEditorOpener(location.getFilename(),
+ location.getPosition());
+ editorOpener.open();
+ }
+
+
+ private final class LocationLabel implements ILabelProvider {
+ public Image getImage(Object element) {
+ return RubyPluginImages.get(RubyPluginImages.IMG_CTOOLS_RUBY_PAGE);
+ }
+
+ public String getText(Object element) {
+ Location location = (Location) element;
+ IFile sourceFile = location.getSourceFile();
+ return sourceFile.getName() + ":" + location.getPosition().getStartLine() + " - " + sourceFile.getFullPath().removeLastSegments(1);
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ }
+ }
+
+
+}
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/RemoteTestRunnerClient.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/RemoteTestRunnerClient.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/RemoteTestRunnerClient.java 2006-12-15 15:39:49 UTC (rev 1711)
@@ -0,0 +1,534 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Julien Ruaux: jr...@oc...
+ * Vincent Massol: vm...@oc...
+ ******************************************************************************/
+package org.rubypeople.rdt.internal.testunit.ui;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.SafeRunner;
+import org.rubypeople.rdt.internal.testunit.runner.MessageIds;
+import org.rubypeople.rdt.testunit.ITestRunListener;
+
+/**
+ * The client side of the RemoteTestRunner. Handles the marshaling of the
+ * different messages.
+ */
+public class RemoteTestRunnerClient {
+
+ public abstract class ListenerSafeRunnable implements ISafeRunnable {
+
+ public void handleException(Throwable exception) {
+ TestunitPlugin.log(exception);
+ }
+ }
+
+ /**
+ * A simple state machine to process requests from the RemoteTestRunner
+ */
+ abstract class ProcessingState {
+
+ abstract ProcessingState readMessage(String message);
+ }
+
+ class DefaultProcessingState extends ProcessingState {
+
+ ProcessingState readMessage(String message) {
+ if (message.startsWith(MessageIds.TRACE_START)) {
+ fFailedTrace = ""; //$NON-NLS-1$
+ return fTraceState;
+ }
+ if (message.startsWith(MessageIds.EXPECTED_START)) {
+ fExpectedResult = null;
+ return fExpectedState;
+ }
+ if (message.startsWith(MessageIds.ACTUAL_START)) {
+ fActualResult = null;
+ return fActualState;
+ }
+ if (message.startsWith(MessageIds.RTRACE_START)) {
+ fFailedRerunTrace = ""; //$NON-NLS-1$
+ return fRerunState;
+ }
+ String arg = message.substring(MessageIds.MSG_HEADER_LENGTH);
+ if (message.startsWith(MessageIds.TEST_RUN_START)) {
+ // version < 2 format: count
+ // version >= 2 format: count+" "+version
+ int count = 0;
+ int v = arg.indexOf(' ');
+ if (v == -1) {
+ fVersion = "v1"; //$NON-NLS-1$
+ count = Integer.parseInt(arg);
+ } else {
+ fVersion = arg.substring(v + 1);
+ String sc = arg.substring(0, v);
+ count = Integer.parseInt(sc);
+ }
+ notifyTestRunStarted(count);
+ return this;
+ }
+ if (message.startsWith(MessageIds.TEST_START)) {
+ notifyTestStarted(arg);
+ return this;
+ }
+ if (message.startsWith(MessageIds.TEST_END)) {
+ notifyTestEnded(arg);
+ return this;
+ }
+ if (message.startsWith(MessageIds.TEST_ERROR)) {
+ extractFailure(arg, ITestRunListener.STATUS_ERROR);
+ return this;
+ }
+ if (message.startsWith(MessageIds.TEST_FAILED)) {
+ extractFailure(arg, ITestRunListener.STATUS_FAILURE);
+ return this;
+ }
+ if (message.startsWith(MessageIds.TEST_RUN_END)) {
+ long elapsedTime = Long.parseLong(arg);
+ testRunEnded(elapsedTime);
+ return this;
+ }
+ if (message.startsWith(MessageIds.TEST_STOPPED)) {
+ long elapsedTime = Long.parseLong(arg);
+ notifyTestRunStopped(elapsedTime);
+ shutDown();
+ return this;
+ }
+ if (message.startsWith(MessageIds.TEST_TREE)) {
+ notifyTestTreeEntry(arg);
+ return this;
+ }
+ if (message.startsWith(MessageIds.TEST_RERAN)) {
+ if (hasTestId())
+ scanReranMessage(arg);
+ else
+ scanOldReranMessage(arg);
+ return this;
+ }
+ return this;
+ }
+ }
+
+ class TraceProcessingState extends ProcessingState {
+
+ ProcessingState readMessage(String message) {
+ if (message.startsWith(MessageIds.TRACE_END)) {
+ notifyTestFailed();
+ fFailedTrace = ""; //$NON-NLS-1$
+ fExpectedResult = null;
+ fActualResult = null;
+ return fDefaultState;
+ }
+ fFailedTrace += message + '\n';
+ return this;
+ }
+ }
+
+ class ExpectedProcessingState extends ProcessingState {
+
+ ProcessingState readMessage(String message) {
+ if (message.startsWith(MessageIds.EXPECTED_END)) return fDefaultState;
+ if (fExpectedResult == null)
+ fExpectedResult = message + '\n';
+ else
+ fExpectedResult += message + '\n';
+ return this;
+ }
+ }
+
+ class ActualProcessingState extends ProcessingState {
+
+ ProcessingState readMessage(String message) {
+ if (message.startsWith(MessageIds.ACTUAL_END)) return fDefaultState;
+ if (fActualResult == null)
+ fActualResult = message + '\n';
+ else
+ fActualResult += message + '\n';
+ return this;
+ }
+ }
+
+ class RerunTraceProcessingState extends ProcessingState {
+
+ ProcessingState readMessage(String message) {
+ if (message.startsWith(MessageIds.RTRACE_END)) return fDefaultState;
+ fFailedRerunTrace += message + '\n';
+ return this;
+ }
+ }
+
+ ProcessingState fDefaultState = new DefaultProcessingState();
+ ProcessingState fTraceState = new TraceProcessingState();
+ ProcessingState fExpectedState = new ExpectedProcessingState();
+ ProcessingState fActualState = new ActualProcessingState();
+ ProcessingState fRerunState = new RerunTraceProcessingState();
+ ProcessingState fCurrentState = fDefaultState;
+
+ /**
+ * An array of listeners that are informed about test events.
+ */
+ private ITestRunListener[] fListeners;
+
+ /**
+ * The server socket
+ */
+ private ServerSocket fServerSocket;
+ private Socket fSocket;
+ private int fPort = -1;
+ private PrintWriter fWriter;
+ private BufferedReader fBufferedReader;
+ /**
+ * The protocol version
+ */
+ private String fVersion;
+ /**
+ * The failed test that is currently reported from the RemoteTestRunner
+ */
+ private String fFailedTest;
+ /**
+ * The Id of the failed test
+ */
+ private String fFailedTestId;
+ /**
+ * The failed trace that is currently reported from the RemoteTestRunner
+ */
+ private String fFailedTrace;
+ /**
+ * The expected test result
+ */
+ private String fExpectedResult;
+ /**
+ * The actual test result
+ */
+ private String fActualResult;
+ /**
+ * The failed trace of a reran test
+ */
+ private String fFailedRerunTrace;
+ /**
+ * The kind of failure of the test that is currently reported as failed
+ */
+ private int fFailureKind;
+
+ private boolean fDebug = false;
+
+ /**
+ * Reads the message stream from the RemoteTestRunner
+ */
+ private class ServerConnection extends Thread {
+
+ int fServerPort;
+
+ public ServerConnection(int port) {
+ super("ServerConnection"); //$NON-NLS-1$
+ fServerPort = port;
+ }
+
+ public void run() {
+ try {
+ if (fDebug) System.out.println("Creating server socket " + fServerPort); //$NON-NLS-1$
+ fServerSocket = new ServerSocket(fServerPort);
+ fSocket = fServerSocket.accept();
+ try {
+ fBufferedReader = new BufferedReader(new InputStreamReader(fSocket.getInputStream(), "UTF-8")); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e) {
+ fBufferedReader = new BufferedReader(new InputStreamReader(fSocket.getInputStream()));
+ }
+ try {
+ fWriter = new PrintWriter(new OutputStreamWriter(fSocket.getOutputStream(), "UTF-8"), true); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e1) {
+ fWriter = new PrintWriter(new OutputStreamWriter(fSocket.getOutputStream()), true);
+ }
+ String message;
+ while (fBufferedReader != null && (message = readMessage(fBufferedReader)) != null)
+ receiveMessage(message);
+ } catch (SocketException e) {
+ notifyTestRunTerminated();
+ } catch (IOException e) {
+ System.out.println(e);
+ // fall through
+ }
+ shutDown();
+ }
+ }
+
+ /**
+ * Start listening to a test run. Start a server connection that the
+ * RemoteTestRunner can connect to.
+ */
+ public synchronized void startListening(ITestRunListener[] listeners, int port) {
+ fListeners = listeners;
+ fPort = port;
+ ServerConnection connection = new ServerConnection(port);
+ connection.start();
+ }
+
+ /**
+ * Requests to stop the remote test run.
+ */
+ public synchronized void stopTest() {
+ if (isRunning()) {
+ fWriter.println(MessageIds.TEST_STOP);
+ fWriter.flush();
+ }
+ }
+
+ private synchronized void shutDown() {
+ if (fDebug) System.out.println("shutdown " + fPort); //$NON-NLS-1$
+
+ if (fWriter != null) {
+ fWriter.close();
+ fWriter = null;
+ }
+ try {
+ if (fBufferedReader != null) {
+ fBufferedReader.close();
+ fBufferedReader = null;
+ }
+ } catch (IOException e) {}
+ try {
+ if (fSocket != null) {
+ fSocket.close();
+ fSocket = null;
+ }
+ } catch (IOException e) {}
+ try {
+ if (fServerSocket != null) {
+ fServerSocket.close();
+ fServerSocket = null;
+ }
+ } catch (IOException e) {}
+ }
+
+ public boolean isRunning() {
+ return fSocket != null;
+ }
+
+ private String readMessage(BufferedReader in) throws IOException {
+ return in.readLine();
+ }
+
+ private void receiveMessage(String message) {
+ fCurrentState = fCurrentState.readMessage(message);
+ }
+
+ private void scanOldReranMessage(String arg) {
+ // OLD V1 format
+ // format: className" "testName" "status
+ // status: FAILURE, ERROR, OK
+ int c = arg.indexOf(" "); //$NON-NLS-1$
+ int t = arg.indexOf(" ", c + 1); //$NON-NLS-1$
+ String className = arg.substring(0, c);
+ String testName = arg.substring(c + 1, t);
+ String status = arg.substring(t + 1);
+ int statusCode = ITestRunListener.STATUS_OK;
+ if (status.equals("FAILURE")) //$NON-NLS-1$
+ statusCode = ITestRunListener.STATUS_FAILURE;
+ else if (status.equals("ERROR")) //$NON-NLS-1$
+ statusCode = ITestRunListener.STATUS_ERROR;
+
+ String trace = ""; //$NON-NLS-1$
+ if (statusCode != ITestRunListener.STATUS_OK) trace = fFailedRerunTrace;
+ // assumption a rerun trace was sent before
+ notifyTestReran(className + testName, className, testName, statusCode, trace);
+ }
+
+ private void scanReranMessage(String arg) {
+ // format: testId" "className" "testName" "status
+ // status: FAILURE, ERROR, OK
+ int i = arg.indexOf(' ');
+ int c = arg.indexOf(' ', i + 1); //$NON-NLS-1$
+ int t = arg.indexOf(' ', c + 1); //$NON-NLS-1$
+ String testId = arg.substring(0, i);
+ String className = arg.substring(i + 1, c);
+ String testName = arg.substring(c + 1, t);
+ String status = arg.substring(t + 1);
+ int statusCode = ITestRunListener.STATUS_OK;
+ if (status.equals("FAILURE")) //$NON-NLS-1$
+ statusCode = ITestRunListener.STATUS_FAILURE;
+ else if (status.equals("ERROR")) //$NON-NLS-1$
+ statusCode = ITestRunListener.STATUS_ERROR;
+
+ String trace = ""; //$NON-NLS-1$
+ if (statusCode != ITestRunListener.STATUS_OK) trace = fFailedRerunTrace;
+ // assumption a rerun trace was sent before
+ notifyTestReran(testId, className, testName, statusCode, trace);
+ }
+
+ private void extractFailure(String arg, int status) {
+ String s[] = extractTestId(arg);
+ fFailedTestId = s[0];
+ fFailedTest = s[1];
+ fFailureKind = status;
+ }
+
+ /**
+ * Returns an array with two elements. The first one is the testId, the
+ * second one the testName.
+ */
+ String[] extractTestId(String arg) {
+ String[] result = new String[2];
+ if (!hasTestId()) {
+ result[0] = arg; // use the test name as the test Id
+ result[1] = arg;
+ return result;
+ }
+ int i = arg.indexOf(',');
+ result[0] = arg.substring(0, i);
+ result[1] = arg.substring(i + 1, arg.length());
+ return result;
+ }
+
+ private boolean hasTestId() {
+ if (fVersion == null) // TODO fix me
+ return true;
+ return fVersion.equals("v2"); //$NON-NLS-1$
+ }
+
+ private void notifyTestReran(final String testId, final String className, final String testName, final int statusCode, final String trace) {
+ for (int i = 0; i < fListeners.length; i++) {
+ final ITestRunListener listener = fListeners[i];
+ SafeRunner.run(new ListenerSafeRunnable() {
+
+ public void run() {
+ if (listener instance...
[truncated message content] |
|
From: <caw...@us...> - 2006-12-15 15:38:45
|
Revision: 1710
http://svn.sourceforge.net/rubyeclipse/?rev=1710&view=rev
Author: cawilliams
Date: 2006-12-15 07:38:43 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
Removed Paths:
-------------
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/views/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-15 15:38:21
|
Revision: 1709
http://svn.sourceforge.net/rubyeclipse/?rev=1709&view=rev
Author: cawilliams
Date: 2006-12-15 07:38:20 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
Added Paths:
-----------
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-15 15:38:07
|
Revision: 1708
http://svn.sourceforge.net/rubyeclipse/?rev=1708&view=rev
Author: cawilliams
Date: 2006-12-15 07:38:02 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
Added Paths:
-----------
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/runner/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-15 15:37:46
|
Revision: 1707
http://svn.sourceforge.net/rubyeclipse/?rev=1707&view=rev
Author: cawilliams
Date: 2006-12-15 07:37:44 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
Added Paths:
-----------
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/launcher/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-15 15:32:51
|
Revision: 1706
http://svn.sourceforge.net/rubyeclipse/?rev=1706&view=rev
Author: cawilliams
Date: 2006-12-15 07:32:50 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
all sorts of plumbing for new test case wizard, new SourceFolder in IRubyElement hierarchy
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/.project
trunk/org.rubypeople.rdt.ui/plugin.properties
trunk/org.rubypeople.rdt.ui/plugin.xml
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/CodeFormatterUtil.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyModelUtil.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPluginImages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.properties
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PropertyAndPreferencePage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/viewsupport/RubyElementImageProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/AbstractOpenWizardAction.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/dialogfields/ListDialogField.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/StandardRubyElementContentProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/RubyTypeSelectionDialog.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/icons/full/obj16/fldr_obj.gif
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/codemanipulation/
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/codemanipulation/StubUtility.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/ProjectSelectionDialog.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/TypedElementSelectionValidator.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/TypedViewerFilter.java
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
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/RubyModuleSelectionDialog.java
Removed Paths:
-------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.properties
Property Changed:
----------------
trunk/org.rubypeople.rdt.ui/icons/full/obj16/
Modified: trunk/org.rubypeople.rdt.ui/.project
===================================================================
(Binary files differ)
Property changes on: trunk/org.rubypeople.rdt.ui/icons/full/obj16
___________________________________________________________________
Name: svn:ignore
- Thumbs.db
+ Thumbs.db
Added: trunk/org.rubypeople.rdt.ui/icons/full/obj16/fldr_obj.gif
===================================================================
(Binary files differ)
Property changes on: trunk/org.rubypeople.rdt.ui/icons/full/obj16/fldr_obj.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/org.rubypeople.rdt.ui/plugin.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.properties 2006-12-15 15:31:22 UTC (rev 1705)
+++ trunk/org.rubypeople.rdt.ui/plugin.properties 2006-12-15 15:32:50 UTC (rev 1706)
@@ -31,7 +31,7 @@
viewCategoryName=Ruby
appearancePrefName=Appearance
-problemSeveritiesPrefName=Errors/Warnings
+problemSeveritiesPageName=Errors/Warnings
preferenceKeywords.general=Ruby resources call type hierarchy refactoring search
preferenceKeywords.appearance=Ruby appearance resources browsing
Modified: trunk/org.rubypeople.rdt.ui/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.xml 2006-12-15 15:31:22 UTC (rev 1705)
+++ trunk/org.rubypeople.rdt.ui/plugin.xml 2006-12-15 15:32:50 UTC (rev 1706)
@@ -285,19 +285,9 @@
</enabledWhen>
</page>
<page
- name="%PropertyPageRubyProject.name"
- class="org.rubypeople.rdt.internal.ui.RubyProjectPropertyPage"
- id="org.rubypeople.rdt.ui.PropertyPageRubyProject">
- <enabledWhen>
- <adapt type="org.eclipse.core.resources.IProject">
- <test property="org.eclipse.core.resources.projectNature" value="org.rubypeople.rdt.core.rubynature"/>
- </adapt>
- </enabledWhen>
- </page>
- <page
name="%problemSeveritiesPageName"
class="org.rubypeople.rdt.internal.ui.preferences.ProblemSeveritiesPreferencePage"
- category="org.rubypeople.rdt.ui.propertyPages.CompliancePreferencePage"
+ category="org.rubypeople.rdt.ui.PropertyPageRubyProject"
id="org.rubypeople.rdt.ui.propertyPages.ProblemSeveritiesPreferencePage">
<enabledWhen>
<adapt type="org.eclipse.core.resources.IProject">
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/codemanipulation/StubUtility.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/codemanipulation/StubUtility.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/codemanipulation/StubUtility.java 2006-12-15 15:32:50 UTC (rev 1706)
@@ -0,0 +1,48 @@
+package org.rubypeople.rdt.internal.corext.codemanipulation;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.rubypeople.rdt.core.IRubyProject;
+
+public class StubUtility {
+
+ /**
+ * Returns the line delimiter which is used in the specified project.
+ *
+ * @param project the ruby project, or <code>null</code>
+ * @return the used line delimiter
+ */
+ public static String getLineDelimiterUsed(IRubyProject project) {
+ return getProjectLineDelimiter(project);
+ }
+
+ private static String getProjectLineDelimiter(IRubyProject javaProject) {
+ IProject project= null;
+ if (javaProject != null)
+ project= javaProject.getProject();
+
+ String lineDelimiter= getLineDelimiterPreference(project);
+ if (lineDelimiter != null)
+ return lineDelimiter;
+
+ return System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public static String getLineDelimiterPreference(IProject project) {
+ IScopeContext[] scopeContext;
+ if (project != null) {
+ // project preference
+ scopeContext= new IScopeContext[] { new ProjectScope(project) };
+ String lineDelimiter= Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);
+ if (lineDelimiter != null)
+ return lineDelimiter;
+ }
+ // workspace preference
+ scopeContext= new IScopeContext[] { new InstanceScope() };
+ String platformDefault= System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ return Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, platformDefault, scopeContext);
+ }
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/CodeFormatterUtil.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/CodeFormatterUtil.java 2006-12-15 15:31:22 UTC (rev 1705)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/CodeFormatterUtil.java 2006-12-15 15:32:50 UTC (rev 1706)
@@ -2,168 +2,274 @@
import java.util.Map;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DefaultPositionUpdater;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.Position;
import org.eclipse.text.edits.TextEdit;
import org.rubypeople.rdt.core.IRubyProject;
import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.ToolFactory;
import org.rubypeople.rdt.core.formatter.DefaultCodeFormatterConstants;
import org.rubypeople.rdt.internal.corext.Assert;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
public class CodeFormatterUtil {
- /**
- * Creates edits that describe how to format the given string. Returns
- * <code>null</code> if the code could not be formatted for the given
- * kind.
- *
- * @throws IllegalArgumentException
- * If the offset and length are not inside the string, a
- * IllegalArgumentException is thrown.
- */
- public static TextEdit format2(int kind, String string, int offset, int length,
- int indentationLevel, String lineSeparator, Map options) {
- if (offset < 0 || length < 0 || offset + length > string.length()) { throw new IllegalArgumentException(
- "offset or length outside of string. offset: " + offset + ", length: " + length + ", string size: " + string.length()); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
- }
- return ToolFactory.createCodeFormatter(options).format(kind, string, offset, length,
- indentationLevel, lineSeparator);
- }
+ /**
+ * Creates edits that describe how to format the given string. Returns
+ * <code>null</code> if the code could not be formatted for the given
+ * kind.
+ *
+ * @throws IllegalArgumentException
+ * If the offset and length are not inside the string, a
+ * IllegalArgumentException is thrown.
+ */
+ public static TextEdit format2(int kind, String string, int offset,
+ int length, int indentationLevel, String lineSeparator, Map options) {
+ if (offset < 0 || length < 0 || offset + length > string.length()) {
+ throw new IllegalArgumentException(
+ "offset or length outside of string. offset: " + offset + ", length: " + length + ", string size: " + string.length()); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ }
+ return ToolFactory.createCodeFormatter(options).format(kind, string,
+ offset, length, indentationLevel, lineSeparator);
+ }
- /**
- * Returns the current indent width.
- *
- * @param project
- * the project where the source is used or <code>null</code> if
- * the project is unknown and the workspace default should be
- * used
- * @return the indent width
- * @since 0.8.0
- */
- public static int getIndentWidth(IRubyProject project) {
- String key;
- if (DefaultCodeFormatterConstants.MIXED.equals(getCoreOption(project,
- DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR)))
- key = DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE;
- else
- key = DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE;
+ /**
+ * Returns the current indent width.
+ *
+ * @param project
+ * the project where the source is used or <code>null</code> if
+ * the project is unknown and the workspace default should be
+ * used
+ * @return the indent width
+ * @since 0.8.0
+ */
+ public static int getIndentWidth(IRubyProject project) {
+ String key;
+ if (DefaultCodeFormatterConstants.MIXED.equals(getCoreOption(project,
+ DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR)))
+ key = DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE;
+ else
+ key = DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE;
- return getCoreOption(project, key, 4);
- }
+ return getCoreOption(project, key, 4);
+ }
- /**
- * Gets the current tab width.
- *
- * @param project
- * The project where the source is used, used for project
- * specific options or <code>null</code> if the project is
- * unknown and the workspace default should be used
- * @return The tab width
- */
- public static int getTabWidth(IRubyProject project) {
- /*
- * If the tab-char is SPACE, FORMATTER_INDENTATION_SIZE is not used by
- * the core formatter. We piggy back the visual tab length setting in
- * that preference in that case.
- */
- String key;
- if (RubyCore.SPACE.equals(getCoreOption(project,
- DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR)))
- key = DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE;
- else
- key = DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE;
+ /**
+ * Gets the current tab width.
+ *
+ * @param project
+ * The project where the source is used, used for project
+ * specific options or <code>null</code> if the project is
+ * unknown and the workspace default should be used
+ * @return The tab width
+ */
+ public static int getTabWidth(IRubyProject project) {
+ /*
+ * If the tab-char is SPACE, FORMATTER_INDENTATION_SIZE is not used by
+ * the core formatter. We piggy back the visual tab length setting in
+ * that preference in that case.
+ */
+ String key;
+ if (RubyCore.SPACE.equals(getCoreOption(project,
+ DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR)))
+ key = DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE;
+ else
+ key = DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE;
- return getCoreOption(project, key, 4);
- }
+ return getCoreOption(project, key, 4);
+ }
- /**
- * Returns the possibly <code>project</code>-specific core preference
- * defined under <code>key</code>.
- *
- * @param project
- * the project to get the preference from, or <code>null</code>
- * to get the global preference
- * @param key
- * the key of the preference
- * @return the value of the preference
- * @since 0.8.0
- */
- private static String getCoreOption(IRubyProject project, String key) {
- if (project == null) return RubyCore.getOption(key);
- return project.getOption(key, true);
- }
+ /**
+ * Returns the possibly <code>project</code>-specific core preference
+ * defined under <code>key</code>.
+ *
+ * @param project
+ * the project to get the preference from, or <code>null</code>
+ * to get the global preference
+ * @param key
+ * the key of the preference
+ * @return the value of the preference
+ * @since 0.8.0
+ */
+ private static String getCoreOption(IRubyProject project, String key) {
+ if (project == null)
+ return RubyCore.getOption(key);
+ return project.getOption(key, true);
+ }
- /**
- * Returns the possibly <code>project</code>-specific core preference
- * defined under <code>key</code>, or <code>def</code> if the value is
- * not a integer.
- *
- * @param project
- * the project to get the preference from, or <code>null</code>
- * to get the global preference
- * @param key
- * the key of the preference
- * @param def
- * the default value
- * @return the value of the preference
- * @since 0.8.0
- */
- private static int getCoreOption(IRubyProject project, String key, int def) {
- try {
- return Integer.parseInt(getCoreOption(project, key));
- } catch (NumberFormatException e) {
- return def;
- }
- }
+ /**
+ * Returns the possibly <code>project</code>-specific core preference
+ * defined under <code>key</code>, or <code>def</code> if the value is
+ * not a integer.
+ *
+ * @param project
+ * the project to get the preference from, or <code>null</code>
+ * to get the global preference
+ * @param key
+ * the key of the preference
+ * @param def
+ * the default value
+ * @return the value of the preference
+ * @since 0.8.0
+ */
+ private static int getCoreOption(IRubyProject project, String key, int def) {
+ try {
+ return Integer.parseInt(getCoreOption(project, key));
+ } catch (NumberFormatException e) {
+ return def;
+ }
+ }
- /**
- * Creates a string that represents the given number of indentation units.
- * The returned string can contain tabs and/or spaces depending on the core
- * formatter preferences.
- *
- * @param indentationUnits
- * the number of indentation units to generate
- * @param project
- * the project from which to get the formatter settings,
- * <code>null</code> if the workspace default should be used
- * @return the indent string
- */
- public static String createIndentString(int indentationUnits, IRubyProject project) {
- final String tabChar = getCoreOption(project,
- DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR);
- final int tabs, spaces;
- if (RubyCore.SPACE.equals(tabChar)) {
- tabs = 0;
- spaces = indentationUnits * getIndentWidth(project);
- } else if (RubyCore.TAB.equals(tabChar)) {
- // indentWidth == tabWidth
- tabs = indentationUnits;
- spaces = 0;
- } else if (DefaultCodeFormatterConstants.MIXED.equals(tabChar)) {
- int tabWidth = getTabWidth(project);
- int spaceEquivalents = indentationUnits * getIndentWidth(project);
- if (tabWidth > 0) {
- tabs = spaceEquivalents / tabWidth;
- spaces = spaceEquivalents % tabWidth;
- } else {
- tabs = 0;
- spaces = spaceEquivalents;
- }
- } else {
- // new indent type not yet handled
- Assert.isTrue(false);
- return null;
- }
+ /**
+ * Creates a string that represents the given number of indentation units.
+ * The returned string can contain tabs and/or spaces depending on the core
+ * formatter preferences.
+ *
+ * @param indentationUnits
+ * the number of indentation units to generate
+ * @param project
+ * the project from which to get the formatter settings,
+ * <code>null</code> if the workspace default should be used
+ * @return the indent string
+ */
+ public static String createIndentString(int indentationUnits,
+ IRubyProject project) {
+ final String tabChar = getCoreOption(project,
+ DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR);
+ final int tabs, spaces;
+ if (RubyCore.SPACE.equals(tabChar)) {
+ tabs = 0;
+ spaces = indentationUnits * getIndentWidth(project);
+ } else if (RubyCore.TAB.equals(tabChar)) {
+ // indentWidth == tabWidth
+ tabs = indentationUnits;
+ spaces = 0;
+ } else if (DefaultCodeFormatterConstants.MIXED.equals(tabChar)) {
+ int tabWidth = getTabWidth(project);
+ int spaceEquivalents = indentationUnits * getIndentWidth(project);
+ if (tabWidth > 0) {
+ tabs = spaceEquivalents / tabWidth;
+ spaces = spaceEquivalents % tabWidth;
+ } else {
+ tabs = 0;
+ spaces = spaceEquivalents;
+ }
+ } else {
+ // new indent type not yet handled
+ Assert.isTrue(false);
+ return null;
+ }
- StringBuffer buffer = new StringBuffer(tabs + spaces);
- for (int i = 0; i < tabs; i++)
- buffer.append('\t');
- for (int i = 0; i < spaces; i++)
- buffer.append(' ');
- return buffer.toString();
- }
+ StringBuffer buffer = new StringBuffer(tabs + spaces);
+ for (int i = 0; i < tabs; i++)
+ buffer.append('\t');
+ for (int i = 0; i < spaces; i++)
+ buffer.append(' ');
+ return buffer.toString();
+ }
- public static TextEdit format2(int kind, String string, int indentationLevel,
- String lineSeparator, Map options) {
- return format2(kind, string, 0, string.length(), indentationLevel, lineSeparator, options);
- }
+ public static TextEdit format2(int kind, String string,
+ int indentationLevel, String lineSeparator, Map options) {
+ return format2(kind, string, 0, string.length(), indentationLevel,
+ lineSeparator, options);
+ }
+
+ /**
+ * Old API. Consider to use format2 (TextEdit)
+ */
+ public static String format(int kind, String string, int offset,
+ int length, int indentationLevel, int[] positions,
+ String lineSeparator, Map options) {
+ TextEdit edit = format2(kind, string, offset, length, indentationLevel,
+ lineSeparator, options);
+ if (edit == null) {
+ // JavaPlugin.logErrorMessage("formatter failed to format (no edit
+ // returned). Will use unformatted text instead. kind: " + kind + ",
+ // string: " + string); //$NON-NLS-1$ //$NON-NLS-2$
+ return string.substring(offset, offset + length);
+ }
+ String formatted = getOldAPICompatibleResult(string, edit,
+ indentationLevel, positions, lineSeparator, options);
+ return formatted.substring(offset, formatted.length()
+ - (string.length() - (offset + length)));
+ }
+
+ private static String getOldAPICompatibleResult(String string, TextEdit edit, int indentationLevel, int[] positions, String lineSeparator, Map options) {
+ Position[] p= null;
+
+ if (positions != null) {
+ p= new Position[positions.length];
+ for (int i= 0; i < positions.length; i++) {
+ p[i]= new Position(positions[i], 0);
+ }
+ }
+ String res= evaluateFormatterEdit(string, edit, p);
+
+ if (positions != null) {
+ for (int i= 0; i < positions.length; i++) {
+ Position curr= p[i];
+ positions[i]= curr.getOffset();
+ }
+ }
+ return res;
+ }
+ /**
+ * Evaluates the edit on the given string.
+ * @throws IllegalArgumentException If the positions are not inside the string, a
+ * IllegalArgumentException is thrown.
+ */
+ public static String evaluateFormatterEdit(String string, TextEdit edit, Position[] positions) {
+ try {
+ Document doc= createDocument(string, positions);
+ edit.apply(doc, 0);
+ if (positions != null) {
+ for (int i= 0; i < positions.length; i++) {
+ Assert.isTrue(!positions[i].isDeleted, "Position got deleted"); //$NON-NLS-1$
+ }
+ }
+ return doc.get();
+ } catch (BadLocationException e) {
+ RubyPlugin.log(e); // bug in the formatter
+ Assert.isTrue(false, "Formatter created edits with wrong positions: " + e.getMessage()); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ private static Document createDocument(String string, Position[] positions) throws IllegalArgumentException {
+ Document doc= new Document(string);
+ try {
+ if (positions != null) {
+ final String POS_CATEGORY= "myCategory"; //$NON-NLS-1$
+
+ doc.addPositionCategory(POS_CATEGORY);
+ doc.addPositionUpdater(new DefaultPositionUpdater(POS_CATEGORY) {
+ protected boolean notDeleted() {
+ if (fOffset < fPosition.offset && (fPosition.offset + fPosition.length < fOffset + fLength)) {
+ fPosition.offset= fOffset + fLength; // deleted positions: set to end of remove
+ return false;
+ }
+ return true;
+ }
+ });
+ for (int i= 0; i < positions.length; i++) {
+ try {
+ doc.addPosition(POS_CATEGORY, positions[i]);
+ } catch (BadLocationException e) {
+ throw new IllegalArgumentException("Position outside of string. offset: " + positions[i].offset + ", length: " + positions[i].length + ", string size: " + string.length()); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ }
+ }
+ }
+ } catch (BadPositionCategoryException cannotHappen) {
+ // can not happen: category is correctly set up
+ }
+ return doc;
+ }
+
+ public static String format(int kind, String string, int indentationLevel, int[] positions, String lineSeparator, IRubyProject project) {
+ Map options= project != null ? project.getOptions(true) : null;
+ return format(kind, string, 0, string.length(), indentationLevel, positions, lineSeparator, options);
+ }
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyModelUtil.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyModelUtil.java 2006-12-15 15:31:22 UTC (rev 1705)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyModelUtil.java 2006-12-15 15:32:50 UTC (rev 1706)
@@ -14,6 +14,7 @@
*/
public final class RubyModelUtil {
+ public static final String DEFAULT_SCRIPT_SUFFIX = ".rb";
private static boolean PRIMARY_ONLY = false;
/**
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPluginImages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPluginImages.java 2006-12-15 15:31:22 UTC (rev 1705)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPluginImages.java 2006-12-15 15:32:50 UTC (rev 1706)
@@ -48,9 +48,10 @@
private static final String IMG_OBJS_CLASS= NAME_PREFIX + "class_obj.gif"; //$NON-NLS-1$
private static final String IMG_OBJS_INNER_CLASS= NAME_PREFIX + "innerclass_obj.gif"; //$NON-NLS-1$
private static final String IMG_OBJS_CLASSALT= NAME_PREFIX + "classfo_obj.gif"; //$NON-NLS-1$
- private static final String IMG_OBJS_MODULE = NAME_PREFIX + "module_obj.gif"; //$NON-NLS-1$
+ public static final String IMG_OBJS_MODULE = NAME_PREFIX + "module_obj.gif"; //$NON-NLS-1$
private static final String IMG_OBJS_MODULEALT= NAME_PREFIX + "modulefo_obj.gif"; //$NON-NLS-1$
private static final String IMG_OBJS_RUBY_MODEL= NAME_PREFIX + "ruby_model_obj.gif"; //$NON-NLS-1$
+ private static final String IMG_OBJS_SOURCE_FOLDER= NAME_PREFIX + "fldr_obj.gif"; //$NON-NLS-1$
private static final String IMG_OBJS_SCRIPT= NAME_PREFIX + "rscript_obj.gif"; //$NON-NLS-1$
private static final String IMG_OBJS_RUBY_RESOURCE= NAME_PREFIX + "rscript_resource_obj.gif"; //$NON-NLS-1$
private static final String IMG_OBJS_UNKNOWN= NAME_PREFIX + "unknown_obj.gif"; //$NON-NLS-1$
@@ -107,7 +108,7 @@
public static final ImageDescriptor DESC_OBJS_IMPCONT= createManaged(T_OBJ, IMG_CTOOLS_RUBY_IMPORT_CONTAINER);
public static final ImageDescriptor DESC_OBJS_RUBY_MODEL= createManaged(T_OBJ, IMG_OBJS_RUBY_MODEL);
-
+ public static final ImageDescriptor DESC_OBJS_SOURCE_FOLDER= createManaged(T_OBJ, IMG_OBJS_SOURCE_FOLDER);
public static final ImageDescriptor DESC_OBJS_LOCAL_VAR = createManaged(T_OBJ, IMG_CTOOLS_RUBY_LOCAL_VAR);
public static final ImageDescriptor DESC_OBJS_GLOBAL = createManaged(T_OBJ, IMG_CTOOLS_RUBY_GLOBAL);
public static final ImageDescriptor DESC_OBJS_MODULE = createManaged(T_OBJ, IMG_OBJS_MODULE);
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:31:22 UTC (rev 1705)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.java 2006-12-15 15:32:50 UTC (rev 1706)
@@ -25,6 +25,10 @@
public static String CoreUtility_buildproject_taskname;
public static String CoreUtility_buildall_taskname;
public static String CoreUtility_job_title;
+ public static String MultiTypeSelectionDialog_errorTitle;
+ public static String MultiTypeSelectionDialog_errorMessage;
+ public static String TypeSelectionDialog_errorTitle;
+ public static String TypeSelectionDialog_dialogMessage;
private RubyUIMessages() {
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.java 2006-12-15 15:31:22 UTC (rev 1705)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.java 2006-12-15 15:32:50 UTC (rev 1706)
@@ -150,6 +150,13 @@
public static String MarkOccurrencesConfigurationBlock_markMethodExitPoints;
public static String MarkOccurrencesConfigurationBlock_stickyOccurrences;
public static String MarkOccurrencesConfigurationBlock_title;
+
+ public static String PropertyAndPreferencePage_useprojectsettings_label;
+ public static String PropertyAndPreferencePage_useworkspacesettings_change;
+ public static String PropertyAndPreferencePage_showprojectspecificsettings_label;
+ public static String ProjectSelectionDialog_title;
+ public static String ProjectSelectionDialog_desciption;
+ public static String ProjectSelectionDialog_filter;
static {
NLS.initializeMessages(BUNDLE_NAME, PreferencesMessages.class);
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.properties 2006-12-15 15:31:22 UTC (rev 1705)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.properties 2006-12-15 15:32:50 UTC (rev 1706)
@@ -171,3 +171,11 @@
DebuggerPreferencePage_description_label=Debugger preferences
DebuggerPreferencePage_useRubyDebug_label=Use ruby-debug library
DebuggerPreferencePage_useRubyDebug_comment=ruby-debug requires a ruby version >= 1.8.4. At the time being a patched ruby-debug version must be used. It is packaged with RDT and can be found at {0}plugins/org.rubypeople.rdt.launching. It can be installed with the command 'gem install'. Please be aware that the package contains native code and therefore a c-compiler for your platform must be available.
+
+PropertyAndPreferencePage_useprojectsettings_label=Enable pr&oject specific settings
+PropertyAndPreferencePage_useworkspacesettings_change=Configure Workspace Settings...
+PropertyAndPreferencePage_showprojectspecificsettings_label=Configure Project Specific Settings...
+
+ProjectSelectionDialog_title=Project Specific Configuration
+ProjectSelectionDialog_desciption=&Select the project to configure:
+ProjectSelectionDialog_filter=&Filter projects with no project specific settings
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/ProjectSelectionDialog.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/ProjectSelectionDialog.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/ProjectSelectionDialog.java 2006-12-15 15:32:50 UTC (rev 1706)
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * 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.preferences;
+
+import java.util.Set;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.SelectionStatusDialog;
+import org.rubypeople.rdt.core.IRubyModel;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.dialogs.StatusInfo;
+import org.rubypeople.rdt.ui.RubyElementLabelProvider;
+import org.rubypeople.rdt.ui.RubyElementSorter;
+import org.rubypeople.rdt.ui.StandardRubyElementContentProvider;
+
+
+public class ProjectSelectionDialog extends SelectionStatusDialog {
+
+ // the visual selection widget group
+ private TableViewer fTableViewer;
+ private Set fProjectsWithSpecifics;
+
+ // sizing constants
+ private final static int SIZING_SELECTION_WIDGET_HEIGHT= 250;
+ private final static int SIZING_SELECTION_WIDGET_WIDTH= 300;
+
+ private final static String DIALOG_SETTINGS_SHOW_ALL= "ProjectSelectionDialog.show_all"; //$NON-NLS-1$
+
+ private ViewerFilter fFilter;
+
+ public ProjectSelectionDialog(Shell parentShell, Set projectsWithSpecifics) {
+ super(parentShell);
+ setTitle(PreferencesMessages.ProjectSelectionDialog_title);
+ setMessage(PreferencesMessages.ProjectSelectionDialog_desciption);
+ fProjectsWithSpecifics= projectsWithSpecifics;
+
+ int shellStyle = getShellStyle();
+ setShellStyle(shellStyle | SWT.MAX | SWT.RESIZE);
+
+ fFilter= new ViewerFilter() {
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ return fProjectsWithSpecifics.contains(element);
+ }
+ };
+
+ }
+
+ /* (non-Rubydoc)
+ * Method declared on Dialog.
+ */
+ protected Control createDialogArea(Composite parent) {
+ // page group
+ Composite composite= (Composite) super.createDialogArea(parent);
+
+ Font font= parent.getFont();
+ composite.setFont(font);
+
+ createMessageArea(composite);
+
+ fTableViewer= new TableViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
+ fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ doSelectionChanged(((IStructuredSelection) event.getSelection()).toArray());
+ }
+ });
+ fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ okPressed();
+ }
+ });
+ GridData data= new GridData(SWT.FILL, SWT.FILL, true, true);
+ data.heightHint= SIZING_SELECTION_WIDGET_HEIGHT;
+ data.widthHint= SIZING_SELECTION_WIDGET_WIDTH;
+ fTableViewer.getTable().setLayoutData(data);
+
+ fTableViewer.setLabelProvider(new RubyElementLabelProvider());
+ fTableViewer.setContentProvider(new StandardRubyElementContentProvider());
+ fTableViewer.setSorter(new RubyElementSorter());
+ fTableViewer.getControl().setFont(font);
+
+ Button checkbox= new Button(composite, SWT.CHECK);
+ checkbox.setText(PreferencesMessages.ProjectSelectionDialog_filter);
+ checkbox.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
+ checkbox.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ updateFilter(((Button) e.widget).getSelection());
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ updateFilter(((Button) e.widget).getSelection());
+ }
+ });
+ IDialogSettings dialogSettings= RubyPlugin.getDefault().getDialogSettings();
+ boolean doFilter= !dialogSettings.getBoolean(DIALOG_SETTINGS_SHOW_ALL) && !fProjectsWithSpecifics.isEmpty();
+ checkbox.setSelection(doFilter);
+ updateFilter(doFilter);
+
+ IRubyModel input= RubyCore.create(ResourcesPlugin.getWorkspace().getRoot());
+ fTableViewer.setInput(input);
+
+ doSelectionChanged(new Object[0]);
+ Dialog.applyDialogFont(composite);
+ return composite;
+ }
+
+ protected void updateFilter(boolean selected) {
+ if (selected) {
+ fTableViewer.addFilter(fFilter);
+ } else {
+ fTableViewer.removeFilter(fFilter);
+ }
+ RubyPlugin.getDefault().getDialogSettings().put(DIALOG_SETTINGS_SHOW_ALL, !selected);
+ }
+
+ private void doSelectionChanged(Object[] objects) {
+ if (objects.length != 1) {
+ updateStatus(new StatusInfo(IStatus.ERROR, "")); //$NON-NLS-1$
+ setSelectionResult(null);
+ } else {
+ updateStatus(new StatusInfo());
+ setSelectionResult(objects);
+ }
+ }
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult()
+ */
+ protected void computeResult() {
+ }
+}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PropertyAndPreferencePage.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PropertyAndPreferencePage.java 2006-12-15 15:31:22 UTC (rev 1705)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PropertyAndPreferencePage.java 2006-12-15 15:32:50 UTC (rev 1706)
@@ -1,213 +1,340 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
+ * 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/cpl-v10.html
- *
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.rubypeople.rdt.internal.ui.preferences;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.ControlEnableState;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.window.Window;
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.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.IWorkbenchPropertyPage;
import org.eclipse.ui.dialogs.PreferencesUtil;
-import org.eclipse.ui.forms.widgets.Hyperlink;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.ui.dialogs.StatusInfo;
import org.rubypeople.rdt.internal.ui.dialogs.StatusUtil;
import org.rubypeople.rdt.internal.ui.wizards.IStatusChangeListener;
+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.LayoutUtil;
import org.rubypeople.rdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
+
/**
* Base for project property and preference pages
*/
-public abstract class PropertyAndPreferencePage extends PreferencePage implements
- IWorkbenchPreferencePage, IWorkbenchPropertyPage {
+public abstract class PropertyAndPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, IWorkbenchPropertyPage {
+
+ private Control fConfigurationBlockControl;
+ private ControlEnableState fBlockEnableState;
+ private Link fChangeWorkspaceSettings;
+ private SelectionButtonDialogField fUseProjectSettings;
+ private IStatus fBlockStatus;
+ private Composite fParentComposite;
+
+ private IProject fProject; // project or null
+ private Map fData; // page data
+
+ public static final String DATA_NO_LINK= "PropertyAndPreferencePage.nolink"; //$NON-NLS-1$
+
+ public PropertyAndPreferencePage() {
+ fBlockStatus= new StatusInfo();
+ fBlockEnableState= null;
+ fProject= null;
+ fData= null;
+ }
- private Control fConfigurationBlockControl;
- private ControlEnableState fBlockEnableState;
- private Hyperlink fChangeWorkspaceSettings;
- private SelectionButtonDialogField fUseProjectSettings;
- private IStatus fBlockStatus;
+ protected abstract Control createPreferenceContent(Composite composite);
+ protected abstract boolean hasProjectSpecificOptions(IProject project);
+
+ protected abstract String getPreferencePageID();
+ protected abstract String getPropertyPageID();
+
+ protected boolean supportsProjectSpecificOptions() {
+ return getPropertyPageID() != null;
+ }
+
+ protected boolean offerLink() {
+ return fData == null || !Boolean.TRUE.equals(fData.get(DATA_NO_LINK));
+ }
+
+ protected Label createDescriptionLabel(Composite parent) {
+ fParentComposite= parent;
+ if (isProjectPreferencePage()) {
+ Composite composite= new Composite(parent, SWT.NONE);
+ composite.setFont(parent.getFont());
+ GridLayout layout= new GridLayout();
+ layout.marginHeight= 0;
+ layout.marginWidth= 0;
+ layout.numColumns= 2;
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ IDialogFieldListener listener= new IDialogFieldListener() {
+ public void dialogFieldChanged(DialogField field) {
+ enableProjectSpecificSettings(((SelectionButtonDialogField)field).isSelected());
+ }
+ };
+
+ fUseProjectSettings= new SelectionButtonDialogField(SWT.CHECK);
+ fUseProjectSettings.setDialogFieldListener(listener);
+ fUseProjectSettings.setLabelText(PreferencesMessages.PropertyAndPreferencePage_useprojectsettings_label);
+ fUseProjectSettings.doFillIntoGrid(composite, 1);
+ LayoutUtil.setHorizontalGrabbing(fUseProjectSettings.getSelectionButton(null));
+
+ if (offerLink()) {
+ fChangeWorkspaceSettings= createLink(composite, PreferencesMessages.PropertyAndPreferencePage_useworkspacesettings_change);
+ fChangeWorkspaceSettings.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
+ } else {
+ LayoutUtil.setHorizontalSpan(fUseProjectSettings.getSelectionButton(null), 2);
+ }
+
+ Label horizontalLine= new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
+ horizontalLine.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1));
+ horizontalLine.setFont(composite.getFont());
+ } else if (supportsProjectSpecificOptions() && offerLink()) {
+ fChangeWorkspaceSettings= createLink(parent, PreferencesMessages.PropertyAndPreferencePage_showprojectspecificsettings_label);
+ fChangeWorkspaceSettings.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
+ }
- private IProject fProject; // project or null
-
- public PropertyAndPreferencePage() {
- fBlockStatus = new StatusInfo();
- fBlockEnableState = null;
- fProject = null;
+ return super.createDescriptionLabel(parent);
}
+
+ /*
+ * @see org.eclipse.jface.preference.IPreferencePage#createContents(Composite)
+ */
+ protected Control createContents(Composite parent) {
+ Composite composite= new Composite(parent, SWT.NONE);
+ GridLayout layout= new GridLayout();
+ layout.marginHeight= 0;
+ layout.marginWidth= 0;
+ composite.setLayout(layout);
+ composite.setFont(parent.getFont());
+
+ GridData data= new GridData(GridData.FILL, GridData.FILL, true, true);
+
+ fConfigurationBlockControl= createPreferenceContent(composite);
+ fConfigurationBlockControl.setLayoutData(data);
+ if (isProjectPreferencePage()) {
+ boolean useProjectSettings= hasProjectSpecificOptions(getProject());
+ enableProjectSpecificSettings(useProjectSettings);
+ }
- /*
- * @see org.eclipse.jface.preference.IPreferencePage#createContents(Composite)
- */
- protected Control createContents(Composite parent) {
- Composite composite= new Composite(parent, SWT.NONE);
- GridLayout layout= new GridLayout();
- layout.marginHeight= 0;
- layout.marginWidth= 0;
- composite.setLayout(layout);
- composite.setFont(parent.getFont());
-
- GridData data= new GridData(GridData.FILL, GridData.FILL, true, true);
-
- fConfigurationBlockControl= createPreferenceContent(composite);
- fConfigurationBlockControl.setLayoutData(data);
+ Dialog.applyDialogFont(composite);
+ return composite;
+ }
- if (isProjectPreferencePage()) {
- boolean useProjectSettings= hasProjectSpecificOptions(getProject());
- enableProjectSpecificSettings(useProjectSettings);
- }
+ private Link createLink(Composite composite, String text) {
+ Link link= new Link(composite, SWT.NONE);
+ link.setFont(composite.getFont());
+ link.setText("<A>" + text + "</A>"); //$NON-NLS-1$//$NON-NLS-2$
+ link.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ doLinkActivated((Link) e.widget);
+ }
- Dialog.applyDialogFont(composite);
- return composite;
- }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ doLinkActivated((Link) e.widget);
+ }
+ });
+ return link;
+ }
+
+ protected boolean useProjectSettings() {
+ return isProjectPreferencePage() && fUseProjectSettings != null && fUseProjectSettings.isSelected();
+ }
+
+ protected boolean isProjectPreferencePage() {
+ return fProject != null;
+ }
+
+ protected IProject getProject() {
+ return fProject;
+ }
+
+ final void doLinkActivated(Link link) {
+ Map data= new HashMap();
+ data.put(DATA_NO_LINK, Boolean.TRUE);
+
+ if (isProjectPreferencePage()) {
+ openWorkspacePreferences(data);
+ } else {
+ HashSet projectsWithSpecifics= new HashSet();
+ try {
+ IRubyProject[] projects= RubyCore.create(ResourcesPlugin.getWorkspace().getRoot()).getRubyProjects();
+ for (int i= 0; i < projects.length; i++) {
+ IRubyProject curr= projects[i];
+ if (hasProjectSpecificOptions(curr.getProject())) {
+ projectsWithSpecifics.add(curr);
+ }
+ }
+ } catch (RubyModelException e) {
+ // ignore
+ }
+ ProjectSelectionDialog dialog= new ProjectSelectionDialog(getShell(), projectsWithSpecifics);
+ if (dialog.open() == Window.OK) {
+ IRubyProject res= (IRubyProject) dialog.getFirstResult();
+ openProjectProperties(res.getProject(), data);
+ }
+ }
+ }
+
+ protected final void openWorkspacePreferences(Object data) {
+ String id= getPreferencePageID();
+ PreferencesUtil.createPreferenceDialogOn(getShell(), id, new String[] { id }, data).open();
+ }
+
+ protected final void openProjectProperties(IProject project, Object data) {
+ String id= getPropertyPageID();
+ if (id != null) {
+ PreferencesUtil.createPropertyDialogOn(getShell(), project, id, new String[] { id }, data).open();
+ }
+ }
+
+
+ protected void enableProjectSpecificSettings(boolean useProjectSpecificSettings) {
+ fUseProjectSettings.setSelection(useProjectSpecificSettings);
+ enablePreferenceContent(useProjectSpecificSettings);
+ updateLinkVisibility();
+ doStatusChanged();
+ }
+
+ private void updateLinkVisibility() {
+ if (fChangeWorkspaceSettings == null || fChangeWorkspaceSettings.isDisposed()) {
+ return;
+ }
+
+ if (isProjectPreferencePage()) {
+ fChangeWorkspaceSettings.setEnabled(!useProjectSettings());
+ }
+ }
+
- protected abstract Control createPreferenceContent(Composite composite);
- protected abstract boolean hasProjectSpecificOptions(IProject project);
- protected abstract String getPreferencePageID();
- protected abstract String getPropertyPageID();
-
- protected final void openWorkspacePreferences(Object data) {
- String id= getPreferencePageID();
- PreferencesUtil.createPreferenceDialogOn(getShell(), id, new String[] { id }, data).open();
- }
-
- protected boolean useProjectSettings() {
- return isProjectPreferencePage() && fUseProjectSettings != null
- && fUseProjectSettings.isSelected();
- }
+ protected void setPreferenceContentStatus(IStatus status) {
+ fBlockStatus= status;
+ doStatusChanged();
+ }
+
+ /**
+ * Returns a new status change listener that calls {@link #setPreferenceContentStatus(IStatus)}
+ * when the status has changed
+ * @return The new listener
+ */
+ protected IStatusChangeListener getNewStatusChangedListener() {
+ return new IStatusChangeListener() {
+ public void statusChanged(IStatus status) {
+ setPreferenceContentStatus(status);
+ }
+ };
+ }
+
+ protected IStatus getPreferenceContentStatus() {
+ return fBlockStatus;
+ }
- protected boolean isProjectPreferencePage() {
- return fProject != null;
- }
+ protected void doStatusChanged() {
+ if (!isProjectPreferencePage() || useProjectSettings()) {
+ updateStatus(fBlockStatus);
+ } else {
+ updateStatus(new StatusInfo());
+ }
+ }
+
+ protected void enablePreferenceContent(boolean enable) {
+ if (enable) {
+ if (fBlockEnableState != null) {
+ fBlockEnableState.restore();
+ fBlockEnableState= null;
+ }
+ } else {
+ if (fBlockEnableState == null) {
+ fBlockEnableState= ControlEnableState.disable(fConfigurationBlockControl);
+ }
+ }
+ }
+
+ /*
+ * @see org.eclipse.jface.preference.IPreferencePage#performDefaults()
+ */
+ protected void performDefaults() {
+ if (useProjectSettings()) {
+ enableProjectSpecificSettings(false);
+ }
+ super.performDefaults();
+ }
- protected IProject getProject() {
- return fProject;
- }
+ private void updateStatus(IStatus status) {
+ setValid(!status.matches(IStatus.ERROR));
+ StatusUtil.applyToStatusLine(this, status);
+ }
- private void doProjectWorkspaceStateChanged() {
- enablePreferenceContent(useProjectSettings());
- fChangeWorkspaceSettings.setVisible(!useProjectSettings());
- doStatusChanged();
- }
+ /* (non-Rubydoc)
+ * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+ */
+ public void init(IWorkbench workbench) {
+ }
- protected void setPreferenceContentStatus(IStatus status) {
- fBlockStatus = status;
- doStatusChanged();
- }
+ /* (non-Rubydoc)
+ * @see org.eclipse.ui.IWorkbenchPropertyPage#getElement()
+ */
+ public IAdaptable getElement() {
+ return fProject;
+ }
- /**
- * Returns a new status change listener that calls
- * {@link #setPreferenceContentStatus(IStatus)} when the status has changed
- *
- * @return The new listener
- */
- protected IStatusChangeListener getNewStatusChangedListener() {
- return new IStatusChangeListener() {
-
- public void statusChanged(IStatus status) {
- setPreferenceContentStatus(status);
- }
- };
- }
-
- protected IStatus getPreferenceContentStatus() {
- return fBlockStatus;
- }
-
- protected void doStatusChanged() {
- if (!isProjectPreferencePage() || useProjectSettings()) {
- updateStatus(fBlockStatus);
- } else {
- updateStatus(new StatusInfo());
- }
- }
-
- protected void enablePreferenceContent(boolean enable) {
- if (enable) {
- if (fBlockEnableState != null) {
- fBlockEnableState.restore();
- fBlockEnableState = null;
- }
- } else {
- if (fBlockEnableState == null) {
- fBlockEnableState = ControlEnableState.disable(fConfigurationBlockControl);
- }
- }
- }
-
- /*
- * @see org.eclipse.jface.preference.IPreferencePage#performDefaults()
- */
- protected void performDefaults() {
- if (useProjectSettings()) {
- fUseProjectSettings.setSelection(false);
- // fUseWorkspaceSettings.setSelection(true);
- }
- super.performDefaults();
- }
-
- private void updateStatus(IStatus status) {
- setValid(!status.matches(IStatus.ERROR));
- StatusUtil.applyToStatusLine(this, status);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
- */
- public void init(IWorkbench workbench) {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IWorkbenchPropertyPage#getElement()
- */
- public IAdaptable getElement() {
- return fProject;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime.IAdaptable)
- */
- public void setElement(IAdaptable element) {
- fProject = (IProject) element.getAdapter(IResource.class);
- }
-
- protected void enableProjectSpecificSettings(boolean useProjectSpecificSettings) {
- fUseProjectSettings.setSelection(useProjectSpecificSettings);
- enablePreferenceContent(useProjectSpecificSettings);
- updateLinkVisibility();
- doStatusChanged();
- }
-
- private void updateLinkVisibility() {
- if (fChangeWorkspaceSettings == null || fChangeWorkspaceSettings.isDisposed()) {
- return;
- }
-
- if (isProjectPreferencePage()) {
- fChangeWorkspaceSettings.setEnabled(!useProjectSettings());
- }
- }
+ /* (non-Rubydoc)
+ * @see org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime.IAdaptable)
+ */
+ public void setElement(IAdaptable element) {
+ fProject= (IProject) element.getAdapter(IResource.class);
+ }
+
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.jface.preference.PreferencePage#applyData(java.lang.Object)
+ */
+ public void applyData(Object data) {
+ if (data instanceof Map) {
+ fData= (Map) data;
+ }
+ if (fChangeWorkspaceSettings != null) {
+ if (!offerLink()) {
+ fChangeWorkspaceSettings.dispose();
+ fParentComposite.layout(true, true);
+ }
+ }
+ }
+
+ protected Map getData() {
+ return fData;
+ }
+
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/viewsupport/RubyElementImageProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/viewsupport/RubyElementImageProvider.java 2006-12-15 15:31:22 UTC (rev 1705)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/viewsupport/RubyElementImageProvider.java 2006-12-15 15:32:50 UTC (rev 1706)
@@ -206,6 +206,9 @@
case IRubyElement.SCRIPT:
return RubyPluginImages.DESC_OBJS_SCRIPT;
+
+ case IRubyElement.SOURCE_FOLDER:
+ return RubyPluginImages.DESC_OBJS_SOURCE_FOLDER;
case IRubyElement.RUBY_PROJECT:
IRubyProject jp = (IRubyProject) element;
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/AbstractOpenWizardAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/AbstractOpenWizardAction.java 2006-12-15 15:31:22 UTC (rev 1705)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/AbstractOpenWizardAction.java 2006-12-15 15:32:50 UTC (rev 1706)
@@ -148,8 +148,8 @@
notifyResult(res == Window.OK);
} catch (CoreException e) {
- String title = NewWizardMessages.getString("AbstractOpenWizardAction.createerror.title"); //$NON-NLS-1$
- String message = NewWizardMessages.getString("AbstractOpenWizardAction.createerror.message"); //$NON-NLS-1$
+ String title = NewWizardMessages.AbstractOpenWizardAction_createerror_title;
+ String message = NewWizardMessages.AbstractOpenWizardAction_createerror_message;
ExceptionHandler.handle(e, shell, title, message);
}
}
@@ -191,8 +191,8 @@
IWorkspace workspace = ResourcesPlugin.getWorkspace();
if (workspace.getRoot().getProjects().length == 0) {
Shell shell = RubyPlugin.getActiveWorkbenchShell();
- String title = NewWizardMessages.getString("AbstractOpenWizardAction.noproject.title"); //$NON-NLS-1$
- String message = NewWizardMessages.getString("AbstractOpenWizardAction.noproject.message"); //$NON-NLS-1$
+ String title = NewWizardMessages.AbstractOpenWizardAction_noproject_title;
+ String message = NewWizardMessages.AbstractOpenWizardAction_noproject_message;
if (MessageDialog.openQuestion(shell, title, message)) {
IWorkbenchWindow window = RubyPlugin.getActiveWorkbenchWindow();
(new NewProjectAction(window)).run();
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:31:22 UTC (rev 1705)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.java 2006-12-15 15:32:50 UTC (rev 1706)
@@ -10,40 +10,50 @@
*******************************************************************************/
package org.rubypeople.rdt.internal.ui.wizards;
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
+import org.eclipse.osgi.util.NLS;
-public class NewWizardMessages {
+public class NewWizardMessages extends NLS {
- private static final String RESOURCE_BUNDLE= NewWizardMessages.class.getName();
- private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
-
+ private static final String BUNDLE_NAME= "org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages";//$NON-NLS-1$
+
private NewWizardMessages() {
+ // Do not instantiate
}
-
- public static String getString(String key) {
- try {
- return fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return '!' + key + '!';
- }
- }
- /**
- * Gets a string from the resource bundle and formats it with the argument
- *
- * @param key the string used to get the bundle value, must not be null
- */
- public static String getFormattedString(String key, Object arg) {
- return MessageFormat.format(getString(key), new Object[] { arg });
+ public static String NewContainerWizardPage_container_label;
+ public static String NewContainerWizardPage_container_button;
+ public static String NewContainerWizardPage_ChooseSourceContainerDialog_title;
+ public static String NewContainerWizardPage_ChooseSourceContainerDialog_description;
+ public static String NewContainerWizardPage_error_EnterContainerName;
+ public static String NewContainerWizardPage_error_ProjectClosed;
+ public static String NewContainerWizardPage_warning_NotARubyProject;
+ public static String NewContainerWizardPage_warning_NotInARubyProject;
+ public static String NewContainerWizardPage_error_NotAFolder;
+ public static String NewContainerWizardPage_error_ContainerDoesNotExist;
+ public static String AbstractOpenWizardAction_createerror_message;
+ public static String AbstractOpenWizardAction_createerror_title;
+ public static String AbstractOpenWizardAction_noproject_title;
+ public static String AbstractOpenWizardAction_noproject_message;
+
+ public static String N...
[truncated message content] |
|
From: <caw...@us...> - 2006-12-15 15:31:23
|
Revision: 1705
http://svn.sourceforge.net/rubyeclipse/?rev=1705&view=rev
Author: cawilliams
Date: 2006-12-15 07:31:22 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
all sorts of plumbing for new test case wizard, new SourceFolder in IRubyElement hierarchy
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyElement.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyProject.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IType.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyConventions.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/RubyElement.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModel.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/RubyModelOperation.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptStructureBuilder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyType.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceRefElement.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/buffer/LRUCache.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/symbols/ISymbolFinder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/CharOperation.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/ISourceFolder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CreateMethodOperation.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CreateRubyScriptOperation.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CreateSourceFolderOperation.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolderInfo.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/ASTRewrite.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/ASTUtil.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/DOMFinder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/WeakHashSet.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyElement.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyElement.java 2006-12-15 15:29:19 UTC (rev 1704)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyElement.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -32,20 +32,29 @@
public interface IRubyElement extends IAdaptable {
public static final int RUBY_MODEL = 0;
+ /**
+ * Constant representing a Ruby project.
+ * A Ruby element with this type can be safely cast to <code>IRubyProject</code>.
+ */
public static final int RUBY_PROJECT = 1;
- public static final int SCRIPT = 2;
- public static final int TYPE = 3;
- public static final int METHOD = 4;
- public static final int GLOBAL = 5;
- public static final int IMPORT_DECLARATION = 6;
- public static final int CONSTANT = 7;
- public static final int CLASS_VAR = 8;
- public static final int INSTANCE_VAR = 9;
- public static final int LOCAL_VARIABLE = 10;
- public static final int BLOCK = 11;
- public static final int DYNAMIC_VAR = 12;
- public static final int FIELD = 13;
- public static final int IMPORT_CONTAINER = 14;
+ /**
+ * Constant representing a source folder
+ * A Ruby element with this type can be safely cast to <code>ISourceFolder</code>.
+ */
+ public static final int SOURCE_FOLDER = 2;
+ public static final int SCRIPT = 3;
+ public static final int TYPE = 4;
+ public static final int METHOD = 5;
+ public static final int GLOBAL = 6;
+ public static final int IMPORT_DECLARATION = 7;
+ public static final int CONSTANT = 8;
+ public static final int CLASS_VAR = 9;
+ public static final int INSTANCE_VAR = 10;
+ public static final int LOCAL_VARIABLE = 11;
+ public static final int BLOCK = 12;
+ public static final int DYNAMIC_VAR = 13;
+ public static final int FIELD = 14;
+ public static final int IMPORT_CONTAINER = 15;
/**
* Returns the first ancestor of this Ruby element that has the given type.
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyProject.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyProject.java 2006-12-15 15:29:19 UTC (rev 1704)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyProject.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -29,7 +29,9 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
/**
* @author Chris
@@ -112,4 +114,13 @@
public IRubyScript getRubyScript(IFile file);
+ public abstract ISourceFolder getSourceFolder(String[] names);
+
+ public abstract ISourceFolder getSourceFolder(IResource resource);
+
+ public abstract ISourceFolder[] getSourceFolders() throws RubyModelException;
+
+ public abstract ISourceFolder createSourceFolder(String packName,
+ boolean force, IProgressMonitor monitor) throws RubyModelException;
+
}
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/ISourceFolder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/ISourceFolder.java (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/ISourceFolder.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -0,0 +1,118 @@
+package org.rubypeople.rdt.core;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+
+public interface ISourceFolder extends IRubyElement, IParent, IOpenable {
+
+ /**
+ * Returns whether this fragment contains at least one Ruby resource.
+ * @return true if this fragment contains at least one Ruby resource, false otherwise
+ * @exception RubyModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ boolean containsRubyResources() throws RubyModelException;
+ /**
+ * Creates and returns a compilation unit in this package fragment
+ * with the specified name and contents. No verification is performed
+ * on the contents.
+ *
+ * <p>It is possible that a compilation unit with the same name already exists in this
+ * package fragment.
+ * The value of the <code>force</code> parameter effects the resolution of
+ * such a conflict:<ul>
+ * <li> <code>true</code> - in this case the compilation is created with the new contents</li>
+ * <li> <code>false</code> - in this case a <code>RubyModelException</code> is thrown</li>
+ * </ul>
+ *
+ * @param contents the given contents
+ * @param force specify how to handle conflict is the same name already exists
+ * @param monitor the given progress monitor
+ * @param name the given name
+ * @exception RubyModelException if the element could not be created. Reasons include:
+ * <ul>
+ * <li> This Ruby element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
+ * <li> A <code>CoreException</code> occurred while creating an underlying resource
+ * <li> The name is not a valid compilation unit name (INVALID_NAME)
+ * <li> The contents are <code>null</code> (INVALID_CONTENTS)
+ * </ul>
+ * @return a compilation unit in this package fragment
+ * with the specified name and contents
+ */
+ IRubyScript createRubyScript(String name, String contents, boolean force, IProgressMonitor monitor) throws RubyModelException;
+ /**
+ * Returns the compilation unit with the specified name
+ * in this package (for example, <code>"Object.java"</code>).
+ * The name has to be a valid compilation unit name.
+ * This is a handle-only method. The compilation unit may or may not be present.
+ *
+ * @param name the given name
+ * @return the compilation unit with the specified name in this package
+ * @see RubyConventions#validateCompilationUnitName(String)
+ */
+// IRubyScript getRubyScript(String name);
+ /**
+ * Returns all of the compilation units in this package fragment.
+ *
+ * <p>Note: it is possible that a package fragment contains only
+ * class files (in other words, its kind is <code>K_BINARY</code>), in which
+ * case this method returns an empty collection.
+ * </p>
+ *
+ * @exception RubyModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ * @return all of the compilation units in this package fragment
+ */
+ IRubyScript[] getRubyScripts() throws RubyModelException;
+ /**
+ * Returns all of the compilation units in this package fragment that are
+ * in working copy mode and that have the given owner.
+ * <p>
+ * Only existing working copies are returned. So a compilation unit handle that has no
+ * corresponding resource on disk will be included if and only if is in working copy mode.
+ * </p>
+ * <p>Note: it is possible that a package fragment contains only
+ * class files (in other words, its kind is <code>K_BINARY</code>), in which
+ * case this method returns an empty collection.
+ * </p>
+ *
+ * @param owner the owner of the returned compilation units
+ * @exception RubyModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ * @return all of the compilation units in this package fragment
+ * @since 3.0
+ */
+ IRubyScript[] getRubyScripts(WorkingCopyOwner owner) throws RubyModelException;
+ /**
+ * Returns the dot-separated package name of this fragment, for example
+ * <code>"java.lang"</code>, or <code>""</code> (the empty string),
+ * for the default package.
+ *
+ * @return the dot-separated package name of this fragment
+ */
+ String getElementName();
+
+ /**
+ * Returns an array of non-Ruby resources contained in this package fragment.
+ * <p>
+ * Non-Ruby resources includes other files and folders located in the same
+ * directory as the compilation units or class files for this package
+ * fragment. Source files excluded from this package by virtue of
+ * inclusion/exclusion patterns on the corresponding source classpath entry
+ * are considered non-Ruby resources and will appear in the result
+ * (possibly in a folder).
+ * </p>
+ *
+ * @exception RubyModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ * @return an array of non-Ruby resources (<code>IFile</code>s,
+ * <code>IFolder</code>s, or <code>IStorage</code>s if the
+ * package fragment is in an archive) contained in this package
+ * fragment
+ * @see IClasspathEntry#getInclusionPatterns()
+ * @see IClasspathEntry#getExclusionPatterns()
+ */
+ Object[] getNonRubyResources() throws RubyModelException;
+ IRubyScript getRubyScript(String name);
+
+}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IType.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IType.java 2006-12-15 15:29:19 UTC (rev 1704)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IType.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -24,6 +24,7 @@
*/
package org.rubypeople.rdt.core;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.rubypeople.rdt.internal.core.RubyMethod;
/**
@@ -137,4 +138,38 @@
public boolean isMember() throws RubyModelException;
+ /**
+ * Creates and returns a method or constructor in this type with the
+ * given contents.
+ * <p>
+ * Optionally, the new element can be positioned before the specified
+ * sibling. If no sibling is specified, the element will be appended
+ * to this type.
+ *
+ * <p>It is possible that a method with the same signature already exists in this type.
+ * The value of the <code>force</code> parameter effects the resolution of
+ * such a conflict:<ul>
+ * <li> <code>true</code> - in this case the method is created with the new contents</li>
+ * <li> <code>false</code> - in this case a <code>RubyModelException</code> is thrown</li>
+ * </ul></p>
+ *
+ * @param contents the given contents
+ * @param sibling the given sibling
+ * @param force a flag in case the same name already exists in this type
+ * @param monitor the given progress monitor
+ * @exception RubyModelException if the element could not be created. Reasons include:
+ * <ul>
+ * <li> This Ruby element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
+ * <li> A <code>CoreException</code> occurred while updating an underlying resource
+ * <li> The specified sibling is not a child of this type (INVALID_SIBLING)
+ * <li> The contents could not be recognized as a method or constructor
+ * declaration (INVALID_CONTENTS)
+ * <li> This type is read-only (binary) (READ_ONLY)
+ * <li> There was a naming collision with an existing method (NAME_COLLISION)
+ * </ul>
+ * @return a method or constructor in this type with the given contents
+ */
+ public IMethod createMethod(String contents, IRubyElement sibling, boolean force,
+ IProgressMonitor progress) throws RubyModelException;
+
}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyConventions.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyConventions.java 2006-12-15 15:29:19 UTC (rev 1704)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyConventions.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -8,6 +8,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.rubypeople.rdt.internal.core.RubyModelStatus;
+import org.rubypeople.rdt.internal.core.util.Messages;
import org.rubypeople.rdt.internal.core.util.Util;
/**
@@ -72,4 +73,33 @@
// Util.bind("convention.illegalIdentifier", id), null); //$NON-NLS-1$
// }
}
+
+ public static IStatus validateRubyTypeName(String typeName) {
+ if (typeName == null) {
+ return new Status(IStatus.ERROR, RubyCore.PLUGIN_ID, -1, Messages.convention_type_nullName, null);
+ }
+ if (typeName.length() == 0) {
+ return new Status(IStatus.ERROR, RubyCore.PLUGIN_ID, -1, Messages.bind(Messages.convention_type_invalidName, typeName), null);
+ }
+ if (!isConstant(typeName)) {
+ return new Status(IStatus.ERROR, RubyCore.PLUGIN_ID, -1, "Class name must be a constant. It must begin with a capital letter, and contain only letters, digits, or underscores.", null);
+ }
+ return new Status(IStatus.OK, RubyCore.PLUGIN_ID, -1, null, null);
+
+ }
+
+ private static 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;
+ }
}
Added: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CreateMethodOperation.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CreateMethodOperation.java (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CreateMethodOperation.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -0,0 +1,272 @@
+package org.rubypeople.rdt.internal.core;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.text.edits.TextEdit;
+import org.jruby.ast.DefnNode;
+import org.jruby.ast.DefsNode;
+import org.jruby.ast.NewlineNode;
+import org.jruby.ast.Node;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyModelStatus;
+import org.rubypeople.rdt.core.IRubyModelStatusConstants;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.core.parser.RubyParser;
+import org.rubypeople.rdt.internal.core.util.ASTRewrite;
+import org.rubypeople.rdt.internal.core.util.ASTUtil;
+import org.rubypeople.rdt.internal.core.util.Messages;
+
+public class CreateMethodOperation extends RubyModelOperation {
+
+ /**
+ * A constant meaning to position the new element
+ * as the last child of its parent element.
+ */
+ protected static final int INSERT_LAST = 1;
+ /**
+ * A constant meaning to position the new element
+ * after the element defined by <code>fAnchorElement</code>.
+ */
+ protected static final int INSERT_AFTER = 2;
+ /**
+ * A constant meaning to position the new element
+ * before the element defined by <code>fAnchorElement</code>.
+ */
+ protected static final int INSERT_BEFORE = 3;
+ /**
+ * One of the position constants, describing where
+ * to position the newly created element.
+ */
+ protected int insertionPolicy = INSERT_LAST;
+ /**
+ * The element that the newly created element is
+ * positioned relative to, as described by
+ * <code>fInsertPosition</code>, or <code>null</code>
+ * if the newly created element will be positioned
+ * last.
+ */
+ protected IRubyElement anchorElement = null;
+ /**
+ * A flag indicating whether creation of a new element occurred.
+ * A request for creating a duplicate element would request in this
+ * flag being set to <code>false</code>. Ensures that no deltas are generated
+ * when creation does not occur.
+ */
+ protected boolean creationOccurred = true;
+
+ private String source;
+ private Node cuAST;
+ private Node createdNode;
+ private String[] parameters;
+
+ public CreateMethodOperation(IType parentElement, String source, boolean force) {
+ super(null, new IRubyElement[]{parentElement}, force);
+ this.source = source;
+ }
+
+ @Override
+ protected void executeOperation() throws RubyModelException {
+ try {
+ beginTask(getMainTaskName(), getMainAmountOfWork());
+ RubyElementDelta delta = newRubyElementDelta();
+ IRubyScript unit = getRubyScript();
+ generateNewRubyScriptAST(unit);
+ if (this.creationOccurred) {
+ //a change has really occurred
+ unit.save(null, false);
+ boolean isWorkingCopy = unit.isWorkingCopy();
+ if (!isWorkingCopy)
+ this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
+ worked(1);
+ resultElements = generateResultHandles();
+ if (!isWorkingCopy // if unit is working copy, then save will have already fired the delta
+ && unit.getParent().exists()) {
+ for (int i = 0; i < resultElements.length; i++) {
+ delta.added(resultElements[i]);
+ }
+ addDelta(delta);
+ } // else unit is created outside classpath
+ // non-ruby resource delta will be notified by delta processor
+ }
+ } finally {
+ done();
+ }
+
+ }
+
+ /**
+ * Returns the IType the member is to be created in.
+ */
+ protected IType getType() {
+ return (IType)getParentElement();
+ }
+
+ /**
+ * @see CreateElementInCUOperation#generateResultHandle
+ */
+ protected IRubyElement generateResultHandle() {
+ String[] types = convertASTMethodTypesToSignatures();
+ String name = getASTNodeName();
+ return getType().getMethod(name, types);
+ }
+
+ private String getASTNodeName() {
+ if (this.createdNode instanceof DefsNode)
+ return ((DefsNode) this.createdNode).getName();
+ return ((DefnNode) this.createdNode).getName();
+ }
+
+ /**
+ * Returns the type signatures of the parameter types of the
+ * current <code>MethodDeclaration</code>
+ */
+ protected String[] convertASTMethodTypesToSignatures() {
+ if (this.parameters == null) {
+ if (this.createdNode != null) {
+ DefnNode methodDeclaration = (DefnNode) this.createdNode;
+ this.parameters = ASTUtil.getArgs(methodDeclaration.getArgsNode(), methodDeclaration.getBodyNode());
+ }
+ }
+ return this.parameters;
+ }
+
+
+
+ /**
+ * Creates and returns the handles for the elements this operation created.
+ */
+ protected IRubyElement[] generateResultHandles() {
+ return new IRubyElement[]{generateResultHandle()};
+ }
+
+ /**
+ * Returns the ruby script in which the new element is being created.
+ */
+ protected IRubyScript getRubyScript() {
+ return getRubyScriptFor(getParentElement());
+ }
+
+ /**
+ * @see CreateElementInCUOperation#getMainTaskName()
+ */
+ public String getMainTaskName(){
+ return Messages.operation_createMethodProgress;
+ }
+
+ /**
+ * Returns the amount of work for the main task of this operation for
+ * progress reporting.
+ */
+ protected int getMainAmountOfWork(){
+ return 2;
+ }
+
+ /**
+ * Instructs this operation to position the new element before
+ * the given sibling, or to add the new element as the last child
+ * of its parent if <code>null</code>.
+ */
+ public void createBefore(IRubyElement sibling) {
+ setRelativePosition(sibling, INSERT_BEFORE);
+ }
+
+ /**
+ * Instructs this operation to position the new element relative
+ * to the given sibling, or to add the new element as the last child
+ * of its parent if <code>null</code>. The <code>position</code>
+ * must be one of the position constants.
+ */
+ protected void setRelativePosition(IRubyElement sibling, int policy) throws IllegalArgumentException {
+ if (sibling == null) {
+ this.anchorElement = null;
+ this.insertionPolicy = INSERT_LAST;
+ } else {
+ this.anchorElement = sibling;
+ this.insertionPolicy = policy;
+ }
+ }
+
+ /*
+ * Generates a new AST for this operation and applies it to the given cu
+ */
+ protected void generateNewRubyScriptAST(IRubyScript cu) throws RubyModelException {
+ this.cuAST = parse(cu);
+ IDocument document = getDocument(cu);
+ ASTRewrite rewriter = ASTRewrite.create(this.cuAST, document);
+
+ Node child = generateElementAST(document, cu);
+ if (child != null) {
+ Node parent = ((RubyElement) getParentElement()).findNode(this.cuAST);
+ if (parent == null)
+ parent = this.cuAST;
+ insertASTNode(rewriter, parent, child);
+ apply(rewriter, document);
+ }
+ worked(1);
+ }
+
+ private void insertASTNode(ASTRewrite rewriter, Node parent, Node child) {
+ switch (this.insertionPolicy) {
+ case INSERT_BEFORE:
+ Node element = ((RubyElement) this.anchorElement).findNode(this.cuAST);
+ rewriter.insertBefore(source, child, element, null);
+ case INSERT_AFTER:
+ element = ((RubyElement) this.anchorElement).findNode(this.cuAST);
+ rewriter.insertAfter(source, child, element, null);
+ case INSERT_LAST:
+ rewriter.insertLast(source, child, null);
+ break;
+ }
+ }
+
+ private Node generateElementAST(IDocument document, IRubyScript cu) {
+ RubyParser parser = new RubyParser();
+ Node root = parser.parse(this.source);
+ NewlineNode newline = (NewlineNode) root;
+ this.createdNode = newline.getNextNode(); // Grab node from our parsed source!
+ return this.createdNode;
+ }
+
+ protected Node parse(IRubyScript cu) throws RubyModelException {
+ // ensure cu is consistent (noop if already consistent)
+ cu.makeConsistent(this.progressMonitor);
+ // create an AST for the ruby script
+ RubyParser parser = new RubyParser();
+ return parser.parse(cu.getSource());
+ }
+
+ protected void apply(ASTRewrite rewriter, IDocument document) throws RubyModelException {
+ TextEdit edits = rewriter.rewriteAST(document, null);
+ try {
+ edits.apply(document);
+ } catch (BadLocationException e) {
+ throw new RubyModelException(e, IRubyModelStatusConstants.INVALID_CONTENTS);
+ }
+ }
+
+ /**
+ * Possible failures: <ul>
+ * <li>NO_ELEMENTS_TO_PROCESS - the compilation unit supplied to the operation is
+ * <code>null</code>.
+ * <li>INVALID_NAME - no name, a name was null or not a valid
+ * import declaration name.
+ * <li>INVALID_SIBLING - the sibling provided for positioning is not valid.
+ * </ul>
+ * @see IRubyModelStatus
+ */
+ public IRubyModelStatus verify() {
+ if (getParentElement() == null) {
+ return new RubyModelStatus(IRubyModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
+ }
+ if (this.anchorElement != null) {
+ IRubyElement domPresentParent = this.anchorElement.getParent();
+ if (!domPresentParent.equals(getParentElement())) {
+ return new RubyModelStatus(IRubyModelStatusConstants.INVALID_SIBLING, this.anchorElement);
+ }
+ }
+ return RubyModelStatus.VERIFIED_OK;
+ }
+
+}
Added: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CreateRubyScriptOperation.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CreateRubyScriptOperation.java (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CreateRubyScriptOperation.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * 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.core;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.rubypeople.rdt.core.IBuffer;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyElementDelta;
+import org.rubypeople.rdt.core.IRubyModelStatus;
+import org.rubypeople.rdt.core.IRubyModelStatusConstants;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.ISourceFolder;
+import org.rubypeople.rdt.core.RubyConventions;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.core.util.Messages;
+import org.rubypeople.rdt.internal.core.util.Util;
+
+/**
+ * <p>This operation creates a compilation unit (CU).
+ * If the CU doesn't exist yet, a new compilation unit will be created with the content provided.
+ * Otherwise the operation will override the contents of an existing CU with the new content.
+ *
+ * <p>Note: It is possible to create a CU automatically when creating a
+ * class or interface. Thus, the preferred method of creating a CU is
+ * to perform a create type operation rather than
+ * first creating a CU and secondly creating a type inside the CU.
+ *
+ * <p>Required Attributes:<ul>
+ * <li>The package fragment in which to create the compilation unit.
+ * <li>The name of the compilation unit.
+ * Do not include the <code>".java"</code> suffix (ex. <code>"Object"</code> -
+ * the <code>".java"</code> will be added for the name of the compilation unit.)
+ * <li>
+ * </ul>
+ */
+public class CreateRubyScriptOperation extends RubyModelOperation {
+
+ /**
+ * The name of the compilation unit being created.
+ */
+ protected String fName;
+ /**
+ * The source code to use when creating the element.
+ */
+ protected String fSource= null;
+/**
+ * When executed, this operation will create a compilation unit with the given name.
+ * The name should have the ".java" suffix.
+ */
+public CreateRubyScriptOperation(ISourceFolder parentElement, String name, String source, boolean force) {
+ super(null, new IRubyElement[] {parentElement}, force);
+ fName = name;
+ fSource = source;
+}
+/**
+ * Creates a compilation unit.
+ *
+ * @exception RubyModelException if unable to create the compilation unit.
+ */
+protected void executeOperation() throws RubyModelException {
+ try {
+ beginTask(Messages.operation_createUnitProgress, 2);
+ RubyElementDelta delta = newRubyElementDelta();
+ IRubyScript unit = getRubyScript();
+ ISourceFolder pkg = (ISourceFolder) getParentElement();
+ IContainer folder = (IContainer) pkg.getResource();
+ worked(1);
+ IFile compilationUnitFile = folder.getFile(new Path(fName));
+ if (compilationUnitFile.exists()) {
+ // update the contents of the existing unit if fForce is true
+ if (force) {
+ IBuffer buffer = unit.getBuffer();
+ if (buffer == null) return;
+ buffer.setContents(fSource);
+ unit.save(new NullProgressMonitor(), false);
+ resultElements = new IRubyElement[] {unit};
+ if (!Util.isExcluded(unit)
+ && unit.getParent().exists()) {
+ for (int i = 0; i < resultElements.length; i++) {
+ delta.changed(resultElements[i], IRubyElementDelta.F_CONTENT);
+ }
+ addDelta(delta);
+ }
+ } else {
+ throw new RubyModelException(new RubyModelStatus(
+ IRubyModelStatusConstants.NAME_COLLISION,
+ Messages.bind(Messages.status_nameCollision, compilationUnitFile.getFullPath().toString())));
+ }
+ } else {
+ try {
+ String encoding = null;
+ try {
+ encoding = folder.getDefaultCharset(); // get folder encoding as file is not accessible
+ }
+ catch (CoreException ce) {
+ // use no encoding
+ }
+ InputStream stream = new ByteArrayInputStream(encoding == null ? fSource.getBytes() : fSource.getBytes(encoding));
+ createFile(folder, unit.getElementName(), stream, force);
+ resultElements = new IRubyElement[] {unit};
+ if (!Util.isExcluded(unit)
+ && unit.getParent().exists()) {
+ for (int i = 0; i < resultElements.length; i++) {
+ delta.added(resultElements[i]);
+ }
+ addDelta(delta);
+ }
+ } catch (IOException e) {
+ throw new RubyModelException(e, IRubyModelStatusConstants.IO_EXCEPTION);
+ }
+ }
+ worked(1);
+ } finally {
+ done();
+ }
+}
+/**
+ * @see CreateElementInCUOperation#getCompilationUnit()
+ */
+protected IRubyScript getRubyScript() {
+ return ((ISourceFolder)getParentElement()).getRubyScript(fName);
+}
+protected ISchedulingRule getSchedulingRule() {
+ IResource resource = getRubyScript().getResource();
+ IWorkspace workspace = resource.getWorkspace();
+ if (resource.exists()) {
+ return workspace.getRuleFactory().modifyRule(resource);
+ } else {
+ return workspace.getRuleFactory().createRule(resource);
+ }
+}
+/**
+ * Possible failures: <ul>
+ * <li>NO_ELEMENTS_TO_PROCESS - the package fragment supplied to the operation is
+ * <code>null</code>.
+ * <li>INVALID_NAME - the compilation unit name provided to the operation
+ * is <code>null</code> or has an invalid syntax
+ * <li>INVALID_CONTENTS - the source specified for the compiliation unit is null
+ * </ul>
+ */
+public IRubyModelStatus verify() {
+ if (getParentElement() == null) {
+ return new RubyModelStatus(IRubyModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
+ }
+ if (RubyConventions.validateRubyScriptName(fName).getSeverity() == IStatus.ERROR) {
+ return new RubyModelStatus(IRubyModelStatusConstants.INVALID_NAME, fName);
+ }
+ if (fSource == null) {
+ return new RubyModelStatus(IRubyModelStatusConstants.INVALID_CONTENTS);
+ }
+ return RubyModelStatus.VERIFIED_OK;
+}
+}
Added: 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 (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CreateSourceFolderOperation.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * 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.core;
+
+import java.util.ArrayList;
+
+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;
+import org.rubypeople.rdt.core.IRubyModelStatusConstants;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.ISourceFolder;
+import org.rubypeople.rdt.core.RubyConventions;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.core.util.CharOperation;
+import org.rubypeople.rdt.internal.core.util.Messages;
+import org.rubypeople.rdt.internal.core.util.Util;
+
+/**
+ * This operation creates a new package fragment under a given package fragment root.
+ * The following must be specified: <ul>
+ * <li>the package fragment root
+ * <li>the package name
+ * </ul>
+ * <p>Any needed folders/package fragments are created.
+ * If the package fragment already exists, this operation has no effect.
+ * The result elements include the <code>IPackageFragment</code> created and any side effect
+ * package fragments that were created.
+ *
+ * <p>NOTE: A default package fragment exists by default for a given root.
+ *
+ * <p>Possible exception conditions: <ul>
+ * <li>Package fragment root is read-only
+ * <li>Package fragment's name is taken by a simple (non-folder) resource
+ * </ul>
+ */
+public class CreateSourceFolderOperation extends RubyModelOperation {
+ /**
+ * The fully qualified, dot-delimited, package name.
+ */
+ protected String[] pkgName;
+/**
+ * When executed, this operation will create a package fragment with the given name
+ * under the given package fragment root. The dot-separated name is broken into
+ * segments. Intermediate folders are created as required for each segment.
+ * If the folders already exist, this operation has no effect.
+ */
+public CreateSourceFolderOperation(IRubyProject parentElement, String packageName, boolean force) {
+ super(null, new IRubyElement[]{parentElement}, force);
+ this.pkgName = packageName == null ? null : Util.getTrimmedSimpleNames(packageName);
+}
+/**
+ * Execute the operation - creates the new package fragment and any
+ * side effect package fragments.
+ *
+ * @exception RubyModelException if the operation is unable to complete
+ */
+protected void executeOperation() throws RubyModelException {
+ RubyElementDelta delta = null;
+ RubyProject root = (RubyProject) getParentElement();
+ beginTask(Messages.operation_createPackageFragmentProgress, this.pkgName.length);
+ IContainer parentFolder = (IContainer) root.getResource();
+ String[] sideEffectPackageName = CharOperation.NO_STRINGS;
+ ArrayList results = new ArrayList(this.pkgName.length);
+ int i;
+ for (i = 0; i < this.pkgName.length; i++) {
+ String subFolderName = this.pkgName[i];
+ sideEffectPackageName = Util.arrayConcat(sideEffectPackageName, subFolderName);
+ IResource subFolder = parentFolder.findMember(subFolderName);
+ if (subFolder == null) {
+ createFolder(parentFolder, subFolderName, force);
+ parentFolder = parentFolder.getFolder(new Path(subFolderName));
+ ISourceFolder addedFrag = root.getSourceFolder(sideEffectPackageName);
+ if (delta == null) {
+ delta = newRubyElementDelta();
+ }
+ delta.added(addedFrag);
+ results.add(addedFrag);
+ } else {
+ parentFolder = (IContainer) subFolder;
+ }
+ worked(1);
+ }
+ if (results.size() > 0) {
+ this.resultElements = new IRubyElement[results.size()];
+ results.toArray(this.resultElements);
+ if (delta != null) {
+ addDelta(delta);
+ }
+ }
+ done();
+}
+/**
+ * Possible failures: <ul>
+ * <li>NO_ELEMENTS_TO_PROCESS - the root supplied to the operation is
+ * <code>null</code>.
+ * <li>INVALID_NAME - the name provided to the operation
+ * is <code>null</code> or is not a valid package fragment name.
+ * <li>READ_ONLY - the root provided to this operation is read only.
+ * <li>NAME_COLLISION - there is a pre-existing resource (file)
+ * with the same name as a folder in the package fragment's hierarchy.
+ * <li>ELEMENT_NOT_PRESENT - the underlying resource for the root is missing
+ * </ul>
+ * @see IRubyModelStatus
+ * @see RubyConventions
+ */
+public IRubyModelStatus verify() {
+ if (getParentElement() == null) {
+ return new RubyModelStatus(IRubyModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
+ }
+
+ String packageName = this.pkgName == null ? null : Util.concatWith(this.pkgName, '/');
+ if (this.pkgName == null) {
+ return new RubyModelStatus(IRubyModelStatusConstants.INVALID_NAME, packageName);
+ }
+ IRubyProject root = (IRubyProject) getParentElement();
+ if (root.isReadOnly()) {
+ return new RubyModelStatus(IRubyModelStatusConstants.READ_ONLY, root);
+ }
+ IContainer parentFolder = (IContainer) root.getResource();
+ int i;
+ for (i = 0; i < this.pkgName.length; i++) {
+ IResource subFolder = parentFolder.findMember(this.pkgName[i]);
+ if (subFolder != null) {
+ if (subFolder.getType() != IResource.FOLDER) {
+ return new RubyModelStatus(
+ IRubyModelStatusConstants.NAME_COLLISION,
+ Messages.bind(Messages.status_nameCollision, subFolder.getFullPath().toString()));
+ }
+ parentFolder = (IContainer) subFolder;
+ }
+ }
+ return RubyModelStatus.VERIFIED_OK;
+}
+}
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:29:19 UTC (rev 1704)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/Openable.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -10,6 +10,8 @@
import java.util.Map;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.rubypeople.rdt.core.BufferChangedEvent;
@@ -339,6 +341,19 @@
}
/**
+ * Returns whether the corresponding resource or associated file exists
+ */
+ protected boolean resourceExists() {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ if (workspace == null) return false; // workaround for http://bugs.eclipse.org/bugs/show_bug.cgi?id=34069
+ return
+ RubyModel.getTarget(
+ workspace.getRoot(),
+ this.getPath().makeRelative(), // ensure path is relative (see http://dev.eclipse.org/bugs/show_bug.cgi?id=22517)
+ true) != null;
+ }
+
+ /**
* @see IOpenable
*/
public void open(IProgressMonitor pm) throws RubyModelException {
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyElement.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyElement.java 2006-12-15 15:29:19 UTC (rev 1704)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyElement.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -30,6 +30,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.PlatformObject;
+import org.jruby.ast.Node;
import org.rubypeople.rdt.core.IField;
import org.rubypeople.rdt.core.IOpenable;
import org.rubypeople.rdt.core.IParent;
@@ -524,4 +525,8 @@
protected void toStringName(StringBuffer buffer) {
buffer.append(getElementName());
}
+
+ public Node findNode(Node cuAST) {
+ return null; // works only inside a ruby script
+ }
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModel.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModel.java 2006-12-15 15:29:19 UTC (rev 1704)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModel.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -4,9 +4,12 @@
*/
package org.rubypeople.rdt.internal.core;
+import java.io.File;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.Map;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@@ -28,9 +31,31 @@
*/
public class RubyModel extends Openable implements IRubyModel {
+ /**
+ * A set of java.io.Files used as a cache of external jars that
+ * are known to be existing.
+ * Note this cache is kept for the whole session.
+ */
+ public static HashSet existingExternalFiles = new HashSet();
+
+ /**
+ * A set of external files ({@link #existingExternalFiles}) which have
+ * been confirmed as file (ie. which returns true to {@link java.io.File#isFile()}.
+ * Note this cache is kept for the whole session.
+ */
+ public static HashSet existingExternalConfirmedFiles = new HashSet();
+
protected RubyModel() {
super(null);
}
+
+ /**
+ * Flushes the cache of external files known to be existing.
+ */
+ public static void flushExternalFileCache() {
+ existingExternalFiles = new HashSet();
+ existingExternalConfirmedFiles = new HashSet();
+ }
/**
* Returns a new element info for this element.
@@ -118,11 +143,7 @@
}
- protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) /*
- * throws
- * RubyModelException
- */{
-
+ protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) {
// determine my children
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (int i = 0, max = projects.length; i < max; i++) {
@@ -163,4 +184,50 @@
return new RubyProject(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName), this);
}
+ /**
+ * Helper method - returns the targeted item (IResource if internal or java.io.File if external),
+ * or null if unbound
+ * Internal items must be referred to using container relative paths.
+ */
+public static Object getTarget(IContainer container, IPath path, boolean checkResourceExistence) {
+
+ if (path == null) return null;
+
+ // lookup - inside the container
+ if (path.getDevice() == null) { // container relative paths should not contain a device
+ // (see http://dev.eclipse.org/bugs/show_bug.cgi?id=18684)
+ // (case of a workspace rooted at d:\ )
+ IResource resource = container.findMember(path);
+ if (resource != null){
+ if (!checkResourceExistence ||resource.exists()) return resource;
+ return null;
+ }
+ }
+
+ // if path is relative, it cannot be an external path
+ // (see http://dev.eclipse.org/bugs/show_bug.cgi?id=22517)
+ if (!path.isAbsolute()) return null;
+
+ // lookup - outside the container
+ return getTargetAsExternalFile(path, checkResourceExistence);
}
+private synchronized static Object getTargetAsExternalFile(IPath path, boolean checkResourceExistence) {
+ File externalFile = new File(path.toOSString());
+ if (!checkResourceExistence) {
+ return externalFile;
+ } else if (existingExternalFiles.contains(externalFile)) {
+ return externalFile;
+ } else {
+ if (RubyModelManager.ZIP_ACCESS_VERBOSE) {
+ System.out.println("(" + Thread.currentThread() + ") [RubyModel.getTarget(...)] Checking existence of " + path.toString()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (externalFile.exists()) {
+ // cache external file
+ existingExternalFiles.add(externalFile);
+ return externalFile;
+ }
+ }
+ return null;
+}
+
+}
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:29:19 UTC (rev 1704)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelManager.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -42,6 +42,7 @@
import org.rubypeople.rdt.internal.core.buffer.BufferManager;
import org.rubypeople.rdt.internal.core.builder.RubyBuilder;
import org.rubypeople.rdt.internal.core.util.Util;
+import org.rubypeople.rdt.internal.core.util.WeakHashSet;
/**
* @author cawilliams
@@ -113,14 +114,18 @@
private static boolean verbose = false;
public static boolean CP_RESOLVE_VERBOSE = false;
+ public static boolean ZIP_ACCESS_VERBOSE = false;
// Preferences
HashSet optionNames = new HashSet(20);
Hashtable optionsCache;
public final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2];
+ private WeakHashSet stringSymbols = new WeakHashSet(5);
static final int PREF_INSTANCE = 0;
static final int PREF_DEFAULT = 1;
+
+ public static final IRubyScript[] NO_WORKING_COPY = new IRubyScript[0];
/**
* Update the classpath variable cache
@@ -740,7 +745,9 @@
case IResource.FILE :
return create((IFile) resource, project);
case IResource.FOLDER :
+// System.err.println("Tried to create a RubyElement for: " + resource.getFullPath().toOSString());
return create((IFolder) resource, project);
+// return null;
case IResource.ROOT :
return RubyCore.create((IWorkspaceRoot) resource);
default :
@@ -748,6 +755,68 @@
}
}
+ /**
+ * Returns the package fragment or package fragment root corresponding to the given folder,
+ * its parent or great parent being the given project.
+ * or <code>null</code> if unable to associate the given folder with a Java element.
+ * <p>
+ * Note that a package fragment root is returned rather than a default package.
+ * <p>
+ * Creating a Java element has the side effect of creating and opening all of the
+ * element's parents if they are not yet open.
+ */
+ public static IRubyElement create(IFolder folder, IRubyProject project) {
+ if (folder == null) {
+ return null;
+ }
+ IRubyElement element;
+ if (project == null) {
+ project = RubyCore.create(folder.getProject());
+
+ element = determineIfOnLoadpath(folder, project);
+ if (element == null) {
+ // walk all projects and find one that have the given folder on the load path
+ IRubyProject[] projects;
+ try {
+ projects = RubyModelManager.getRubyModelManager().getRubyModel().getRubyProjects();
+ } catch (RubyModelException e) {
+ return null;
+ }
+ for (int i = 0, length = projects.length; i < length; i++) {
+ project = projects[i];
+ element = determineIfOnLoadpath(folder, project);
+ if (element != null)
+ break;
+ }
+ }
+ } else {
+ element = determineIfOnLoadpath(folder, project);
+ }
+
+ return element;
+ }
+
+ private static IRubyElement determineIfOnLoadpath(IResource resource,
+ IRubyProject project) {
+ // TODO Actually take load paths into account
+ IPath resourcePath = resource.getFullPath();
+ IPath rootPath = project.getPath();
+ if (rootPath.equals(resourcePath)) {
+ return project.getSourceFolder(resource);
+ } else if (rootPath.isPrefixOf(resourcePath)) {
+ IPath pkgPath = resourcePath.removeFirstSegments(rootPath.segmentCount());
+
+ if (resource.getType() == IResource.FILE) {
+ // if the resource is a file, then remove the last segment which
+ // is the file name in the package
+ pkgPath = pkgPath.removeLastSegments(1);
+ }
+ String[] pkgName = pkgPath.segments();
+ return project.getSourceFolder(pkgName);
+ }
+ return null;
+ }
+
public static IRubyElement create(IFile file, IRubyProject project) {
if (file == null) {
return null;
@@ -772,5 +841,57 @@
}
return project.getRubyScript(file);
}
+
+ /*
+ * Returns all the working copies which have the given owner.
+ * Adds the working copies of the primary owner if specified.
+ * Returns null if it has none.
+ */
+ public IRubyScript[] getWorkingCopies(WorkingCopyOwner owner, boolean addPrimary) {
+ synchronized(this.perWorkingCopyInfos) {
+ IRubyScript[] primaryWCs = addPrimary && owner != DefaultWorkingCopyOwner.PRIMARY
+ ? getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY, false)
+ : null;
+ Map workingCopyToInfos = (Map)this.perWorkingCopyInfos.get(owner);
+ if (workingCopyToInfos == null) return primaryWCs;
+ int primaryLength = primaryWCs == null ? 0 : primaryWCs.length;
+ int size = workingCopyToInfos.size(); // note size is > 0 otherwise pathToPerWorkingCopyInfos would be null
+ IRubyScript[] result = new IRubyScript[primaryLength + size];
+ int index = 0;
+ if (primaryWCs != null) {
+ for (int i = 0; i < primaryLength; i++) {
+ IRubyScript primaryWorkingCopy = primaryWCs[i];
+ IRubyScript workingCopy = new RubyScript((SourceFolder) primaryWorkingCopy.getParent(), (IFile) primaryWorkingCopy.getResource(), primaryWorkingCopy.getElementName(), owner);
+ if (!workingCopyToInfos.containsKey(workingCopy))
+ result[index++] = primaryWorkingCopy;
+ }
+ if (index != primaryLength)
+ System.arraycopy(result, 0, result = new IRubyScript[index+size], 0, index);
+ }
+ Iterator iterator = workingCopyToInfos.values().iterator();
+ while(iterator.hasNext()) {
+ result[index++] = ((RubyModelManager.PerWorkingCopyInfo)iterator.next()).getWorkingCopy();
+ }
+ return result;
+ }
+ }
+ public synchronized String intern(String s) {
+ // make sure to copy the string (so that it doesn't hold on the underlying char[] that might be much bigger than necessary)
+ return (String) this.stringSymbols.add(new String(s));
+
+ // Note1: String#intern() cannot be used as on some VMs this prevents the string from being garbage collected
+ // Note 2: Instead of using a WeakHashset, one could use a WeakHashMap with the following implementation
+ // This would costs more per entry (one Entry object and one WeakReference more))
+
+ /*
+ WeakReference reference = (WeakReference) this.symbols.get(s);
+ String existing;
+ if (reference != null && (existing = (String) reference.get()) != null)
+ return existing;
+ this.symbols.put(s, new WeakReference(s));
+ return s;
+ */
+ }
+
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelOperation.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelOperation.java 2006-12-15 15:29:19 UTC (rev 1704)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelOperation.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -382,7 +382,7 @@
* or the element itself (if it is a compilation unit),
* otherwise <code>null</code>.
*/
- protected IRubyScript getRubyScripttFor(IRubyElement element) {
+ protected IRubyScript getRubyScriptFor(IRubyElement element) {
return ((RubyElement)element).getRubyScript();
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java 2006-12-15 15:29:19 UTC (rev 1704)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -16,6 +16,7 @@
import javax.xml.parsers.SAXParserFactory;
import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
@@ -33,12 +34,16 @@
import org.rubypeople.rdt.core.ILoadpathEntry;
import org.rubypeople.rdt.core.IParent;
import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyModelStatusConstants;
import org.rubypeople.rdt.core.IRubyProject;
import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.ISourceFolder;
import org.rubypeople.rdt.core.IType;
import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.core.builder.ProjectFileFinder;
+import org.rubypeople.rdt.internal.core.util.CharOperation;
+import org.rubypeople.rdt.internal.core.util.Util;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
@@ -84,7 +89,14 @@
public boolean upgrade() throws CoreException {
return addToBuildSpec(RubyCore.BUILDER_ID);
}
+
+ public ISourceFolder createSourceFolder(String pkgName, boolean force, IProgressMonitor monitor) throws RubyModelException {
+ CreateSourceFolderOperation op = new CreateSourceFolderOperation(this, pkgName, force);
+ op.runOperation(monitor);
+ return getSourceFolder(op.pkgName);
+ }
+
/**
* Adds a builder to the build spec for the given project.
*/
@@ -513,20 +525,95 @@
return false;
}
- /**
- * @see Openable
- */
- protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm,
- Map newElements, IResource underlyingResource) throws RubyModelException {
- // check whether the ruby project can be opened
- if (!underlyingResource.isAccessible()) { throw newNotPresentException(); }
+ /**
+ * @see Openable
+ */
+ protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws RubyModelException {
+
+ // check whether the ruby project can be opened
+ if (!hasRubyNature((IProject) underlyingResource)) {
+ throw newNotPresentException();
+ }
+ // check whether this project can be opened
+ if (!resourceExists()) throw newNotPresentException();
- // Find all the scripts in this project
- info.setChildren(getScripts());
- return true;
- }
+ return computeChildren(info, newElements);
+ }
+
+ /**
+ * Compute the package fragment children of this package fragment root.
+ *
+ * @exception JavaModelException The resource associated with this package fragment root does not exist
+ */
+ protected boolean computeChildren(OpenableElementInfo info, Map newElements) throws RubyModelException {
+ try {
+ // the underlying resource may be a folder or a project (in the case that the project folder
+ // is actually the source folder root)
+ IResource underlyingResource = getResource();
+ if (underlyingResource.getType() == IResource.FOLDER || underlyingResource.getType() == IResource.PROJECT) {
+ ArrayList vChildren = new ArrayList(5);
+ IContainer rootFolder = (IContainer) underlyingResource;
+ computeFolderChildren(rootFolder, CharOperation.NO_STRINGS, vChildren);
+ IRubyElement[] children = new IRubyElement[vChildren.size()];
+ vChildren.toArray(children);
+ info.setChildren(children);
+ }
+ } catch (RubyModelException e) {
+ //problem resolving children; structure remains unknown
+ info.setChildren(new IRubyElement[]{});
+ throw e;
+ }
+ return true;
+ }
+
+ /**
+ * Starting at this folder, create package fragments and add the fragments that are not exclused
+ * to the collection of children.
+ *
+ * @exception RubyModelException The resource associated with this package fragment does not exist
+ */
+ protected void computeFolderChildren(IContainer folder, String[] pkgName, ArrayList vChildren) throws RubyModelException {
+ // Don't add yourself as a child
+// ISourceFolder pkg = getSourceFolder(pkgName);
+// vChildren.add(pkg);
- /**
+ try {
+ RubyProject javaProject = (RubyProject)getRubyProject();
+ RubyModelManager manager = RubyModelManager.getRubyModelManager();
+ IResource[] members = folder.members();
+
+ for (int i = 0, max = members.length; i < max; i++) {
+ IResource member = members[i];
+ String memberName = member.getName();
+
+ switch(member.getType()) {
+ case IResource.FOLDER:
+ if (javaProject.contains(member)) {
+ String[] newNames = Util.arrayConcat(pkgName, manager.intern(memberName));
+// computeFolderChildren((IFolder) member, newNames, vChildren);
+ ISourceFolder child = getSourceFolder(newNames);
+ vChildren.add(child);
+ }
+
+ break;
+ case IResource.FILE:
+ // inclusion filter may only include files, in which case we still want to include the immediate parent package (lazily)
+ break;
+ }
+ }
+ } catch(IllegalArgumentException e){
+ throw new RubyModelException(e, IRubyModelStatusConstants.ELEMENT_DOES_NOT_EXIST); // could be thrown by ElementTree when path is not found
+ } catch (CoreException e) {
+ throw new RubyModelException(e);
+ }
+ }
+
+ public boolean contains(IResource resource) {
+ // XXX Check the paths to see if this is true or not!
+ return true;
+ }
+
+ /**
* @return
*/
private IRubyElement[] getScripts() {
@@ -727,12 +814,44 @@
}
public boolean isOnLoadpath(IRubyScript element) {
- // TODO We cheat and assume all scripts are on loadpath. Thsi may not be true. We shoudl check!
+ // TODO We cheat and assume all scripts are on loadpath. This may not be true. We should check!
return true;
}
public IRubyScript getRubyScript(IFile file) {
return new RubyScript(this, file, file.getName(), DefaultWorkingCopyOwner.PRIMARY);
}
+
+ public ISourceFolder getSourceFolder(String[] names) {
+ return new SourceFolder(this, names);
+ }
+
+ public ISourceFolder getSourceFolder(IResource resource) {
+ switch (resource.getType()) {
+ case IResource.FILE:
+ return null;
+ case IResource.FOLDER:
+ return new SourceFolder(this, resource.getProjectRelativePath().segments());
+ case IResource.PROJECT:
+ return new SourceFolder(this, resource.getProjectRelativePath().segments());
+ default:
+ return null;
+ }
+ }
+
+ public ISourceFolder[] getSourceFolders() throws RubyModelException {
+ Object[] children;
+ int length;
+ ISourceFolder[] roots;
+
+ System.arraycopy(
+ children = getChildren(),
+ 0,
+ roots = new ISourceFolder[length = children.length],
+ 0,
+ length);
+
+ return roots;
+ }
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptStructureBuilder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptStructureBuilder.java 2006-12-15 15:29:19 UTC (rev 1704)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptStructureBuilder.java 2006-12-15 15:31:22 UTC (rev 1705)
@@ -35,7 +35,6 @@
import org.jruby.ast.AndNode;
im...
[truncated message content] |
|
From: <caw...@us...> - 2006-12-15 15:29:20
|
Revision: 1704
http://svn.sourceforge.net/rubyeclipse/?rev=1704&view=rev
Author: cawilliams
Date: 2006-12-15 07:29:19 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
add a new test case wizard
Modified Paths:
--------------
trunk/org.rubypeople.rdt.testunit/plugin.properties
trunk/org.rubypeople.rdt.testunit/plugin.xml
Modified: trunk/org.rubypeople.rdt.testunit/plugin.properties
===================================================================
--- trunk/org.rubypeople.rdt.testunit/plugin.properties 2006-12-15 15:29:06 UTC (rev 1703)
+++ trunk/org.rubypeople.rdt.testunit/plugin.properties 2006-12-15 15:29:19 UTC (rev 1704)
@@ -10,4 +10,6 @@
testRunTabs.name= Test Run Tabs
TestUnitShortcut.description.run= Run Test::Unit Test
-TestUnitShortcut.description.debug= Debug Test::Unit Test
\ No newline at end of file
+TestUnitShortcut.description.debug= Debug Test::Unit Test
+
+NewWizardRubyTestCase.name=Test::Unit Test Case
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.testunit/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.testunit/plugin.xml 2006-12-15 15:29:06 UTC (rev 1703)
+++ trunk/org.rubypeople.rdt.testunit/plugin.xml 2006-12-15 15:29:19 UTC (rev 1704)
@@ -2,11 +2,11 @@
<?eclipse version="3.0"?>
<plugin>
- <extension-point id="internalTestRunTabs" name="%testRunTabs.name" schema="schema/internal-testRunTabs.exsd"/>
+ <extension-point id="internalTestRunTabs" name="%testRunTabs.name" schema="schema/internal_testRunTabs.exsd"/>
<extension point="org.rubypeople.rdt.testunit.internalTestRunTabs">
- <testRunTab class="org.rubypeople.rdt.testunit.views.FailureTab"/>
- <testRunTab class="org.rubypeople.rdt.testunit.views.TestHierarchyTab"/>
+ <testRunTab class="org.rubypeople.rdt.internal.testunit.ui.FailureTab"/>
+ <testRunTab class="org.rubypeople.rdt.internal.testunit.ui.TestHierarchyTab"/>
</extension>
<extension
point="org.eclipse.ui.views">
@@ -14,7 +14,7 @@
name="Test::Unit"
icon="icons/full/eview16/testunit.gif"
category="org.rubypeople.rdt.ui.ruby"
- class="org.rubypeople.rdt.testunit.views.TestUnitView"
+ class="org.rubypeople.rdt.internal.testunit.ui.TestUnitView"
id="org.rubypeople.rdt.testunit.views.TestUnitView">
</view>
</extension>
@@ -100,7 +100,7 @@
<launchConfigurationTabGroup
type="org.rubypeople.rdt.testunit.launchconfig"
helpContextId="org.rubypeople.rdt.testunit.testunit_tab_group"
- class="org.rubypeople.rdt.testunit.launcher.TestUnitTabGroup"
+ class="org.rubypeople.rdt.internal.testunit.launcher.TestUnitTabGroup"
id="org.rubypeople.rdt.testunit.launchConfigurationTabGroup.testunit">
<launchMode
perspective="org.eclipse.debug.ui.DebugPerspective"
@@ -138,4 +138,19 @@
commandId="org.rubypeople.rdt.testunit.testunitShortcut.run"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
</extension>
+
+ <extension
+ point="org.eclipse.ui.newWizards">
+ <wizard
+ name="%NewWizardRubyTestCase.name"
+ icon="$nl$/icons/full/etool16/new_testcase.gif"
+ category="org.rubypeople.rdt.ui"
+ class="org.rubypeople.rdt.internal.testunit.wizards.NewTestCaseCreationWizard"
+ preferredPerspectives="org.rubypeople.rdt.ui.PerspectiveRuby"
+ id="org.rubypeople.rdt.testunit.wizards.RubyNewTestCaseWizard">
+ <description>
+ Create a new Ruby Test::Unit Test Case.
+ </description>
+ </wizard>
+ </extension>
</plugin>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-15 15:29:08
|
Revision: 1703
http://svn.sourceforge.net/rubyeclipse/?rev=1703&view=rev
Author: cawilliams
Date: 2006-12-15 07:29:06 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
add a new test case wizard
Added Paths:
-----------
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/MethodStubsSelectionButtonGroup.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/NewTestCaseCreationWizard.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/WizardMessages.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/WizardMessages.properties
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/MethodStubsSelectionButtonGroup.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/MethodStubsSelectionButtonGroup.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/MethodStubsSelectionButtonGroup.java 2006-12-15 15:29:06 UTC (rev 1703)
@@ -0,0 +1,419 @@
+/*******************************************************************************
+ * 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.testunit.wizards;
+
+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.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.rubypeople.rdt.internal.testunit.util.LayoutUtil;
+
+
+/**
+ * A group of controls used in the JUnit TestCase and TestSuite wizards
+ * for selecting method stubs to create.
+ */
+public class MethodStubsSelectionButtonGroup {
+
+ private Label fLabel;
+ protected String fLabelText;
+
+ private SelectionButtonGroupListener fGroupListener;
+
+ private boolean fEnabled;
+
+ private Composite fButtonComposite;
+
+ private Button[] fButtons;
+ private String[] fButtonNames;
+ private boolean[] fButtonsSelected;
+ private boolean[] fButtonsEnabled;
+
+ private int fGroupBorderStyle;
+ private int fGroupNumberOfColumns;
+ private int fButtonsStyle;
+
+
+ public interface SelectionButtonGroupListener {
+ /**
+ * The dialog field has changed.
+ * @param field The changed dialog field
+ */
+ void groupChanged(MethodStubsSelectionButtonGroup field);
+ }
+
+ /**
+ * Creates a group without border.
+ */
+ public MethodStubsSelectionButtonGroup(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 MethodStubsSelectionButtonGroup(int buttonsStyle, String[] buttonNames, int nColumns, int borderStyle) {
+ fEnabled= true;
+ fLabel= null;
+ fLabelText= ""; //$NON-NLS-1$
+
+ Assert.isTrue(buttonsStyle == SWT.RADIO || buttonsStyle == SWT.CHECK || buttonsStyle == SWT.TOGGLE);
+ fButtonNames= buttonNames;
+
+ 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;
+
+ fButtonsStyle= buttonsStyle;
+ }
+
+ /*
+ * @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;
+ }
+
+ 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() && isEnabled(index));
+ button.setSelection(isSelected(index));
+ button.addSelectionListener(listener);
+ return button;
+ }
+
+
+ /**
+ * Returns the group widget. When called the first time, the widget will be created.
+ * @param 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);
+ if (fLabelText != null && fLabelText.length() > 0) {
+ group.setText(fLabelText);
+ }
+ fButtonComposite= group;
+ } else {
+ fButtonComposite= new Composite(parent, SWT.NULL);
+ 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);
+ }
+ setSelectionGroupListener(new SelectionButtonGroupListener() {
+ public void groupChanged(MethodStubsSelectionButtonGroup field) {
+ field.setEnabled(1, isEnabled() && field.isSelected(0));
+ }
+ });
+ }
+ 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;
+ }
+ }
+ }
+
+ /**
+ * Returns the selection state of a button contained in the group.
+ * @param index of the button
+ */
+ public boolean isSelected(int index) {
+ if (index >= 0 && index < fButtonsSelected.length) {
+ return fButtonsSelected[index] && fButtonsEnabled[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.isEnabled()) {
+ button.setSelection(selected);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns the enabled state of a button contained in the group.
+ * @param index of the button
+ */
+ public boolean isEnabled(int index) {
+ if (index >= 0 && index < fButtonsEnabled.length) {
+ return fButtonsEnabled[index];
+ }
+ return false;
+ }
+
+ /**
+ * Sets the selection state of a button contained in the group.
+ */
+ public void setEnabled(int index, boolean enabled) {
+ if (index >= 0 && index < fButtonsEnabled.length) {
+ if (fButtonsEnabled[index] != enabled) {
+ fButtonsEnabled[index]= enabled;
+ if (fButtons != null) {
+ Button button= fButtons[index];
+ if (isOkToUse(button)) {
+ button.setEnabled(enabled);
+ if (!enabled) {
+ button.setSelection(false);
+ } else {
+ button.setSelection(fButtonsSelected[index]);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ protected void updateEnableState() {
+ if (fLabel != null) {
+ fLabel.setEnabled(fEnabled);
+ }
+ 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 label of the dialog field.
+ */
+ public void setLabelText(String labeltext) {
+ fLabelText= labeltext;
+ }
+
+ /**
+ * Defines the listener for this dialog field.
+ */
+ public final void setSelectionGroupListener(SelectionButtonGroupListener listener) {
+ fGroupListener= listener;
+ }
+
+ /**
+ * A dialog field has changed.
+ */
+ public void dialogFieldChanged() {
+ if (fGroupListener != null) {
+ fGroupListener.groupChanged(this);
+ }
+ }
+
+ /**
+ * Tries to set the focus to the dialog field.
+ * Returns <code>true</code> if the dialog field can take focus.
+ * To be re-implemented by dialog field implementors.
+ */
+ public boolean setFocus() {
+ return false;
+ }
+
+ /**
+ * Posts <code>setFocus</code> to the display event queue.
+ */
+ public void postSetFocusOnDialogField(Display display) {
+ if (display != null) {
+ display.asyncExec(
+ new Runnable() {
+ public void run() {
+ setFocus();
+ }
+ }
+ );
+ }
+ }
+
+ protected static GridData gridDataForLabel(int span) {
+ GridData gd= new GridData();
+ gd.horizontalSpan= span;
+ return gd;
+ }
+
+ /**
+ * Creates or returns the created label widget.
+ * @param parent The parent composite or <code>null</code> if the widget has
+ * already been created.
+ */
+ public Label getLabelControl(Composite parent) {
+ if (fLabel == null) {
+ assertCompositeNotNull(parent);
+
+ fLabel= new Label(parent, SWT.LEFT | SWT.WRAP);
+ fLabel.setFont(parent.getFont());
+ fLabel.setEnabled(fEnabled);
+ if (fLabelText != null && !"".equals(fLabelText)) { //$NON-NLS-1$
+ fLabel.setText(fLabelText);
+ } else {
+ // XXX: to avoid a 16 pixel wide empty label - revisit
+ fLabel.setText("."); //$NON-NLS-1$
+ fLabel.setVisible(false);
+ }
+ }
+ return fLabel;
+ }
+
+ /**
+ * Creates a spacer control.
+ * @param parent The parent composite
+ */
+ public static Control createEmptySpace(Composite parent) {
+ return createEmptySpace(parent, 1);
+ }
+
+ /**
+ * Creates a spacer control with the given span.
+ * The composite is assumed to have <code>MGridLayout</code> as
+ * layout.
+ * @param parent The parent composite
+ */
+ public static Control createEmptySpace(Composite parent, int span) {
+ return LayoutUtil.createEmptySpace(parent, span);
+ }
+
+ /**
+ * Tests is the control is not <code>null</code> and not disposed.
+ */
+ protected final boolean isOkToUse(Control control) {
+ return (control != null) && !(control.isDisposed());
+ }
+
+ // --------- enable / disable management
+
+ /**
+ * Sets the enable state of the dialog field.
+ */
+ public final void setEnabled(boolean enabled) {
+ if (enabled != fEnabled) {
+ fEnabled= enabled;
+ updateEnableState();
+ }
+ }
+
+ /**
+ * Gets the enable state of the dialog field.
+ */
+ public final boolean isEnabled() {
+ return fEnabled;
+ }
+
+ protected final void assertCompositeNotNull(Composite comp) {
+ Assert.isNotNull(comp, "uncreated control requested with composite null"); //$NON-NLS-1$
+ }
+
+ protected final void assertEnoughColumns(int nColumns) {
+ Assert.isTrue(nColumns >= getNumberOfControls(), "given number of columns is too small"); //$NON-NLS-1$
+ }
+}
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/NewTestCaseCreationWizard.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/NewTestCaseCreationWizard.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/NewTestCaseCreationWizard.java 2006-12-15 15:29:06 UTC (rev 1703)
@@ -0,0 +1,252 @@
+package org.rubypeople.rdt.internal.testunit.wizards;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+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.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+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.IWorkbenchWizard;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.core.formatter.Indents;
+import org.rubypeople.rdt.internal.testunit.ui.TestunitPlugin;
+import org.rubypeople.rdt.internal.ui.RubyPluginImages;
+import org.rubypeople.rdt.internal.ui.actions.WorkbenchRunnableAdapter;
+import org.rubypeople.rdt.internal.ui.util.ExceptionHandler;
+import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
+import org.rubypeople.rdt.testunit.wizards.RubyNewTestCaseWizardPage;
+
+public class NewTestCaseCreationWizard extends Wizard implements INewWizard {
+
+ private static final String RUBY_FILE_EXTENSION = ".rb";
+ private RubyNewTestCaseWizardPage page;
+ private IStructuredSelection selection;
+
+ /**
+ * Constructor for SampleNewWizard.
+ */
+ public NewTestCaseCreationWizard() {
+ super();
+ setWindowTitle(WizardMessages.Wizard_title_new_testcase);
+ setDefaultPageImageDescriptor(RubyPluginImages.DESC_WIZBAN_NEWCLASS);
+ setNeedsProgressMonitor(true);
+ }
+
+ /**
+ * Adding the page to the wizard.
+ */
+
+ public void addPages() {
+ page = new RubyNewTestCaseWizardPage(selection);
+ page.init(selection);
+ addPage(page);
+ }
+
+ /**
+ * This method is called when 'Finish' button is pressed in the wizard. We
+ * will create an operation and run it using wizard as execution context.
+ */
+ 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 boolean canRunForked() {
+ return true;
+ }
+
+ /**
+ * Returns the scheduling rule for creating the element.
+ */
+ protected ISchedulingRule getSchedulingRule() {
+ return ResourcesPlugin.getWorkspace().getRoot(); // look all by default
+ }
+
+ 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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
+ page.createType(monitor); // use the full progress monitor
+ }
+
+ /**
+ * The worker method. It will find the container, create the file if missing
+ * or just replace its contents, and open the editor on the newly created
+ * file.
+ * @param superclassName
+ */
+
+ private void doFinish(String containerName, String className, String superclassName, IProgressMonitor monitor)
+ throws CoreException {
+ // create a sample file
+ monitor.beginTask("Creating " + className, 2);
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IResource resource = root.findMember(new Path(containerName));
+ if (!resource.exists() || !(resource instanceof IContainer)) {
+ throwCoreException("Container \"" + containerName + "\" does not exist.");
+ }
+ IContainer container = (IContainer) resource;
+ String fileName = classNameToFileName(className) + RUBY_FILE_EXTENSION;
+
+ final IFile file = container.getFile(new Path(fileName));
+ try {
+ InputStream stream = openContentStream(className, superclassName);
+ if (file.exists()) {
+ file.setContents(stream, true, true, monitor);
+ } else {
+ file.create(stream, true, monitor);
+ }
+ stream.close();
+ } catch (IOException e) {
+ }
+ monitor.worked(1);
+ monitor.setTaskName("Opening file for editing...");
+ getShell().getDisplay().asyncExec(new Runnable() {
+
+ public void run() {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage();
+ try {
+ IDE.openEditor(page, file, true);
+ } catch (PartInitException e) {
+ }
+ }
+ });
+ monitor.worked(1);
+ }
+
+ /**
+ * Convert a Constant Class Name (in camels) to a file name (all lowercase,
+ * uppercase characters get downcased and have underscores put in front,
+ * except first character.)
+ *
+ * @param className
+ * @return
+ */
+ private String classNameToFileName(String className) {
+ className = stripNamespace(className);
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0; i < className.length(); i++) {
+ char c = className.charAt(i);
+ if (Character.isUpperCase(c)) {
+ if (i != 0) buffer.append('_');
+ buffer.append(Character.toLowerCase(c));
+ } else {
+ buffer.append(c);
+ }
+ }
+ return buffer.toString();
+ }
+
+ private String stripNamespace(String className) {
+ if (className == null || className.length() == 0) return className;
+ if (className.lastIndexOf("::") != -1) {
+ return className.substring(className.lastIndexOf("::") + 2);
+ }
+ return className;
+ }
+
+ /**
+ * We will initialize file contents with a sample text.
+ *
+ * @param className
+ * The Filename chosen by the user
+ * @param superclassName
+ */
+
+ private InputStream openContentStream(String className, String superclassName) {
+ StringBuffer contents = new StringBuffer();
+ String endLine = System.getProperty("line.separator");
+ if (endLine == null) endLine = "\n";
+ contents.append("require 'test/unit'");
+ contents.append(endLine);
+
+ contents.append("class ");
+ contents.append(className);
+ contents.append(" < ");
+ contents.append(superclassName);
+ contents.append(endLine);
+
+ contents.append(Indents.createIndentString(1, RubyCore.getOptions()));
+ contents.append(endLine);
+
+ contents.append(Indents.createIndentString(1, RubyCore.getOptions()));
+ contents.append(endLine);
+
+ contents.append("end");
+ contents.append(endLine);
+ return new ByteArrayInputStream(contents.toString().getBytes());
+ }
+
+ private void throwCoreException(String message) throws CoreException {
+ IStatus status = new Status(IStatus.ERROR, TestunitPlugin.PLUGIN_ID, IStatus.OK, message, null);
+ throw new CoreException(status);
+ }
+
+ /**
+ * We will accept the selection in the workbench to see if we can initialize
+ * from it.
+ *
+ * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
+ */
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.selection = selection;
+ }
+}
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/WizardMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/WizardMessages.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/WizardMessages.java 2006-12-15 15:29:06 UTC (rev 1703)
@@ -0,0 +1,30 @@
+package org.rubypeople.rdt.internal.testunit.wizards;
+
+import org.eclipse.osgi.util.NLS;
+
+public class WizardMessages extends NLS {
+ private static final String BUNDLE_NAME = "org.rubypeople.rdt.internal.testunit.wizards.WizardMessages";//$NON-NLS-1$
+ public static String NewTestCaseWizardPage_title;
+ public static String NewTestCaseWizardPage_description;
+ public static String Wizard_title_new_testcase;
+
+ public static String NewTestCaseWizardPage_method_Stub_label;
+ public static String NewTestCaseWizardPage_methodStub_setUp;
+ public static String NewTestCaseWizardPage_methodStub_tearDown;
+ public static String NewTestCaseWizardPage_methodStub_constructor;
+ public static String NewTestCaseWizardPage_class_to_test_label;
+ public static String NewTestCaseWizardPage_class_to_test_browse;
+ public static String NewTestCaseWizardPage_class_to_test_dialog_title;
+ public static String NewTestCaseWizardPage_class_to_test_dialog_message;
+ public static String NewTestCaseWizardPage_error_class_to_test_not_valid;
+ public static String NewTestCaseWizardPage_error_class_to_test_not_exist;
+ public static String NewTestCaseWizardPage_warning_class_to_test_is_interface;
+
+ private WizardMessages() {
+ // Do not instantiate
+ }
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, WizardMessages.class);
+ }
+}
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/WizardMessages.properties
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/WizardMessages.properties (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/wizards/WizardMessages.properties 2006-12-15 15:29:06 UTC (rev 1703)
@@ -0,0 +1,16 @@
+NewTestCaseWizardPage_title=Test::Unit Test Case
+NewTestCaseWizardPage_description=This wizard creates a new Test::Unit Test case
+Wizard_title_new_testcase=New Test::Unit Test Case
+
+NewTestCaseWizardPage_method_Stub_label=Which method stubs would you like to create?
+NewTestCaseWizardPage_methodStub_setUp=set&Up()
+NewTestCaseWizardPage_methodStub_tearDown=&tearDown()
+NewTestCaseWizardPage_methodStub_constructor=&constructor
+
+NewTestCaseWizardPage_class_to_test_label=C&lass under test:
+NewTestCaseWizardPage_class_to_test_browse=B&rowse...
+NewTestCaseWizardPage_class_to_test_dialog_title=Class Under Test
+NewTestCaseWizardPage_class_to_test_dialog_message=Test stubs will be generated for class:
+NewTestCaseWizardPage_error_class_to_test_not_valid=Class under test is not valid.
+NewTestCaseWizardPage_error_class_to_test_not_exist=Class under test does not exist in current project.
+NewTestCaseWizardPage_warning_class_to_test_is_interface=Warning: Class under test ''{0}'' is an interface.
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-15 15:28:59
|
Revision: 1702
http://svn.sourceforge.net/rubyeclipse/?rev=1702&view=rev
Author: cawilliams
Date: 2006-12-15 07:28:55 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
add a new test case wizard
Added Paths:
-----------
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/wizards/
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/wizards/RubyNewTestCaseWizardPage.java
Added: 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 (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/wizards/RubyNewTestCaseWizardPage.java 2006-12-15 15:28:55 UTC (rev 1702)
@@ -0,0 +1,424 @@
+package org.rubypeople.rdt.testunit.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.IDialogPage;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+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.Label;
+import org.eclipse.swt.widgets.Text;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.RubyConventions;
+import org.rubypeople.rdt.core.RubyModelException;
+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.ui.wizards.NewTypeWizardPage;
+import org.rubypeople.rdt.ui.wizards.RubyClassSelectionDialog;
+
+public class RubyNewTestCaseWizardPage extends NewTypeWizardPage {
+
+ private final static String PAGE_NAME= "NewTestCaseCreationWizardPage"; //$NON-NLS-1$
+
+ /** Field ID of the class under test field. */
+ public final static String CLASS_UNDER_TEST= PAGE_NAME + ".classundertest"; //$NON-NLS-1$
+
+ private final static String TEST_SUFFIX= "Test"; //$NON-NLS-1$
+
+ private final static String STORE_SETUP= PAGE_NAME + ".USE_SETUP"; //$NON-NLS-1$
+ private final static String STORE_TEARDOWN= PAGE_NAME + ".USE_TEARDOWN"; //$NON-NLS-1$
+ private final static String STORE_CONSTRUCTOR= PAGE_NAME + ".USE_CONSTRUCTOR"; //$NON-NLS-1$
+
+ private final static int IDX_SETUP= 0;
+ private final static int IDX_TEARDOWN= 1;
+ private final static int IDX_CONSTRUCTOR= 2;
+
+ private String fClassUnderTestText;
+ private MethodStubsSelectionButtonGroup fMethodStubsButtons;
+
+ private Text fClassUnderTestControl;
+ private Button fClassUnderTestButton;
+
+ private IStatus fClassUnderTestStatus;
+
+ private IType fClassUnderTest;
+
+ /**
+ * Constructor for SampleNewWizardPage.
+ *
+ * @param pageName
+ */
+ public RubyNewTestCaseWizardPage(ISelection selection) {
+ super(true, PAGE_NAME);
+
+ setTitle(WizardMessages.NewTestCaseWizardPage_title);
+ setDescription(WizardMessages.NewTestCaseWizardPage_description);
+
+ String[] buttonNames= new String[] {
+ /* IDX_SETUP */ WizardMessages.NewTestCaseWizardPage_methodStub_setUp,
+ /* IDX_TEARDOWN */ WizardMessages.NewTestCaseWizardPage_methodStub_tearDown,
+ /* IDX_CONSTRUCTOR */ WizardMessages.NewTestCaseWizardPage_methodStub_constructor
+ };
+
+ fMethodStubsButtons= new MethodStubsSelectionButtonGroup(SWT.CHECK, buttonNames, 2);
+ fMethodStubsButtons.setLabelText(WizardMessages.NewTestCaseWizardPage_method_Stub_label);
+
+ fClassUnderTestStatus= new TestUnitStatus();
+
+ fClassUnderTestText= ""; //$NON-NLS-1$
+ }
+
+ /**
+ * @see IDialogPage#createControl(Composite)
+ */
+ public void createControl(Composite parent) {
+
+ Composite container= new Composite(parent, SWT.NONE);
+
+ int nColumns= 4;
+
+ GridLayout layout= new GridLayout();
+ layout.numColumns= nColumns;
+ container.setLayout(layout);
+
+ createContainerControls(container, nColumns);
+ createSeparator(container, nColumns);
+ createTypeNameControls(container, nColumns);
+ createSuperClassControls(container, nColumns);
+ createMethodStubSelectionControls(container, nColumns);
+ createSeparator(container, nColumns);
+ createClassUnderTestControls(container, nColumns);
+
+ setControl(container);
+ setSuperClass("Test::Unit::TestCase", true);
+
+ //set default and focus
+ String classUnderTest= getClassUnderTestText();
+ if (classUnderTest.length() > 0) {
+ setTypeName(classUnderTest+TEST_SUFFIX, true);
+ }
+
+ Dialog.applyDialogFont(container);
+ // TODO Uncomment
+// PlatformUI.getWorkbench().getHelpSystem().setHelp(container, ITestUnitHelpContextIds.NEW_TESTCASE_WIZARD_PAGE);
+
+ setFocus();
+ }
+
+ /* (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 {
+ if (fMethodStubsButtons.isSelected(IDX_CONSTRUCTOR)) {
+ createConstructor(type);
+ }
+
+ if (fMethodStubsButtons.isSelected(IDX_SETUP)) {
+ createSetUp(type);
+ }
+
+ if (fMethodStubsButtons.isSelected(IDX_TEARDOWN)) {
+ createTearDown(type);
+ }
+
+ if (fClassUnderTest != null) {
+ createTestMethodStubs(type);
+ }
+ }
+
+
+ private void createConstructor(IType type) throws CoreException {
+ StringBuffer content = new StringBuffer("def initialize\n");
+ content.append(" super\n");
+ content.append("end\n");
+ 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");
+ 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");
+ type.createMethod(content.toString(), null, true, null);
+ }
+
+ private void createTestMethodStubs(IType type) throws CoreException {
+// StringBuffer content = new StringBuffer("def setup");
+// content.append(" super\n");
+// content.append("end\n");
+// type.createMethod(content.toString(), null, true, null);
+ }
+
+ /**
+ * Creates the controls for the method stub selection buttons. Expects a <code>GridLayout</code> with
+ * at least 3 columns.
+ *
+ * @param composite the parent composite
+ * @param nColumns number of columns to span
+ */
+ protected void createMethodStubSelectionControls(Composite composite, int nColumns) {
+ LayoutUtil.setHorizontalSpan(fMethodStubsButtons.getLabelControl(composite), nColumns);
+ LayoutUtil.createEmptySpace(composite, 1);
+ LayoutUtil.setHorizontalSpan(fMethodStubsButtons.getSelectionButtonsGroup(composite), nColumns - 1);
+ }
+
+ /**
+ * Creates the controls for the 'class under test' field. Expects a <code>GridLayout</code> with
+ * at least 3 columns.
+ *
+ * @param composite the parent composite
+ * @param nColumns number of columns to span
+ */
+ protected void createClassUnderTestControls(Composite composite, int nColumns) {
+ Label classUnderTestLabel= new Label(composite, SWT.LEFT | SWT.WRAP);
+ classUnderTestLabel.setFont(composite.getFont());
+ classUnderTestLabel.setText(WizardMessages.NewTestCaseWizardPage_class_to_test_label);
+ classUnderTestLabel.setLayoutData(new GridData());
+
+ fClassUnderTestControl= new Text(composite, SWT.SINGLE | SWT.BORDER);
+ fClassUnderTestControl.setEnabled(true);
+ fClassUnderTestControl.setFont(composite.getFont());
+ fClassUnderTestControl.setText(fClassUnderTestText);
+ fClassUnderTestControl.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ internalSetClassUnderText(((Text) e.widget).getText());
+ }
+ });
+ GridData gd= new GridData();
+ gd.horizontalAlignment= GridData.FILL;
+ gd.grabExcessHorizontalSpace= true;
+ gd.horizontalSpan= nColumns - 2;
+ fClassUnderTestControl.setLayoutData(gd);
+
+ fClassUnderTestButton= new Button(composite, SWT.PUSH);
+ fClassUnderTestButton.setText(WizardMessages.NewTestCaseWizardPage_class_to_test_browse);
+ fClassUnderTestButton.setEnabled(true);
+ fClassUnderTestButton.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ classToTestButtonPressed();
+ }
+ public void widgetSelected(SelectionEvent e) {
+ classToTestButtonPressed();
+ }
+ });
+ gd= new GridData();
+ gd.horizontalAlignment= GridData.FILL;
+ gd.grabExcessHorizontalSpace= false;
+ gd.horizontalSpan= 1;
+ gd.widthHint = LayoutUtil.getButtonWidthHint(fClassUnderTestButton);
+ fClassUnderTestButton.setLayoutData(gd);
+
+// ControlContentAssistHelper.createTextContentAssistant(fClassUnderTestControl, fClassToTestCompletionProcessor);
+ }
+
+ private IType chooseClassToTestType() {
+ IRubyProject root = getProject();
+ if (root == null)
+ return null;
+
+// IRubyElement[] elements= new IRubyElement[] { root.getRubyProject() };
+
+
+ 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];
+ }
+
+ return null;
+ }
+
+ private void classToTestButtonPressed() {
+ IType type= chooseClassToTestType();
+ if (type != null) {
+ setClassUnderTest(type.getElementName());
+ }
+ }
+
+ /**
+ * Sets the name of the class under test.
+ *
+ * @param name The name to set
+ */
+ public void setClassUnderTest(String name) {
+ if (fClassUnderTestControl != null && !fClassUnderTestControl.isDisposed()) {
+ fClassUnderTestControl.setText(name);
+ }
+ internalSetClassUnderText(name);
+ }
+
+ private void internalSetClassUnderText(String name) {
+ fClassUnderTestText= name;
+ fClassUnderTestStatus= classUnderTestChanged();
+ handleFieldChanged(CLASS_UNDER_TEST);
+ }
+
+ /**
+ * Hook method that gets called when the class under test has changed. The method class under test
+ * returns the status of the validation.
+ * <p>
+ * Subclasses may extend this method to perform their own validation.
+ * </p>
+ *
+ * @return the status of the validation
+ */
+ protected IStatus classUnderTestChanged() {
+ TestUnitStatus status= new TestUnitStatus();
+
+
+ fClassUnderTest= null;
+
+ IRubyProject root = getProject();
+ if (root == null) {
+ return status;
+ }
+
+ String classToTestName= getClassUnderTestText();
+ if (classToTestName.length() == 0) {
+ return status;
+ }
+ IStatus val= RubyConventions.validateRubyTypeName(classToTestName);
+ if (val.getSeverity() == IStatus.ERROR) {
+ status.setError(WizardMessages.NewTestCaseWizardPage_error_class_to_test_not_valid);
+ return status;
+ }
+
+ try {
+ IType type= resolveClassNameToType(root, classToTestName);
+ if (type == null) {
+ status.setError(WizardMessages.NewTestCaseWizardPage_error_class_to_test_not_exist);
+ return status;
+ }
+ if (type.isModule()) {
+ status.setWarning(Messages.format(WizardMessages.NewTestCaseWizardPage_warning_class_to_test_is_interface, classToTestName));
+ }
+
+ fClassUnderTest= type;
+// fPage2.setClassUnderTest(fClassUnderTest);
+ } catch (RubyModelException e) {
+ status.setError(WizardMessages.NewTestCaseWizardPage_error_class_to_test_not_valid);
+ }
+ return status;
+ }
+
+ private IType resolveClassNameToType(IRubyProject rproject, String classToTestName) throws RubyModelException {
+ if (!rproject.exists()) {
+ return null;
+ }
+
+ IType type= rproject.findType(classToTestName);
+
+ // search in java.lang
+// if (type == null) {
+// type= jproject.findType("java.lang", classToTestName); //$NON-NLS-1$
+// }
+ return type;
+ }
+
+ /**
+ * Returns the content of the class to test text field.
+ *
+ * @return the name of the class to test
+ */
+ public String getClassUnderTestText() {
+ return fClassUnderTestText;
+ }
+
+ /**
+ * Initialized the page with the current selection
+ * @param selection The selection
+ */
+ public void init(IStructuredSelection selection) {
+ IRubyElement element= getInitialRubyElement(selection);
+
+ initContainerPage(element);
+ // TODO Uncomment to set up type page
+// initTypePage(element);
+ // put default class to test
+ if (element != null) {
+ IType classToTest= null;
+ // evaluate the enclosing type
+ IType typeInCompUnit= (IType) element.getAncestor(IRubyElement.TYPE);
+ if (typeInCompUnit != null) {
+ if (typeInCompUnit.getRubyScript() != null) {
+ classToTest= typeInCompUnit;
+ }
+ } else {
+ IRubyScript cu= (IRubyScript) element.getAncestor(IRubyElement.SCRIPT);
+ if (cu != null)
+ classToTest= cu.findPrimaryType();
+ }
+ // TODO uncomment to set class under test
+// if (classToTest != null) {
+// try {
+// if (!TestSearchEngine.isTestImplementor(classToTest)) {
+// setClassUnderTest(classToTest.getFullyQualifiedName('.'));
+// }
+// } catch (RubyModelException e) {
+// TestunitPlugin.log(e);
+// }
+// }
+ }
+
+ restoreWidgetValues();
+
+ updateStatus(getStatusList());
+ }
+
+ /**
+ * Returns all status to be consider for the validation. Clients can override.
+ * @return The list of status to consider for the validation.
+ */
+ protected IStatus[] getStatusList() {
+ return new IStatus[] {
+ fContainerStatus,
+ fTypeNameStatus,
+ fClassUnderTestStatus,
+ fSuperClassStatus
+ };
+ }
+
+ /**
+ * Use the dialog store to restore widget values to the values that they held
+ * last time this wizard was used to completion
+ */
+ private void restoreWidgetValues() {
+ IDialogSettings settings= getDialogSettings();
+ if (settings != null) {
+ fMethodStubsButtons.setSelection(IDX_SETUP, settings.getBoolean(STORE_SETUP));
+ fMethodStubsButtons.setSelection(IDX_TEARDOWN, settings.getBoolean(STORE_TEARDOWN));
+ fMethodStubsButtons.setSelection(IDX_CONSTRUCTOR, settings.getBoolean(STORE_CONSTRUCTOR));
+ } else {
+ fMethodStubsButtons.setSelection(IDX_SETUP, false); //setUp
+ fMethodStubsButtons.setSelection(IDX_TEARDOWN, false); //tearDown
+ fMethodStubsButtons.setSelection(IDX_CONSTRUCTOR, false); //constructor
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-15 15:28:45
|
Revision: 1701
http://svn.sourceforge.net/rubyeclipse/?rev=1701&view=rev
Author: cawilliams
Date: 2006-12-15 07:28:41 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
add a new test case wizard
Added Paths:
-----------
trunk/org.rubypeople.rdt.testunit/icons/full/etool16/
trunk/org.rubypeople.rdt.testunit/icons/full/etool16/new_testcase.gif
Added: trunk/org.rubypeople.rdt.testunit/icons/full/etool16/new_testcase.gif
===================================================================
(Binary files differ)
Property changes on: trunk/org.rubypeople.rdt.testunit/icons/full/etool16/new_testcase.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-15 15:28:30
|
Revision: 1700
http://svn.sourceforge.net/rubyeclipse/?rev=1700&view=rev
Author: cawilliams
Date: 2006-12-15 07:28:29 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
add a new test case wizard
Added Paths:
-----------
trunk/org.rubypeople.rdt.testunit/icons/full/dtool16/
trunk/org.rubypeople.rdt.testunit/icons/full/dtool16/new_testcase.gif
Added: trunk/org.rubypeople.rdt.testunit/icons/full/dtool16/new_testcase.gif
===================================================================
(Binary files differ)
Property changes on: trunk/org.rubypeople.rdt.testunit/icons/full/dtool16/new_testcase.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-15 15:28:04
|
Revision: 1699
http://svn.sourceforge.net/rubyeclipse/?rev=1699&view=rev
Author: cawilliams
Date: 2006-12-15 07:28:00 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
try a logo change (to the one on our trac site)
Modified Paths:
--------------
trunk/org.rubypeople.rdt/about.ini
trunk/org.rubypeople.rdt/ruby.png
Added Paths:
-----------
trunk/org.rubypeople.rdt/rdt_logo.png
Modified: trunk/org.rubypeople.rdt/about.ini
===================================================================
(Binary files differ)
Added: trunk/org.rubypeople.rdt/rdt_logo.png
===================================================================
(Binary files differ)
Property changes on: trunk/org.rubypeople.rdt/rdt_logo.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/org.rubypeople.rdt/ruby.png
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2006-12-15 15:27:35
|
Revision: 1698
http://svn.sourceforge.net/rubyeclipse/?rev=1698&view=rev
Author: cawilliams
Date: 2006-12-15 07:27:34 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
Eclipse reccomended our branding plugin not be unpacked
Modified Paths:
--------------
trunk/org.rubypeople.rdt-feature/feature.xml
Modified: trunk/org.rubypeople.rdt-feature/feature.xml
===================================================================
--- trunk/org.rubypeople.rdt-feature/feature.xml 2006-12-15 15:27:11 UTC (rev 1697)
+++ trunk/org.rubypeople.rdt-feature/feature.xml 2006-12-15 15:27:34 UTC (rev 1698)
@@ -296,7 +296,7 @@
download-size="0"
install-size="0"
version="0.0.0"
- unpack="true"/>
+ unpack="false"/>
<plugin
id="org.rubypeople.rdt.testunit"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|