initial commit in accordance with CQ 3784
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/.classpath b/plugins/org.eclipse.objectteams.otdt.ui/.classpath
new file mode 100644
index 0000000..64c5e31
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/.cvsignore b/plugins/org.eclipse.objectteams.otdt.ui/.cvsignore
new file mode 100644
index 0000000..f9b5b51
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/.cvsignore
@@ -0,0 +1,3 @@
+bin
+temp.folder
+otdtui.jar
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/.project b/plugins/org.eclipse.objectteams.otdt.ui/.project
new file mode 100644
index 0000000..ba49923
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.objectteams.otdt.ui</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/.settings/org.eclipse.core.resources.prefs b/plugins/org.eclipse.objectteams.otdt.ui/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..613c62b
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,3 @@
+#Fri Mar 23 07:54:22 CET 2007
+eclipse.preferences.version=1
+encoding//src/org/objectteams/otdt/internal/ui/bindingeditor/Messages.properties=8859_1
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.objectteams.otdt.ui/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..35fc435
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,58 @@
+#Thu May 14 15:41:11 CEST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore
+org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
+org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning
+org.eclipse.jdt.core.compiler.problem.nullReference=ignore
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.objectteams.otdt.ui/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..22a0a2f
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/META-INF/MANIFEST.MF
@@ -0,0 +1,43 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: OTDTUI Plug-in
+Bundle-SymbolicName: org.eclipse.objectteams.otdt.ui;singleton:=true
+Bundle-Version: 1.4.0.qualifier
+Bundle-Activator: org.eclipse.objectteams.otdt.ui.OTDTUIPlugin
+Bundle-Vendor: Fraunhofer FIRST
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.ui.views,
+ org.eclipse.jface.text,
+ org.eclipse.ui.workbench.texteditor,
+ org.eclipse.ui.editors,
+ org.eclipse.ui,
+ org.eclipse.jdt.core,
+ org.eclipse.jdt.ui,
+ org.eclipse.debug.core,
+ org.eclipse.debug.ui,
+ org.eclipse.jdt.debug.ui,
+ org.eclipse.jdt.launching,
+ org.eclipse.core.resources,
+ org.eclipse.search,
+ org.eclipse.ui.console,
+ org.eclipse.ui.ide,
+ org.eclipse.help,
+ org.eclipse.core.filesystem,
+ org.eclipse.objectteams.otdt.debug,
+ org.eclipse.ui.forms,
+ org.eclipse.objectteams.otdt,
+ org.eclipse.compare;bundle-version="3.5.100",
+ org.eclipse.team.core;bundle-version="3.5.0",
+ org.eclipse.team.ui;bundle-version="3.5.100"
+Bundle-ActivationPolicy: lazy
+Export-Package:
+ org.eclipse.objectteams.otdt.internal.ui.callinmarkers;x-friends:="org.eclipse.objectteams.otdt.ui.tests",
+ org.eclipse.objectteams.otdt.internal.ui.javaeditor;x-friends:="org.eclipse.objectteams.otdt.debug.ui,org.eclipse.objectteams.otdt.jdt.ui",
+ org.eclipse.objectteams.otdt.internal.ui.preferences;x-friends:="org.eclipse.objectteams.otdt.ui.tests",
+ org.eclipse.objectteams.otdt.internal.ui.wizards;x-friends:="org.eclipse.objectteams.otdt.ui.tests",
+ org.eclipse.objectteams.otdt.internal.ui.wizards.listeners;x-friends:="org.eclipse.objectteams.otdt.ui.tests",
+ org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation;x-friends:="org.eclipse.objectteams.otdt.ui.tests",
+ org.eclipse.objectteams.otdt.ui,
+ org.eclipse.objectteams.otdt.ui.dialogs
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/build.properties b/plugins/org.eclipse.objectteams.otdt.ui/build.properties
new file mode 100644
index 0000000..acc83bd
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/build.properties
@@ -0,0 +1,7 @@
+bin.includes = plugin.xml,\
+ icons/,\
+ plugin.properties,\
+ .,\
+ META-INF/,\
+ templates/
+source.. = src/
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/jdt/full/ctool16/opentype.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/jdt/full/ctool16/opentype.gif
new file mode 100644
index 0000000..40d2bc9
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/jdt/full/ctool16/opentype.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/jdt/full/obj16/over_co.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/jdt/full/obj16/over_co.gif
new file mode 100644
index 0000000..938767b
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/jdt/full/obj16/over_co.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/baseguard_obj.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/baseguard_obj.gif
new file mode 100644
index 0000000..85d8fa7
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/baseguard_obj.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/boundrole_co.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/boundrole_co.gif
new file mode 100644
index 0000000..5ff9789
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/boundrole_co.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinbinding_obj.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinbinding_obj.gif
new file mode 100644
index 0000000..b3b5254
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinbinding_obj.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinbindingafter_obj.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinbindingafter_obj.gif
new file mode 100644
index 0000000..dde17c8
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinbindingafter_obj.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinbindingbefore_obj.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinbindingbefore_obj.gif
new file mode 100644
index 0000000..c71a184
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinbindingbefore_obj.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinbindingreplace_obj.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinbindingreplace_obj.gif
new file mode 100644
index 0000000..0000be3
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinbindingreplace_obj.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinmethod_co.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinmethod_co.gif
new file mode 100644
index 0000000..177407c
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callinmethod_co.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callout_marker.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callout_marker.gif
new file mode 100644
index 0000000..afd816d
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/callout_marker.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/calloutbinding_obj.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/calloutbinding_obj.gif
new file mode 100644
index 0000000..f96f755
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/calloutbinding_obj.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/default/hide_team_package.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/default/hide_team_package.gif
new file mode 100644
index 0000000..894fdcb
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/default/hide_team_package.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/disabled/hide_team_package.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/disabled/hide_team_package.gif
new file mode 100644
index 0000000..894fdcb
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/disabled/hide_team_package.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/guard_obj.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/guard_obj.gif
new file mode 100644
index 0000000..67c5623
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/guard_obj.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/hover/hide_team_package.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/hover/hide_team_package.gif
new file mode 100644
index 0000000..b9a2c56
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/hover/hide_team_package.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/jcu_obj.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/jcu_obj.gif
new file mode 100644
index 0000000..4cecec9
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/jcu_obj.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/newrole_obj.png b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/newrole_obj.png
new file mode 100644
index 0000000..a157171
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/newrole_obj.png
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/newteam_obj.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/newteam_obj.gif
new file mode 100644
index 0000000..29c0d94
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/newteam_obj.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/ot.png b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/ot.png
new file mode 100644
index 0000000..d2ed13d
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/ot.png
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/ot_bare_10.png b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/ot_bare_10.png
new file mode 100644
index 0000000..fcbb8cc
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/ot_bare_10.png
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/playedBy_obj.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/playedBy_obj.gif
new file mode 100644
index 0000000..8520281
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/playedBy_obj.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/role_obj.png b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/role_obj.png
new file mode 100644
index 0000000..f89af2d
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/role_obj.png
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/role_ovr.png b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/role_ovr.png
new file mode 100644
index 0000000..a9d9dc3
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/role_ovr.png
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/role_protected_obj.png b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/role_protected_obj.png
new file mode 100644
index 0000000..c47d049
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/role_protected_obj.png
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_obj.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_obj.gif
new file mode 100644
index 0000000..cadfdc2
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_obj.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_ovr.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_ovr.gif
new file mode 100644
index 0000000..595f584
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_ovr.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_role_obj.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_role_obj.gif
new file mode 100644
index 0000000..bb7076e
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_role_obj.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_role_ovr.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_role_ovr.gif
new file mode 100644
index 0000000..e289935
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_role_ovr.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_role_protected_obj.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_role_protected_obj.gif
new file mode 100644
index 0000000..a41d18f
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/team_role_protected_obj.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/wizard/newotjprj_wiz.png b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/wizard/newotjprj_wiz.png
new file mode 100644
index 0000000..2f04ac4
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/wizard/newotjprj_wiz.png
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/wizard/newprj_wiz.gif b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/wizard/newprj_wiz.gif
new file mode 100644
index 0000000..858f4c9
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/wizard/newprj_wiz.gif
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/wizard/newrole_wiz.png b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/wizard/newrole_wiz.png
new file mode 100644
index 0000000..e22484d
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/wizard/newrole_wiz.png
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/wizard/newteam_wiz.png b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/wizard/newteam_wiz.png
new file mode 100644
index 0000000..567cb10
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/icons/ot/wizard/newteam_wiz.png
Binary files differ
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/plugin.properties b/plugins/org.eclipse.objectteams.otdt.ui/plugin.properties
new file mode 100644
index 0000000..302800f
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/plugin.properties
@@ -0,0 +1,39 @@
+pluginName= Object Teams Development Tools UI
+providerName= Fraunhofer FIRST
+
+# New OT project wizard
+ObjectTeams = Object Teams
+NewOTProject.label = Object Teams Project
+NewOTProject.description = Create an Object Teams project
+
+# NewTeamCreationWizard
+NewTeam.label = Team
+NewTeam.description = Create a team
+
+# NewRoleCreationWizard
+NewRole.label = Role
+NewRole.description = Create a role
+
+perspectiveName=Object Teams
+viewCategoryName=Object Teams
+packagesViewName=Package Explorer
+hierarchyViewName=Hierarchy
+
+##########################################################################
+# Compiler configurable options
+##########################################################################
+OTCompilerPreferencePageName=Compiler (OT/J)
+OTCompilerPropertyPageName=Java Compiler (OT/J)
+
+preferenceKeywords.compiler.options=Java errors warnings ignore compiler options decapsulation basecall lifting callin playedBy role
+
+
+############################
+
+OTGeneralPreferencePageName=Object Teams
+
+# Context menu:
+CompareWithBaseMethodAction.label=&Bound Base Method
+CompareWithBaseMethodAction.description=Compare the current method with the base method it replaces.
+# Repeated from org.eclipse.compare:
+CompareWithMenu.label= Comp&are With
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/plugin.xml b/plugins/org.eclipse.objectteams.otdt.ui/plugin.xml
new file mode 100644
index 0000000..cf05030
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/plugin.xml
@@ -0,0 +1,472 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+
+<!-- Perspectives -->
+ <extension
+ point="org.eclipse.ui.perspectives">
+ <perspective
+ name="%perspectiveName"
+ icon="icons/ot/ot.png"
+ class="org.eclipse.objectteams.otdt.internal.ui.OTJavaPerspectiveFactory"
+ id="org.eclipse.objectteams.otdt.ui.OTJavaPerspective">
+ </perspective>
+ </extension>
+
+<!-- View category -->
+ <extension
+ point="org.eclipse.ui.views">
+ <category
+ id="org.eclipse.objectteams.otdt.ui"
+ name="Object Teams">
+ </category>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.perspectiveExtensions">
+ <perspectiveExtension
+ targetID="org.eclipse.objectteams.otdt.ui.OTJavaPerspective">
+
+ <!-- "Open Perspective" shows the Debug, Resource and OT-perspective -->
+ <perspectiveShortcut
+ id="org.eclipse.debug.ui.DebugPerspective">
+ </perspectiveShortcut>
+ <perspectiveShortcut
+ id="org.eclipse.ui.resourcePerspective">
+ </perspectiveShortcut>
+ <perspectiveShortcut
+ id="org.eclipse.objectteams.otdt.ui.OTJavaPerspective">
+ </perspectiveShortcut>
+ <view
+ id="org.eclipse.pde.runtime.LogView"
+ minimized="false"
+ relationship="stack"
+ relative="org.eclipse.ui.views.ProblemView">
+ </view>
+ <newWizardShortcut
+ id="org.eclipse.objectteams.otdt.ui.wizards.NewTeamCreationWizard">
+ </newWizardShortcut>
+ <newWizardShortcut
+ id="org.eclipse.objectteams.otdt.ui.wizards.NewRoleCreationWizard">
+ </newWizardShortcut>
+ <newWizardShortcut
+ id="org.eclipse.objectteams.otdt.ui.wizards.OTNewProjectWizard">
+ </newWizardShortcut>
+ <newWizardShortcut
+ id="org.eclispe.objectteams.otdt.pde.ui.wizards.OTNewPluginProjectWizard">
+ </newWizardShortcut>
+ <actionSet
+ id="org.eclipse.jdt.ui.text.java.actionSet.presentation">
+ </actionSet>
+ </perspectiveExtension>
+
+ <!-- Add our own perspective to the Resource, Java and Debug perspectives -->
+ <perspectiveExtension
+ targetID="org.eclipse.ui.resourcePerspective">
+ <perspectiveShortcut
+ id="org.eclipse.objectteams.otdt.ui.OTJavaPerspective">
+ </perspectiveShortcut>
+ </perspectiveExtension>
+
+ <perspectiveExtension
+ targetID="org.eclipse.jdt.ui.JavaPerspective">
+ <perspectiveShortcut
+ id="org.eclipse.objectteams.otdt.ui.OTJavaPerspective">
+ </perspectiveShortcut>
+ </perspectiveExtension>
+
+ <perspectiveExtension
+ targetID="org.eclipse.debug.ui.DebugPerspective">
+ <perspectiveShortcut
+ id="org.eclipse.objectteams.otdt.ui.OTJavaPerspective">
+ </perspectiveShortcut>
+ </perspectiveExtension>
+
+ </extension>
+
+<!-- Object Teams Wizards -->
+ <extension
+ point="org.eclipse.ui.newWizards">
+ <category
+ name="%ObjectTeams"
+ id="org.eclipse.objectteams.otdt.ui.wizards">
+ </category>
+ <wizard
+ name="%NewOTProject.label"
+ icon="icons/ot/wizard/newprj_wiz.gif"
+ category="org.eclipse.objectteams.otdt.ui.wizards"
+ class="org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewProjectWizard"
+ preferredPerspectives="org.eclipse.objectteams.otdt.ui.OTJavaPerspective"
+ project="true"
+ finalPerspective="org.eclipse.objectteams.otdt.ui.OTJavaPerspective"
+ id="org.eclipse.objectteams.otdt.ui.wizards.OTNewProjectWizard">
+ <description>
+ %NewOTProject.description
+ </description>
+ </wizard>
+ <wizard
+ name="%NewTeam.label"
+ icon="icons/ot/newteam_obj.gif"
+ category="org.eclipse.objectteams.otdt.ui.wizards"
+ id="org.eclipse.objectteams.otdt.ui.wizards.NewTeamCreationWizard">
+ <class
+ class="org.eclipse.objectteams.otdt.internal.ui.wizards.NewTeamCreationWizard">
+ <parameter name="javatype" value="true"/>
+ </class>
+ <description>
+ %NewTeam.description
+ </description>
+ </wizard>
+ <wizard
+ name="%NewRole.label"
+ icon="icons/ot/newrole_obj.png"
+ category="org.eclipse.objectteams.otdt.ui.wizards"
+ id="org.eclipse.objectteams.otdt.ui.wizards.NewRoleCreationWizard">
+ <class
+ class="org.eclipse.objectteams.otdt.internal.ui.wizards.NewRoleCreationWizard">
+ <parameter name="javatype" value="true"/>
+ </class>
+ <description>
+ %NewRole.description
+ </description>
+ </wizard>
+ </extension>
+
+
+<!-- Object Teams Markers/Annotation: Callin, Callout, PlayedBy, OverridingRole -->
+ <extension
+ point="org.eclipse.core.resources.markers"
+ id="callinMarker"
+ name="Callin Marker">
+ <super type="org.eclipse.core.resources.textmarker"/>
+ <persistent value="false"/>
+ <attribute name="org.eclipse.objectteams.otdt.ui.markerAttr.CallinMapping"/>
+ </extension>
+ <extension
+ point="org.eclipse.core.resources.markers"
+ id="calloutMarker"
+ name="Callout Marker">
+ <super type="org.eclipse.core.resources.textmarker"/>
+ <persistent value="false"/>
+ <attribute name="org.eclipse.objectteams.otdt.ui.markerAttr.CalloutMapping"/>
+ </extension>
+ <extension
+ point="org.eclipse.core.resources.markers"
+ id="playedByMarker"
+ name="PlayedBy Marker">
+ <super type="org.eclipse.core.resources.textmarker"/>
+ <persistent value="false"/>
+ <attribute name="org.eclipse.objectteams.otdt.ui.markerAttr.PlayedByMapping"/>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.editors.annotationTypes">
+ <type
+ name="org.eclipse.objectteams.otdt.ui.annotationtypes.CallinMarker"
+ super="org.eclipse.jdt.ui.info"
+ markerType="org.eclipse.objectteams.otdt.ui.callinMarker">
+ </type>
+ <type
+ name="org.eclipse.objectteams.otdt.ui.annotationtypes.CalloutMarker"
+ super="org.eclipse.jdt.ui.info"
+ markerType="org.eclipse.objectteams.otdt.ui.calloutMarker">
+ </type>
+ <type
+ name="org.eclipse.objectteams.otdt.ui.annotationtypes.PlayedByMarker"
+ super="org.eclipse.jdt.ui.info"
+ markerType="org.eclipse.objectteams.otdt.ui.playedByMarker">
+ </type>
+ <type
+ name="org.eclipse.objectteams.otdt.ui.roleOverrideIndicator"/>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.editors.markerAnnotationSpecification">
+ <specification
+ annotationType="org.eclipse.objectteams.otdt.ui.annotationtypes.CallinMarker"
+ colorPreferenceKey="callinmarker.color"
+ colorPreferenceValue="120,159,79"
+ contributesToHeader="true"
+ highlightPreferenceKey="callinmarker.highlight"
+ icon="icons/ot/callinbinding_obj.gif"
+ includeOnPreferencePage="true"
+ isGoToNextNavigationTarget="true"
+ isGoToNextNavigationTargetKey="callinmarker.gotonext"
+ isGoToPreviousNavigationTarget="true"
+ isGoToPreviousNavigationTargetKey="callinmarker.gotoprev"
+ label="Callin bindings"
+ overviewRulerPreferenceKey="callinmarker.overview"
+ overviewRulerPreferenceValue="true"
+ presentationLayer="9"
+ showInNextPrevDropdownToolbarAction="true"
+ showInNextPrevDropdownToolbarActionKey="callinmarker.nextprev.action"
+ symbolicIcon="info"
+ textPreferenceKey="callinmarker.text"
+ textStylePreferenceKey="callinmarker.textstyle"
+ textStylePreferenceValue="NONE"
+ verticalRulerPreferenceKey="callinmarker.vertical"
+ verticalRulerPreferenceValue="true">
+ </specification>
+
+ <specification
+ annotationType="org.eclipse.objectteams.otdt.ui.annotationtypes.CalloutMarker"
+ colorPreferenceKey="calloutmarker.color"
+ colorPreferenceValue="120,159,79"
+ contributesToHeader="true"
+ highlightPreferenceKey="calloutmarker.highlight"
+ icon="icons/ot/callout_marker.gif"
+ includeOnPreferencePage="true"
+ isGoToNextNavigationTarget="true"
+ isGoToNextNavigationTargetKey="calloutmarker.gotonext"
+ isGoToPreviousNavigationTarget="true"
+ isGoToPreviousNavigationTargetKey="calloutmarker.gotoprev"
+ label="Decapsulating callout bindings"
+ overviewRulerPreferenceKey="calloutmarker.overview"
+ overviewRulerPreferenceValue="true"
+ presentationLayer="9"
+ showInNextPrevDropdownToolbarAction="true"
+ showInNextPrevDropdownToolbarActionKey="calloutmarker.nextprev.action"
+ symbolicIcon="info"
+ textPreferenceKey="calloutmarker.text"
+ textStylePreferenceKey="calloutmarker.textstyle"
+ textStylePreferenceValue="NONE"
+ verticalRulerPreferenceKey="calloutmarker.vertical"
+ verticalRulerPreferenceValue="true">
+ </specification>
+
+ <specification
+ annotationType="org.eclipse.objectteams.otdt.ui.annotationtypes.PlayedByMarker"
+ colorPreferenceKey="playedbymarker.color"
+ colorPreferenceValue="120,159,79"
+ contributesToHeader="true"
+ highlightPreferenceKey="playedbymarker.highlight"
+ icon="icons/ot/playedBy_obj.gif"
+ includeOnPreferencePage="true"
+ isGoToNextNavigationTarget="true"
+ isGoToNextNavigationTargetKey="playedbymarker.gotonext"
+ label="Role bindings"
+ overviewRulerPreferenceKey="playedbymarker.overview"
+ overviewRulerPreferenceValue="true"
+ presentationLayer="9"
+ symbolicIcon="info"
+ textPreferenceKey="playedbymarker.text"
+ textStylePreferenceKey="playedbymarker.teststyle"
+ textStylePreferenceValue="NONE"
+ verticalRulerPreferenceKey="playedbymarker.vertical"
+ verticalRulerPreferenceValue="true">
+ </specification>
+<!-- modelled after org.eclipse.jdt.ui.overrideIndicator (with which it still shares the preferences): -->
+ <specification
+ annotationType="org.eclipse.objectteams.otdt.ui.roleOverrideIndicator"
+ label="Role class override indicator"
+ icon="icons/jdt/full/obj16/over_co.gif"
+ textPreferenceKey="overrideIndicator"
+ textPreferenceValue="false"
+ highlightPreferenceKey="overrideIndicatorHighlighting"
+ highlightPreferenceValue="false"
+ contributesToHeader="false"
+ overviewRulerPreferenceKey="overrideIndicatorInOverviewRuler"
+ overviewRulerPreferenceValue="false"
+ verticalRulerPreferenceKey="overrideIndicatorInVerticalRuler"
+ verticalRulerPreferenceValue="true"
+ colorPreferenceKey="overrideIndicatorColor"
+ colorPreferenceValue="180,207,205"
+ presentationLayer="3"
+ showInNextPrevDropdownToolbarActionKey="showoverrideIndicatorInNextPrevDropdownToolbarAction"
+ showInNextPrevDropdownToolbarAction="false"
+ isGoToNextNavigationTargetKey="isOverrideIndicatorGoToNextNavigationTarget"
+ isGoToNextNavigationTarget="false"
+ isGoToPreviousNavigationTargetKey="isOverrideIndicatorGoToPreviousNavigationTarget"
+ textStylePreferenceKey="overrideIndicatorTextStyle"
+ textStylePreferenceValue="SQUIGGLES">
+ </specification>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.editorActions">
+ <editorContribution
+ id="org.eclipse.ui.texteditor.ruler.actions"
+ targetID="org.eclipse.jdt.ui.CompilationUnitEditor">
+ <action
+ actionID="RulerClick"
+ label="openteam"
+ class="org.eclipse.objectteams.otdt.ui.UpdateRulerAction"
+ id="org.eclipse.objectteams.otdt.refactoring.ui.actions.UpdateRulerAction">
+ </action>
+ </editorContribution>
+ <editorContribution
+ id="org.eclipse.ui.texteditor.ruler.actions"
+ targetID="org.eclipse.jdt.ui.ClassFileEditor">
+ <action
+ actionID="RulerClick"
+ label="openteam"
+ class="org.eclipse.objectteams.otdt.ui.UpdateRulerAction"
+ id="org.eclipse.objectteams.otdt.refactoring.ui.actions.UpdateRulerAction">
+ </action>
+ </editorContribution>
+ </extension>
+
+<!-- Object Teams Templates-->
+ <extension
+ point="org.eclipse.ui.editors.templates">
+ <contextType
+ name="%templates.java.contextType.name"
+ class="org.eclipse.jdt.internal.corext.template.java.JavaContextType"
+ id="java">
+ </contextType>
+ <contextType
+ name="%templates.javadoc.contextType.name"
+ class="org.eclipse.jdt.internal.corext.template.java.JavaDocContextType"
+ id="javadoc">
+ </contextType>
+ <resolver
+ class="org.eclipse.objectteams.otdt.internal.ui.templates.ParameterMappingTemplateResolver"
+ contextTypeId="java"
+ description="Resolver for callin parameter mappings"
+ name="callin parameter mapping"
+ type="callin_parameter_name">
+ </resolver>
+ <resolver
+ class="org.eclipse.objectteams.otdt.internal.ui.templates.ParameterMappingTemplateResolver"
+ contextTypeId="java"
+ description="Resolver for callout parameter mappings"
+ name="callout parameter mapping"
+ type="callout_parameter_name">
+ </resolver>
+ <include
+ file="templates/OT-templates.xml"
+ translations="templates/OT-templates.properties">
+ </include>
+ </extension>
+
+
+
+<!-- Configurable options for the OT/J compiler -->
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ id="org.eclipse.objectteams.otdt.ui.preferences.CompilerPreferencePage"
+ name="%OTCompilerPreferencePageName"
+ category="org.eclipse.jdt.ui.preferences.JavaBasePreferencePage"
+ class="org.eclipse.objectteams.otdt.internal.ui.preferences.OTCompilerPreferencePage">
+ <keywordReference id="org.eclipse.objectteams.otdt.ui.compliance"/>
+ </page>
+
+ <!-- General Object Teams configuration options -->
+ <page
+ id="org.eclipse.objectteams.otdt.ui.preferences.GeneralPreferencePage"
+ name="%OTGeneralPreferencePageName"
+ class="org.eclipse.objectteams.otdt.internal.ui.preferences.OTGeneralPreferencePage">
+ </page>
+
+ </extension>
+ <extension
+ point="org.eclipse.ui.propertyPages">
+ <page
+ class="org.eclipse.objectteams.otdt.internal.ui.preferences.OTCompilerPreferencePage"
+ icon="icons/ot/ot_bare_10.png"
+ id="org.eclipse.objectteams.otdt.ui.propertyPages.CompilerPreferencePage"
+ name="%OTCompilerPropertyPageName">
+ <filter name="nature"
+ value="org.eclipse.objectteams.otdt.OTJavaNature">
+ </filter>
+ <keywordReference id="org.eclipse.objectteams.otdt.ui.compliance"/>
+ <enabledWhen>
+ <or>
+ <instanceof
+ value="org.eclipse.core.resources.IProject">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.jdt.core.IJavaProject">
+ </instanceof>
+ </or>
+ </enabledWhen>
+ </page>
+ </extension>
+ <extension
+ point="org.eclipse.ui.keywords">
+ <keyword
+ id="org.eclipse.objectteams.otdt.ui.compliance"
+ label="%preferenceKeywords.compiler.options"/>
+ </extension>
+ <!-- Binding Editor -->
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="popup:org.eclipse.ui.popup.any?before=group.open">
+ <command
+ commandId="org.eclipse.objectteams.otdt.ui.commands.openBindingEditor"
+ icon="icons/ot/calloutbinding_obj.gif"
+ style="push">
+ <visibleWhen
+ checkEnabled="true">
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ id="org.eclipse.objectteams.otdt.ui.commands.openBindingEditor"
+ name="Open Binding Editor">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.objectteams.otdt.ui.handlers.OpenBindingEditorHandler"
+ commandId="org.eclipse.objectteams.otdt.ui.commands.openBindingEditor">
+ </handler>
+ </extension>
+ <!-- Compare callin method with base method: -->
+ <extension
+ point="org.eclipse.ui.menus">
+ <!-- Forward declaration of a menu declared the old way: -->
+ <menuContribution
+ locationURI="popup:org.eclipse.ui.popup.any">
+ <menu
+ id="compareWithMenu"
+ label="%CompareWithMenu.label">
+ <separator
+ name="compareWithGroup">
+ </separator>
+ </menu>
+ </menuContribution>
+ <!-- Hook this contribution into the above submenu: -->
+ <menuContribution
+ locationURI="popup:compareWithMenu?after=compareWithGroup">
+ <command
+ commandId="org.eclipse.objectteams.otdt.ui.commands.compareWithBaseMethod"
+ icon="icons/ot/callinbindingreplace_obj.gif"
+ style="push">
+ <visibleWhen
+ checkEnabled="true">
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ description="%CompareWithBaseMethodAction.description"
+ id="org.eclipse.objectteams.otdt.ui.commands.compareWithBaseMethod"
+ name="%CompareWithBaseMethodAction.label">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.objectteams.otdt.ui.handlers.CompareWithBaseMethodHandler"
+ commandId="org.eclipse.objectteams.otdt.ui.commands.compareWithBaseMethod">
+ </handler>
+ </extension>
+<!--
+ <extension
+ point="org.eclipse.jdt.ui.foldingStructureProviders">
+ <provider
+ class="org.eclipse.objectteams.otdt.internal.ui.text.folding.OTJavaFoldingStructureProvider"
+ id="org.eclipse.objectteams.otdt.ui.foldingProvider"/>
+ </extension>
+-->
+</plugin>
+
\ No newline at end of file
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTDTUIMessages.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTDTUIMessages.java
new file mode 100644
index 0000000..2b40b04
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTDTUIMessages.java
@@ -0,0 +1,37 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2009, Stephan Herrmann.
+ *
+ * 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
+ * $Id: OTDTUIMessages.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Stephan Herrmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui;
+
+import org.eclipse.osgi.util.NLS;
+
+public class OTDTUIMessages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.objectteams.otdt.internal.ui.OTDTUIMessages"; //$NON-NLS-1$
+ public static String CompareWithBaseMethodAction_errorTitle;
+ public static String CompareWithBaseMethodAction_ambiguousBindingsError;
+ public static String CompareWithBaseMethodAction_multipleBaseMethodsError;
+ public static String CompareBoundMethods_base_method_label;
+ public static String CompareBoundMethods_compare_title;
+ public static String CompareBoundMethods_compare_tooltip;
+ public static String CompareBoundMethods_role_method_label;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, OTDTUIMessages.class);
+ }
+
+ private OTDTUIMessages() {
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTDTUIMessages.properties b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTDTUIMessages.properties
new file mode 100644
index 0000000..d8bd68f
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTDTUIMessages.properties
@@ -0,0 +1,26 @@
+ #**********************************************************************
+ # This file is part of "Object Teams Development Tooling"-Software
+ #
+ # Copyright 2009, Stephan Herrmann.
+ #
+ # 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
+ # $Id: OTDTUIMessages.properties 23435 2010-02-04 00:14:38Z stephan $
+ #
+ # Please visit http://www.objectteams.org for updates and contact.
+ #
+ # Contributors:
+ # Stephan Herrmann - Initial API and implementation
+ #**********************************************************************
+
+# Context menu:
+CompareWithBaseMethodAction_errorTitle=Cannot compare bound methods.
+CompareWithBaseMethodAction_ambiguousBindingsError=This callin method is bound more than once, please select the callin binding.
+CompareWithBaseMethodAction_multipleBaseMethodsError=This callin binding refers to multiple base methods.
+
+CompareBoundMethods_base_method_label=Base method {0}.{1}(..)
+CompareBoundMethods_compare_title=Compare {0}() with its base method
+CompareBoundMethods_compare_tooltip=Compare role method {0}() with its callin-bound base method {1}()
+CompareBoundMethods_role_method_label=Role method {0}.{1}(..)
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTElementAdapterFactory.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTElementAdapterFactory.java
new file mode 100644
index 0000000..8e8edae
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTElementAdapterFactory.java
@@ -0,0 +1,55 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: OTElementAdapterFactory.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+
+
+/**
+ * This factory provides a WorkbenchAdapter for IAdaptable OT elements and
+ * needs to be registered by the platforms AdapterManager.
+ *
+ * @author kaiser
+ * @version $Id: OTElementAdapterFactory.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class OTElementAdapterFactory implements IAdapterFactory
+{
+ WorkbenchAdapter _otAdapter = new WorkbenchAdapter();
+ Class[] _allAdapters = { IWorkbenchAdapter.class };
+
+ public Object getAdapter(Object adaptableObject, Class adapterType)
+ {
+ Object adapter = null;
+
+ if (IWorkbenchAdapter.class.equals(adapterType))
+ {
+ adapter = _otAdapter;
+ }
+
+ return adapter;
+ }
+
+ public Class[] getAdapterList()
+ {
+ return _allAdapters;
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTJavaPerspectiveFactory.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTJavaPerspectiveFactory.java
new file mode 100644
index 0000000..41d6b99
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTJavaPerspectiveFactory.java
@@ -0,0 +1,33 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: OTJavaPerspectiveFactory.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui;
+
+import org.eclipse.jdt.internal.ui.JavaPerspectiveFactory;
+
+/**
+ * The Object Teams perspective is a clone of the Java perspective.
+ * All additions are defined via extension points.
+ * @author mosconi
+ * @version $Id: OTJavaPerspectiveFactory.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class OTJavaPerspectiveFactory extends JavaPerspectiveFactory {
+
+}
\ No newline at end of file
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/WorkbenchAdapter.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/WorkbenchAdapter.java
new file mode 100644
index 0000000..d9b1420
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/WorkbenchAdapter.java
@@ -0,0 +1,170 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: WorkbenchAdapter.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IParent;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.objectteams.otdt.core.ICallinMapping;
+import org.eclipse.objectteams.otdt.core.IMethodMapping;
+import org.eclipse.objectteams.otdt.core.IOTJavaElement;
+import org.eclipse.objectteams.otdt.core.IOTType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.ui.ImageConstants;
+import org.eclipse.objectteams.otdt.ui.ImageManager;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+
+/**
+ * WorkbenchAdapter implementation for OTM elements.
+ *
+ * @author kaiser
+ * @version $Id: WorkbenchAdapter.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class WorkbenchAdapter implements IWorkbenchAdapter
+{
+ public Object[] getChildren(Object parentElement)
+ {
+ try {
+ if (parentElement instanceof ICompilationUnit)
+ return getCUMembers((ICompilationUnit)parentElement);
+
+//{OTModelUpdate : children are in the java element:
+ if (parentElement instanceof IOTType)
+ parentElement = ((IOTType)parentElement).getCorrespondingJavaElement();
+// SH}
+ if (parentElement instanceof IParent)
+ return ((IParent)parentElement).getChildren();
+ }
+ catch (JavaModelException ex) { /* noop */ }
+
+ return new Object[0];
+ }
+
+ /**
+ * Returns all types, including team and "external defined" role classes, of
+ * a given ICompilationUnit.
+ */
+ private Object[] getCUMembers(ICompilationUnit unit) throws JavaModelException
+ {
+ List<IType> result = new ArrayList<IType>();
+ IType[] types = unit.getTypes();
+
+ for (int idx = 0; idx < types.length; idx++)
+ {
+ if (OTModelManager.hasOTElementFor(types[idx]))
+ result.add(OTModelManager.getOTElement(types[idx]));
+ else
+ result.add(types[idx]);
+ }
+
+ return result.toArray();
+ }
+
+ public ImageDescriptor getImageDescriptor(Object element)
+ {
+ ImageDescriptor result = ImageDescriptor.getMissingImageDescriptor();
+
+ try
+ {
+ if (element instanceof IOTType)
+ result = getTypeImageDescriptor((IOTType)element);
+ else if (element instanceof IMethodMapping)
+ result = getBindingImageDescriptor((IMethodMapping)element);
+ }
+ catch (JavaModelException ex)
+ {
+ // MissingImageDescriptor is already added to the result.
+ }
+
+ return result;
+ }
+
+ public String getLabel(Object elem)
+ {
+ if (elem instanceof IOTJavaElement)
+ return ((IOTJavaElement)elem).getElementName();
+
+ return null;
+ }
+
+ public Object getParent(Object elem)
+ {
+ if (elem instanceof IOTType)
+ {
+ IOTType otType = (IOTType)elem;
+//{OTModelUpdate
+ return ((IType) otType.getCorrespondingJavaElement()).getParent();
+//haebor}
+ }
+
+ return null;
+ }
+
+ /**
+ * Return the propriate image descriptor for an OT type.
+ */
+ private ImageDescriptor getTypeImageDescriptor(IOTType type) throws JavaModelException
+ {
+ if (type.isTeam())
+ {
+ if (type.isRole()) {
+ if ((type.getFlags() & Flags.AccProtected) != 0)
+ return ImageManager.getSharedInstance().getDescriptor(ImageConstants.TEAM_ROLE_PROTECTED_IMG);
+ return ImageManager.getSharedInstance().getDescriptor(ImageConstants.TEAM_ROLE_IMG);
+ }
+ return ImageManager.getSharedInstance().getDescriptor(ImageConstants.TEAM_IMG);
+ }
+ else
+ {
+ if ((type.getFlags() & Flags.AccProtected) != 0)
+ return ImageManager.getSharedInstance().getDescriptor(ImageConstants.ROLECLASS_PROTECTED_IMG);
+ return ImageManager.getSharedInstance().getDescriptor(ImageConstants.ROLECLASS_IMG);
+ }
+ }
+
+ private ImageDescriptor getBindingImageDescriptor(IMethodMapping binding)
+ {
+ if (binding.getMappingKind() == IMethodMapping.CALLIN_MAPPING)
+ {
+ ICallinMapping callinMapping = (ICallinMapping) binding;
+ switch(callinMapping.getCallinKind())
+ {
+ case ICallinMapping.KIND_BEFORE:
+ return ImageManager.getSharedInstance().getDescriptor(ImageConstants.CALLINBINDING_BEFORE_IMG);
+ case ICallinMapping.KIND_AFTER:
+ return ImageManager.getSharedInstance().getDescriptor(ImageConstants.CALLINBINDING_AFTER_IMG);
+ default:
+ case ICallinMapping.KIND_REPLACE:
+ return ImageManager.getSharedInstance().getDescriptor(ImageConstants.CALLINBINDING_REPLACE_IMG);
+ }
+ }
+ else
+ {
+ return ImageManager.getSharedInstance().getDescriptor(ImageConstants.CALLOUTBINDING_IMG);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/AddTypeBindingDialog.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/AddTypeBindingDialog.java
new file mode 100644
index 0000000..c0fd644
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/AddTypeBindingDialog.java
@@ -0,0 +1,523 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2006 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: AddTypeBindingDialog.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.bindingeditor;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.search.IJavaSearchConstants;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.core.search.SearchEngine;
+import org.eclipse.jdt.internal.corext.util.Messages;
+import org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.layout.PixelConverter;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.objectteams.otdt.core.IOTType;
+import org.eclipse.objectteams.otdt.core.IRoleType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+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.Event;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.FilteredList;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+
+/**
+ * This dialog is for selection of a role class and a base class for editing.
+ *
+ * @author $ikeman$
+ * @version $Id:AddTypeBindingDialog.java 15586 2007-03-23 13:07:39Z stephan $
+ */
+public class AddTypeBindingDialog extends FilteredTypesSelectionDialog
+{
+ private boolean _baseRelativeToEnclosingBase = false;
+ private IType _baseType;
+ private IType _roleType;
+ private IType _focusTeam;
+ private String _roleTypeName;
+ private String _baseTypeName;
+
+ private IType[] _roleTypes;
+ private FilteredList _rolList;
+ private String _roleNamePattern = ""; //$NON-NLS-1$
+
+ private Button _okButton;
+ private IJavaSearchScope _currentSearchScope; // FIXME(SH) (see showOnlyBaseOfEnclosing())
+
+ public class LabelProvider extends WorkbenchLabelProvider implements ITableLabelProvider
+ {
+ protected String decorateText(String input, Object element)
+ {
+ IType role = (IType)element;
+ String name = role.getTypeQualifiedName().replace('$','.');
+ return name;
+ }
+
+ public void addListener(ILabelProviderListener listener)
+ {
+ }
+
+ public void dispose()
+ {
+ }
+
+ public boolean isLabelProperty(Object element, String property)
+ {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener)
+ {
+ }
+
+ public Image getColumnImage(Object element, int columnIndex)
+ {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex)
+ {
+ return null;
+ }
+ }
+
+
+ static AddTypeBindingDialog create(Shell parentshell, IType focusTeam) {
+ IJavaSearchScope scope = createSearchScope(focusTeam, true);
+ return new AddTypeBindingDialog(parentshell, focusTeam, scope);
+ }
+ private AddTypeBindingDialog(Shell parentshell, IType focusTeam, IJavaSearchScope scope)
+ {
+ super(parentshell, false, null, scope, IJavaSearchConstants.TYPE);
+ _currentSearchScope = scope;
+ _focusTeam = focusTeam;
+
+ setMessage(
+ OTDTUIPlugin.getResourceString("BindingEditor.AddconnectorDialog.BaseClassSelect.Input.title")); //$NON-NLS-1$
+ }
+
+ protected static IJavaSearchScope createSearchScope(IType type, boolean onlyEnclosingBase)
+ {
+ IJavaSearchScope scope = null;
+
+ if (onlyEnclosingBase)
+ {
+ IRoleType enclosingRole = null;
+ if (type instanceof IRoleType) // shouldn't OTModelManager.getOTElement() handle that case?
+ enclosingRole = (IRoleType) type;
+ else
+ {
+ IOTType enclosingType = (IOTType) OTModelManager.getOTElement(type);
+ if (enclosingType instanceof IRoleType)
+ enclosingRole = (IRoleType) enclosingType;
+ }
+
+ if (enclosingRole != null)
+ {
+ try {
+ IType baseType = enclosingRole.getBaseClass();
+ scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {baseType}, false);
+ } catch (JavaModelException ex) {
+ OTDTUIPlugin.getExceptionHandler().logCoreException("Cannot create enclosing-base-searchscope", ex); //$NON-NLS-1$
+ }
+ }
+ // else flag an error? for now, just create the other scope
+ }
+
+ if (scope == null)
+ scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {type.getJavaProject()}, true);
+
+ return scope;
+ }
+
+ protected void configureShell(Shell newShell)
+ {
+ super.configureShell(newShell);
+ newShell.setText(OTDTUIPlugin.getResourceString("BindingEditor.AddconnectorDialog.title")); //$NON-NLS-1$
+ }
+
+ public Control createDialogArea(Composite parent)
+ {
+ Group panes = new Group(parent, SWT.NONE);
+ panes.setLayout(new GridLayout(2, true));
+ panes.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ Group roleTypeGrp = createRoleGroup(panes);
+ createRoleLabel(roleTypeGrp);
+ createRoleTypeText(roleTypeGrp);
+ createRoleListLabel(roleTypeGrp);
+ createRoleList(roleTypeGrp);
+
+ Group baseTypeGrp = createBaseGroup(panes);
+ super.createDialogArea(baseTypeGrp);
+ createSrchInEncBaseCheck(baseTypeGrp);
+
+ return panes;
+ }
+
+ private Group createRoleGroup(Composite container)
+ {
+ Group roleClsGrp = new Group(container, SWT.SHADOW_NONE);
+ roleClsGrp.setText(OTDTUIPlugin.getResourceString(
+ "BindingEditor.AddconnectorDialog.RoleClassSelect.title")); //$NON-NLS-1$
+ roleClsGrp.setLayout(new GridLayout());
+ roleClsGrp.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ return roleClsGrp;
+ }
+
+ private void createRoleLabel(Group roleTypeGrp)
+ {
+ Label rolPatLabel = new Label(roleTypeGrp, SWT.NONE);
+ rolPatLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ rolPatLabel.setText(
+ OTDTUIPlugin.getResourceString("BindingEditor.AddconnectorDialog.RoleClassSelect.Input.title")); //$NON-NLS-1$
+ }
+
+ private void createRoleTypeText(Group roleTypeGrp)
+ {
+ final Text result = new Text(roleTypeGrp, SWT.BORDER);
+ result.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ result.setText((_roleNamePattern == null ? "" : _roleNamePattern)); //$NON-NLS-1$
+
+ result.addListener(SWT.Modify, new Listener()
+ {
+ public void handleEvent(Event evt)
+ {
+ _rolList.setFilter(result.getText());
+ checkOkButton();
+ }
+ });
+ result.addKeyListener(new KeyListener()
+ {
+ public void keyPressed(KeyEvent evt)
+ {
+ if (evt.keyCode == SWT.ARROW_DOWN)
+ _rolList.setFocus();
+ }
+
+ public void keyReleased(KeyEvent evt)
+ {
+ checkOkButton();
+ }
+ });
+ }
+
+ private void createRoleListLabel(Group roleTypeGrp)
+ {
+ Label result = new Label(roleTypeGrp, SWT.NONE);
+ result.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ result.setText(
+ OTDTUIPlugin.getResourceString("BindingEditor.AddconnectorDialog.RoleClassSelect.List.title")); //$NON-NLS-1$
+ }
+
+ private void createRoleList(Group roleGroup)
+ {
+ FilteredList result = new FilteredList(
+ roleGroup,
+ SWT.BORDER,
+ new LabelProvider(),
+ true,
+ false,
+ true);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ PixelConverter converter= new PixelConverter(result);
+ gd.widthHint= converter.convertWidthInCharsToPixels(70);
+ gd.heightHint= convertHeightInCharsToPixels(10);
+ result.setLayoutData(gd);
+ result.setElements(_roleTypes); // computed by open()->computeRoles()
+ _rolList = result;
+ }
+
+ private Group createBaseGroup(Composite container)
+ {
+ final Group result = new Group(container, SWT.TOP);
+ result.setText(OTDTUIPlugin.getResourceString(
+ "BindingEditor.AddconnectorDialog.BaseClassSelect.title")); //$NON-NLS-1$
+ result.setLayout(new GridLayout());
+ result.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ return result;
+ }
+
+ private void createSrchInEncBaseCheck(Group baseTypeGrp) {
+ final Button srchInEncBaseCheck = new Button(baseTypeGrp, SWT.CHECK);
+ srchInEncBaseCheck.setText(OTDTUIPlugin.getResourceString("BindingEditor.AddTypeBindingDialog.use_base_as_anchor")); //$NON-NLS-1$
+ srchInEncBaseCheck.setEnabled(false);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ srchInEncBaseCheck.setLayoutData(gd);
+ try {
+ IOTType teamType = null;
+ if (_focusTeam != null)
+ teamType = OTModelManager.getOTElement(_focusTeam);
+
+ if (teamType != null && teamType.isRole()) {
+ IType baseclass = ((IRoleType)teamType).getBaseClass();
+ if (baseclass != null) {
+ srchInEncBaseCheck.setText(Messages.format(
+ OTDTUIPlugin.getResourceString("BindingEditor.AddTypeBindingDialog.use_specified_base_as_anchor"), //$NON-NLS-1$
+ baseclass.getElementName()));
+ srchInEncBaseCheck.setEnabled(true);
+ srchInEncBaseCheck.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected(SelectionEvent evt)
+ {
+ showOnlyBaseOfEnclosing(srchInEncBaseCheck.getSelection());
+ }
+ });
+ }
+ }
+ } catch (JavaModelException jme) {
+ // no change
+ }
+ }
+
+ private void showOnlyBaseOfEnclosing(boolean onlyBase)
+ {
+ // FIXME(SH): cannot affect scope of super class TypeSelectionDialog2!!
+ _currentSearchScope = createSearchScope(_focusTeam, onlyBase);
+ _baseRelativeToEnclosingBase = onlyBase;
+ }
+
+ protected void createButtonsForButtonBar(Composite parent)
+ {
+ _okButton = createButton(
+ parent,
+ IDialogConstants.OK_ID,
+ IDialogConstants.OK_LABEL,
+ true);
+ createButton(
+ parent,
+ IDialogConstants.CANCEL_ID,
+ IDialogConstants.CANCEL_LABEL,
+ false);
+
+ _okButton.setEnabled(false);
+ }
+
+ private void checkOkButton()
+ {
+ // Note(SH): seemingly called only when base selection has been made.
+ if (_rolList.isEmpty() || _rolList.getSelectionIndex()== -1)
+ _okButton.setEnabled(false);
+ else
+ _okButton.setEnabled(true);
+ }
+
+ protected void updateButtonsEnableState(IStatus status)
+ {
+ if (!_rolList.isEmpty())
+ super.updateButtonsEnableState(status);
+ }
+
+ @Override
+ protected void handleSelected(StructuredSelection selection) {
+ super.handleSelected(selection);
+ checkOkButton();
+ }
+
+ @Override
+ protected void handleDoubleClick() {
+ //overwrite inherited method, just do nothing on a doubleclick on a type
+ }
+
+ @Override
+ public int open()
+ {
+ computeRoles();
+ if (_roleTypes == null || _roleTypes.length == 0)
+ {
+ String title= org.eclipse.objectteams.otdt.internal.ui.bindingeditor.Messages.AddTypeBindingDialog_role_selection_title;
+ String message= org.eclipse.objectteams.otdt.internal.ui.bindingeditor.Messages.AddTypeBindingDialog_no_roles_available_error;
+ MessageDialog.openInformation(getShell(), title, message);
+ return CANCEL;
+ }
+ return super.open();
+ }
+
+ private void computeRoles() {
+ IOTType teamType = null;
+ if (_focusTeam != null)
+ {
+ teamType = OTModelManager.getOTElement(_focusTeam);
+//{Experimental: look for roles inherited from explicit _and_ implicit superteam
+ IType[] roles = null;
+// ArrayList roles = new ArrayList();
+ try
+ {
+ // roles = TypeHelper.getInheritedRoleTypes(team);
+ roles = teamType.getRoleTypes(IOTType.ALL);
+ // FIXME(SH): filter overridden tsupers.
+// if (team.isRole()) {
+// ITypeHierarchy tsuperHierarchy = ((IRoleType)team).newImplicitSupertypeHierarchy();
+// IType[] tsuperTeams = tsuperHierarchy.getAllClasses();
+// for (int i = 0; i < tsuperTeams.length; i++) {
+// roles.addAll(Arrays.asList(TypeHelper.getRoleTypes(tsuperTeams[i], false)));
+// }
+// } else {
+// roles.addAll(Arrays.asList(TypeHelper.getRoleTypes(team, false)));
+// }
+ IType javaTeam = (IType)teamType.getCorrespondingJavaElement();
+ IType[] relevant = new IType[roles.length];
+ int j=0;
+ for (IType role : roles) {
+ IOTType roleType = (IOTType)OTModelManager.getOTElement(role);
+ if (!roleType.isRole())
+ continue;
+ if (((IRoleType)roleType).getBaseClass() == null) {
+ IType declaringTeam = roleType.getDeclaringType();
+ if (declaringTeam == javaTeam)
+ continue;
+ }
+ relevant[j++] = role;
+ }
+ if (j == 0)
+ return;
+ if (j < roles.length)
+ System.arraycopy(relevant, 0, roles=new IType[j], 0, j);
+ }
+ catch (JavaModelException ex)
+ {
+ String title = Messages.format(
+ OTDTUIPlugin.getResourceString("BindingEditor.generic_error_in_dialog"), //$NON-NLS-1$
+ OTDTUIPlugin.getResourceString("BindingEditor.AddconnectorDialog.title")); //$NON-NLS-1$
+ String message = Messages.format(
+ OTDTUIPlugin.getResourceString("BindingEditor.AddTypeBindingDialog.error_retrieving_roles"), //$NON-NLS-1$
+ this._focusTeam.getFullyQualifiedName());
+
+ MessageDialog.openError(getShell(), title, message);
+ buttonPressed(IDialogConstants.CANCEL_ID);
+ }
+ _roleTypes = replaceITypesWithOTTypes(roles);
+// _roleTypes = roles.toArray(new IType[roles.size()]);
+// SH}
+ }
+
+ }
+
+ private static IType[] replaceITypesWithOTTypes(IType[] types)
+ {
+ for (int i = 0; i < types.length; i++)
+ {
+ IType type = types[i];
+ type.exists(); // ensure it's "open"
+ IType otType = OTModelManager.getOTElement(type);
+ if (otType != null)
+ types[i] = otType;
+ }
+
+ return types;
+ }
+
+ protected void computeResult()
+ {
+// CRIPPLE (3.5) migration
+// TypeNameMatch ref = getSelectedTypes()[0];
+//
+// IType type= ref.getType();
+// if (type == null)
+// {
+// // not a class file or compilation unit
+// String title= JavaUIMessages.TypeSelectionDialog_errorTitle;
+// String message= Messages.format(JavaUIMessages.TypeSelectionDialog_dialogMessage, type.getElementName());
+// MessageDialog.openError(getShell(), title, message);
+// setResult(null);
+// }
+// else
+// {
+// List<IType> result= new ArrayList<IType>(1);
+// result.add(type);
+// setResult(result);
+// }
+ }
+
+ protected void okPressed()
+ {
+ if (_rolList.isEmpty() || getResult()[0] == null)
+ {
+ checkOkButton();
+ String title = Messages.format(
+ OTDTUIPlugin.getResourceString("BindingEditor.generic_error_in_dialog"), //$NON-NLS-1$
+ OTDTUIPlugin.getResourceString("BindingEditor.AddconnectorDialog.title")); //$NON-NLS-1$
+ String message = OTDTUIPlugin.getResourceString("BindingEditor.AddTypeBindingDialog.missing_class"); //$NON-NLS-1$
+ MessageDialog.openError(getShell(), title, message);
+ }
+ else
+ {
+ computeResult();
+
+ _baseType = (IType) super.getFirstResult();
+ _baseTypeName = _baseType.getFullyQualifiedName();
+ _roleType = (IType)_rolList.getSelection()[0];
+ _roleTypeName = _roleType.getFullyQualifiedName();
+
+ setReturnCode(OK);
+ close();
+ }
+ }
+
+ public IType getBaseType()
+ {
+ return _baseType;
+ }
+
+ /**
+ * @return the selected BaseTypeName as FullyQualifiedName
+ */
+ public String getBaseTypeName()
+ {
+ if (_baseRelativeToEnclosingBase)
+ return "base."+_baseType.getElementName(); //$NON-NLS-1$
+ return _baseTypeName;
+ }
+
+ public IType getRoleType()
+ {
+ return _roleType;
+ }
+
+ /**
+ * @return the selected RoleTypeName as FullyQualifiedName
+ */
+ public String getRoleTypeName()
+ {
+ return _roleTypeName;
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/BindingConfiguration.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/BindingConfiguration.java
new file mode 100644
index 0000000..d80e540
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/BindingConfiguration.java
@@ -0,0 +1,1408 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2005, 2007 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: BindingConfiguration.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.bindingeditor;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.Signature;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.AbstractMethodMappingDeclaration;
+import org.eclipse.jdt.core.dom.ArrayType;
+import org.eclipse.jdt.core.dom.CallinMappingDeclaration;
+import org.eclipse.jdt.core.dom.CalloutMappingDeclaration;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.MethodMappingElement;
+import org.eclipse.jdt.core.dom.MethodSpec;
+import org.eclipse.jdt.core.dom.Modifier;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.PrimitiveType;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.RoleTypeDeclaration;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SimpleType;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.Type;
+import org.eclipse.jdt.core.dom.rewrite.ASTNodeCreator;
+import org.eclipse.jdt.internal.corext.dom.ASTNodes;
+import org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider;
+import org.eclipse.jdt.internal.ui.viewsupport.TreeHierarchyLayoutProblemsDecorator;
+import org.eclipse.jdt.ui.JavaElementLabels;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.objectteams.otdt.core.IOTType;
+import org.eclipse.objectteams.otdt.core.IRoleType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.core.TypeHelper;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+
+/**
+ * Select role-Method, callout or callin-kind and base-Method for creation of Callin-/CalloutMappingDeclaration.
+ *
+ * @author jwloka
+ */
+public class BindingConfiguration extends Composite
+{
+ private static final int DESELECT_DISABLE_BUTTONS = 1;
+ private static final int SELECT_BUTTONS = 0;
+ private static final String OT_GENERATED_INDICATOR = "_OT$"; //$NON-NLS-1$
+ private static final String FAKED_METHOD_NAME = '\''+Messages.BindingConfiguration_new_method_label;
+ private static final Object[] EMPTY_LIST = new Object[0];
+ private static final int OT_CALLOUT = 0x1000000;
+ private static final int OT_CALLOUT_OVERRIDE = 0x2000000;
+
+ private IMethod[] _roleMethods;
+ private IMember[] _baseMethods;
+ private IMethod _fakedMeth;
+
+ final TableViewer _roleMethListViewer;
+ final TableViewer _baseMethListViewer;
+ final RadioButtonComposite _methMapBtnComp;
+ private Button _calloutBtn;
+ private Button _calloutOverrideBtn;
+ private Button _callinBeforeBtn;
+ private Button _callinReplaceBtn;
+ private Button _callinAfterBtn;
+ private RoleTypeDeclaration _selectedRole;
+ private CalloutMappingDeclaration _selectedCalloutDecl;
+ private CalloutMappingDeclaration _calloutMapping;
+ private CallinMappingDeclaration _selectedCallinDecl;
+ private CallinMappingDeclaration _callinMapping;
+ private BindingEditor _bindingEditor;
+
+ private Button _applyBtn;
+ private boolean _newCallout;
+ private List _parameterMappings;
+ private IType _curTeam;
+
+ class BaseMethodContentProvider implements IStructuredContentProvider
+ {
+ public Object[] getElements(Object inputElement)
+ {
+ return (_baseMethods != null) ? getFilteredMethods() : EMPTY_LIST;
+ }
+
+ public void dispose() {}
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+
+ private Object[] getFilteredMethods()
+ {
+ List<IMember> result = new ArrayList<IMember>();
+ for (int idx = 0; idx < _baseMethods.length; idx++)
+ {
+ IMember curElem = _baseMethods[idx];
+ try {
+ if ( !curElem.getElementName().startsWith(OT_GENERATED_INDICATOR)
+ && !Flags.isSynthetic(curElem.getFlags()))
+ {
+ result.add(curElem);
+ }
+ } catch (JavaModelException jme) {
+ // nop
+ }
+ }
+
+ return result.toArray();
+ }
+ }
+
+ class RoleMethodContentProvider implements IStructuredContentProvider
+ {
+ public Object[] getElements(Object inputElement)
+ {
+ return getFakedMethodList();
+ }
+
+ private Object[] getFakedMethodList()
+ {
+ if (_curTeam == null)
+ {
+ return EMPTY_LIST;
+ }
+
+ _fakedMeth = _curTeam.getMethod(FAKED_METHOD_NAME, new String[0] );
+
+ if (_roleMethods == null)
+ {
+ return new IMethod[] { _fakedMeth };
+ }
+ else
+ {
+ List<IMethod> result = new ArrayList<IMethod>();
+ for (int idx = 0; idx < _roleMethods.length; idx++)
+ {
+ IMethod curElem = _roleMethods[idx];
+ if (!curElem.getElementName().startsWith(OT_GENERATED_INDICATOR))
+ {
+ result.add(curElem);
+ }
+ }
+ result.add(_fakedMeth);
+
+ return result.toArray();
+ }
+ }
+
+ public void dispose() {}
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+ }
+
+
+ public BindingConfiguration(Composite parent, int style)
+ {
+ super(parent, style);
+ setLayout(new FormLayout());
+
+ _bindingEditor = (BindingEditor)parent.getParent();
+
+ JavaUILabelProvider labelProvider = new JavaUILabelProvider();
+ labelProvider.addLabelDecorator(new TreeHierarchyLayoutProblemsDecorator());
+ labelProvider.setTextFlags(JavaElementLabels.M_APP_RETURNTYPE | JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES);
+
+ final Composite composite = new Composite(this, SWT.NONE);
+ final FormData formData_10 = new FormData();
+ formData_10.bottom = new FormAttachment(100, -5);
+ formData_10.right = new FormAttachment(100, -5);
+ formData_10.top = new FormAttachment(100, -50);
+ formData_10.left = new FormAttachment(0, 5);
+ composite.setLayoutData(formData_10);
+ composite.setLayout(new FormLayout());
+
+ _applyBtn = new Button(composite, SWT.NONE);
+ final FormData formData_11 = new FormData();
+ formData_11.bottom = new FormAttachment(100, -5);
+ formData_11.right = new FormAttachment(100, -5);
+ _applyBtn.setLayoutData(formData_11);
+ _applyBtn.setText(Messages.BindingConfiguration_apply_button);
+ _applyBtn.setEnabled(false);
+ addApplyButtonListener(_applyBtn);
+
+ // method mapping button group
+ _methMapBtnComp = new RadioButtonComposite(this, SWT.NONE);
+ final FormData formData_1 = new FormData();
+ formData_1.right = new FormAttachment(60, -5);
+ formData_1.bottom = new FormAttachment(composite, 5, SWT.TOP);
+ formData_1.top = new FormAttachment(0, 8);
+ formData_1.left = new FormAttachment(40, 5);
+ _methMapBtnComp.setLayoutData(formData_1);
+ _methMapBtnComp.setLayout(new FormLayout());
+
+ _calloutBtn = new Button(_methMapBtnComp, SWT.TOGGLE);
+ addButtonListener(_calloutBtn);
+ final FormData formData_3 = new FormData();
+ formData_3.right = new FormAttachment(100, -5);
+ formData_3.top = new FormAttachment(0, 5);
+ formData_3.left = new FormAttachment(0, 5);
+ _calloutBtn.setLayoutData(formData_3);
+ _calloutBtn.setText("->"); //$NON-NLS-1$
+
+ _calloutOverrideBtn = new Button(_methMapBtnComp, SWT.TOGGLE);
+ addButtonListener( _calloutOverrideBtn);
+ final FormData formData_4 = new FormData();
+ formData_4.right = new FormAttachment(100, -5);
+ formData_4.top = new FormAttachment(_calloutBtn, 5, SWT.BOTTOM);
+ formData_4.left = new FormAttachment(0, 5);
+ _calloutOverrideBtn.setLayoutData(formData_4);
+ _calloutOverrideBtn.setText("=>"); //$NON-NLS-1$
+
+ _callinBeforeBtn = new Button(_methMapBtnComp, SWT.TOGGLE);
+ addButtonListener(_callinBeforeBtn);
+ final FormData formData_5 = new FormData();
+ formData_5.right = new FormAttachment(100, -5);
+ formData_5.top = new FormAttachment(_calloutOverrideBtn, 5, SWT.BOTTOM);
+ formData_5.left = new FormAttachment(0, 5);
+ _callinBeforeBtn.setLayoutData(formData_5);
+ _callinBeforeBtn.setText("<- before"); //$NON-NLS-1$
+
+ _callinReplaceBtn = new Button(_methMapBtnComp, SWT.TOGGLE);
+ addButtonListener(_callinReplaceBtn);
+ final FormData formData_6 = new FormData();
+ formData_6.right = new FormAttachment(100, -5);
+ formData_6.top = new FormAttachment(_callinBeforeBtn, 5, SWT.BOTTOM);
+ formData_6.left = new FormAttachment(0, 5);
+ _callinReplaceBtn.setLayoutData(formData_6);
+ _callinReplaceBtn.setText("<- replace"); //$NON-NLS-1$
+
+ _callinAfterBtn = new Button(_methMapBtnComp, SWT.TOGGLE);
+ addButtonListener(_callinAfterBtn);
+ final FormData formData_7 = new FormData();
+ formData_7.right = new FormAttachment(100, -5);
+ formData_7.top = new FormAttachment(_callinReplaceBtn, 5, SWT.BOTTOM);
+ formData_7.left = new FormAttachment(0, 5);
+ _callinAfterBtn.setLayoutData(formData_7);
+ _callinAfterBtn.setText("<- after"); //$NON-NLS-1$
+
+ final Label roleMethLabel = new Label(this, SWT.NONE);
+ final FormData formData = new FormData();
+ formData.right = new FormAttachment(0, 210);
+ formData.top = new FormAttachment(0, 5);
+ formData.left = new FormAttachment(0, 5);
+ roleMethLabel.setLayoutData(formData);
+ roleMethLabel.setText(Messages.BindingConfiguration_role_methods_label);
+
+ _roleMethListViewer = new TableViewer(this, SWT.V_SCROLL | SWT.BORDER | SWT.H_SCROLL);
+ _roleMethListViewer.setContentProvider(new RoleMethodContentProvider());
+ _roleMethListViewer.setLabelProvider(labelProvider);
+ final Table roleMethList = _roleMethListViewer.getTable();
+ final FormData formData_8 = new FormData();
+ formData_8.bottom = new FormAttachment(composite, 5, SWT.TOP);
+ formData_8.right = new FormAttachment(40, 0);
+ formData_8.top = new FormAttachment(roleMethLabel, 5, SWT.BOTTOM);
+ formData_8.left = new FormAttachment(0, 5);
+ roleMethList.setLayoutData(formData_8);
+ _roleMethListViewer.setSorter(new ViewerSorter());
+ _roleMethListViewer.setInput(new Object());
+
+ addRoleListSelectionChangedListener(_roleMethListViewer);
+
+ final Label baseMethLabel = new Label(this, SWT.NONE);
+ final FormData formData_2 = new FormData();
+ formData_2.right = new FormAttachment(100, -5);
+ formData_2.top = new FormAttachment(0, 5);
+ formData_2.left = new FormAttachment(_methMapBtnComp, 5, SWT.RIGHT);
+ baseMethLabel.setLayoutData(formData_2);
+ baseMethLabel.setText(Messages.BindingConfiguration_base_methods_label);
+
+ _baseMethListViewer = new TableViewer(this, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL);
+ _baseMethListViewer.setContentProvider(new BaseMethodContentProvider());
+ _baseMethListViewer.setLabelProvider(labelProvider);
+ final Table baseMethList = _baseMethListViewer.getTable();
+ final FormData formData_12 = new FormData();
+ formData_12.bottom = new FormAttachment(composite, 5, SWT.TOP);
+ formData_12.right = new FormAttachment(100, -5);
+ formData_12.top = new FormAttachment(baseMethLabel, 5, SWT.BOTTOM);
+ formData_12.left = new FormAttachment(60, 0);
+ baseMethList.setLayoutData(formData_12);
+ _baseMethListViewer.setSorter(new ViewerSorter());
+ _baseMethListViewer.setInput(new Object());
+
+ addBaseListSelectionChangedListener(_baseMethListViewer);
+ }
+
+ private void addRoleListSelectionChangedListener(final TableViewer tableViewer)
+ {
+ ISelectionChangedListener listener = new ISelectionChangedListener()
+ {
+ public void selectionChanged(SelectionChangedEvent event)
+ {
+ if (validateSelections())
+ {
+ _methMapBtnComp.enableAll();
+ }
+
+ toggleApplyButton();
+ }
+ };
+
+ tableViewer.addSelectionChangedListener(listener);
+ }
+
+ private void addBaseListSelectionChangedListener(final TableViewer tableViewer)
+ {
+ ISelectionChangedListener listener = new ISelectionChangedListener()
+ {
+ public void selectionChanged(SelectionChangedEvent event)
+ {
+ if (!validateSelections())
+ {
+ return;
+ }
+
+ //no abstract methods selected
+ _methMapBtnComp.enableAll();
+ if (!tableViewer.getSelection().isEmpty()
+ && tableViewer.getTable().getSelection().length > 1)
+ {
+ toggleModifierButtons(OT_CALLOUT|OT_CALLOUT_OVERRIDE, DESELECT_DISABLE_BUTTONS);
+ _methMapBtnComp.removeSelectionButton(_calloutBtn);
+ _methMapBtnComp.removeSelectionButton(_calloutOverrideBtn);
+ }
+ toggleApplyButton();
+ }
+ };
+
+ tableViewer.addSelectionChangedListener(listener);
+ }
+
+ private boolean validateSelections()
+ {
+ StructuredSelection selectedBaseIMembers = (StructuredSelection)_baseMethListViewer.getSelection();
+ for (Iterator iter = selectedBaseIMembers.iterator(); iter.hasNext();)
+ {
+ IMember baseIMember = (IMember) iter.next();
+ try
+ {
+ if (Flags.isAbstract(baseIMember.getFlags()))
+ {
+ _methMapBtnComp.deselectAll();
+ _methMapBtnComp.disableAll();
+ toggleApplyButton();
+ return false;
+ }
+ }
+ catch (JavaModelException ex)
+ {
+ return false;
+ }
+ }
+
+ StructuredSelection selectedRoleIMethod = (StructuredSelection)_roleMethListViewer.getSelection();
+
+ if (selectedRoleIMethod.isEmpty())
+ {
+ return true;
+ }
+
+ IMethod roleMethod = (IMethod)selectedRoleIMethod.getFirstElement();
+ try
+ {
+ if (roleMethod.getElementName().equals(FAKED_METHOD_NAME))
+ {
+ toggleModifierButtons(OT_CALLOUT_OVERRIDE|
+ Modifier.OT_AFTER_CALLIN|
+ Modifier.OT_BEFORE_CALLIN|
+ Modifier.OT_REPLACE_CALLIN,
+ DESELECT_DISABLE_BUTTONS);
+
+ toggleApplyButton();
+ return false;
+ }
+
+ if (!roleMethod.getElementName().equals(FAKED_METHOD_NAME)
+ && !Flags.isCallin(roleMethod.getFlags())
+ && !Flags.isAbstract(roleMethod.getFlags()))
+ {
+ toggleModifierButtons(Modifier.OT_REPLACE_CALLIN|OT_CALLOUT, DESELECT_DISABLE_BUTTONS);
+ toggleApplyButton();
+ return false;
+ }
+
+ if (!roleMethod.getElementName().equals(FAKED_METHOD_NAME)
+ && Flags.isCallin(roleMethod.getFlags())
+ && !Flags.isAbstract(roleMethod.getFlags()))
+ {
+ toggleModifierButtons(OT_CALLOUT_OVERRIDE|
+ OT_CALLOUT|
+ Modifier.OT_AFTER_CALLIN|
+ Modifier.OT_BEFORE_CALLIN,
+ DESELECT_DISABLE_BUTTONS);
+ toggleApplyButton();
+ return false;
+ }
+ }
+ catch (JavaModelException ex)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ protected void checkSubclass() {}
+
+ public IMember[] getBaseMethods(IType baseClass) throws JavaModelException
+ {
+ List<IMember> result = new ArrayList<IMember>();
+ //FIXME: cleaner but way(!) too slow:
+ //TypeHelper.getInheritedMethods(baseClass, true, false, false, new NullProgressMonitor());//
+
+ // ---------- stolen (and adapted) from CallinMapping.findBaseMethods():
+ IType[] typeParents = TypeHelper.getSuperTypes(baseClass);
+ if (OTModelManager.hasOTElementFor(baseClass)) {
+ IOTType otType = OTModelManager.getOTElement(baseClass);
+ if (otType.isRole()) {
+ IType[] implicitSupers = TypeHelper.getImplicitSuperTypes((IRoleType)otType);
+ int len1 = implicitSupers.length;
+ int len2 = typeParents.length;
+ // shift to back:
+ System.arraycopy(
+ typeParents, 0,
+ typeParents = new IType[len1+len2-1],
+ len1-1, // let tsupers overwrite first element which repeats the original baseClass
+ len2);
+ // insert at front (implicit has higher priority)
+ System.arraycopy(
+ implicitSupers, 0,
+ typeParents, 0,
+ len1);
+ }
+ }
+ HashSet<String> signatures = new HashSet<String>(); // for filtering of duplicates.
+ for (int i = 0; i < typeParents.length; i++) {
+ if (typeParents[i].getFullyQualifiedName().equals(TypeHelper.JAVA_LANG_OBJECT))
+ continue;
+ // TODO(SH): don't include private fields from super classes
+ IField[] fields = typeParents[i].getFields();
+ for (int fieldIdx = 0; fieldIdx < fields.length; fieldIdx++)
+ {
+ IField field = fields[fieldIdx];
+ String signature = field.getElementName()+field.getTypeSignature();
+ if (!signatures.contains(signature))
+ {
+ result.add(field);
+ signatures.add(signature);
+ }
+ }
+
+ IMethod[] methods = typeParents[i].getMethods();
+ for (int methIdx = 0; methIdx < methods.length; methIdx++)
+ {
+ IMethod method = methods[methIdx];
+ String signature = method.getElementName()+method.getSignature();
+ if ( !method.isConstructor()
+ && !signatures.contains(signature))
+ {
+ result.add(method);
+ signatures.add(signature);
+ }
+ }
+ }
+ // -----------
+
+ return result.toArray(new IMember[result.size()]);
+ }
+
+ public void setFocusRole(RoleTypeDeclaration focusRole, IType teamType, boolean initial)
+ {
+ if (initial)
+ {
+ _selectedCallinDecl = null;
+ _selectedCalloutDecl = null;
+ _parameterMappings = null;
+ }
+
+ _selectedRole = focusRole;
+
+ IJavaProject project = teamType.getCompilationUnit().getJavaProject();
+ IType teamClass = null;
+ // implicit inherited role class methods
+ try
+ {
+ teamClass = project.findType(teamType.getFullyQualifiedName('.'));
+ _roleMethods = TypeHelper.getAllRoleMethods(
+ teamClass,
+ focusRole.getName().toString());
+
+ }
+ catch (JavaModelException ex)
+ {
+ openErrorDialog(Messages.BindingConfiguration_error_retrieving_role_methods);
+ }
+
+ Type baseType = focusRole.getBaseClassType();
+
+ // base class methods
+ if (baseType != null)
+ {
+ try
+ {
+ String qualifiedBaseName = null;
+ if (baseType instanceof SimpleType) {
+ // try for cached names (those roles created within the binding editor):
+ Name baseName = ((SimpleType)baseType).getName();
+ qualifiedBaseName = (baseName instanceof QualifiedName) ?
+ baseName.getFullyQualifiedName() :
+ this._bindingEditor._baseClassLookup.get(((SimpleName)baseName).getIdentifier());
+ }
+ if (qualifiedBaseName == null) // other roles should be resolvable:
+ qualifiedBaseName = focusRole.resolveBinding().getBaseClass().getQualifiedName();
+
+ if (qualifiedBaseName != null)
+ _baseMethods = getBaseMethods(project.findType(qualifiedBaseName));
+ else
+ OTDTUIPlugin.getExceptionHandler().logCoreException("Failed to resolve focus role - no methods available.", null); //$NON-NLS-1$
+ }
+ catch (JavaModelException ex)
+ {
+ OTDTUIPlugin.getExceptionHandler().logCoreException(ex.getMessage(), ex);
+ }
+ }
+
+ // clear selection
+ _roleMethListViewer.setSelection(new StructuredSelection(EMPTY_LIST));
+ _baseMethListViewer.setSelection(new StructuredSelection(EMPTY_LIST));
+ _roleMethListViewer.refresh();
+ _baseMethListViewer.refresh();
+ _methMapBtnComp.enableAll();
+ _methMapBtnComp.deselectAll();
+ toggleApplyButton();
+ }
+
+ IType findRoleType (IType teamClass, String roleName)
+ throws JavaModelException
+ {
+ IType[] roles = teamClass.getTypes();
+ for (IType roleType : roles)
+ if (roleType.getElementName().equals(roleName))
+ return roleType;
+
+ for (IType roleType : roles)
+ {
+ IType result = findRoleType(roleType, roleName);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ private void toggleApplyButton()
+ {
+ if (_baseMethListViewer.getSelection().isEmpty()
+ || _roleMethListViewer.getSelection().isEmpty()
+ || (_methMapBtnComp.getSelectedButton() == null))
+ {
+ _applyBtn.setEnabled(false);
+ }
+ else
+ {
+ _applyBtn.setEnabled(true);
+ }
+ }
+
+ public void setCalloutMapping(ASTNode selectedNode, IType teamType)
+ {
+ if ( !(selectedNode instanceof CalloutMappingDeclaration) )
+ {
+ return;
+ }
+
+ _selectedCallinDecl = null;
+ _selectedCalloutDecl = (CalloutMappingDeclaration)selectedNode;
+ RoleTypeDeclaration roleTypeDecl = (RoleTypeDeclaration)_selectedCalloutDecl.getParent();
+ setFocusRole(roleTypeDecl, teamType, false);
+
+ MethodSpec roleMethSpec = (MethodSpec)_selectedCalloutDecl.getRoleMappingElement();
+ IMember roleMeth = findCorrespondingIMember(roleMethSpec, _roleMethods, null);
+ if (roleMeth != null)
+ {
+ _roleMethListViewer.setSelection( new StructuredSelection(roleMeth) );
+ }
+ else
+ {
+ _roleMethListViewer.setSelection( new StructuredSelection(_fakedMeth) );
+ }
+
+ MethodMappingElement baseSpec = (MethodMappingElement)_selectedCalloutDecl.getBaseMappingElement();
+ List<MethodMappingElement> baseSpecs = new ArrayList<MethodMappingElement>();
+ baseSpecs.add(baseSpec);
+ List<IMember> curBaseMeths = findCorrespondingIMembers(baseSpecs, _baseMethods);
+ if (curBaseMeths != null)
+ {
+ _baseMethListViewer.setSelection( new StructuredSelection(curBaseMeths) );
+ }
+ else
+ {
+ _baseMethListViewer.setSelection( new StructuredSelection(EMPTY_LIST) );
+ }
+
+ _parameterMappings = _selectedCalloutDecl.getParameterMappings();
+
+
+ if( _selectedCalloutDecl.isCalloutOverride())
+ {
+ _methMapBtnComp.setSelectionButton(_calloutOverrideBtn);
+ }
+ else
+ {
+ _methMapBtnComp.setSelectionButton(_calloutBtn);
+ }
+
+ toggleApplyButton();
+ }
+
+ public void setCallinMapping(ASTNode selectedNode, IType teamType)
+ {
+ if ( !(selectedNode instanceof CallinMappingDeclaration))
+ {
+ return;
+ }
+
+ _selectedCalloutDecl = null;
+ _selectedCallinDecl = (CallinMappingDeclaration)selectedNode;
+
+ RoleTypeDeclaration roleTypeDecl = (RoleTypeDeclaration)_selectedCallinDecl.getParent();
+ setFocusRole(roleTypeDecl, teamType, false);
+
+ MethodSpec roleMethSpec = (MethodSpec)_selectedCallinDecl.getRoleMappingElement();
+ IMember roleMeth = findCorrespondingIMember(roleMethSpec, _roleMethods, null);
+ if (roleMeth != null)
+ {
+ _roleMethListViewer.setSelection( new StructuredSelection(roleMeth) );
+ }
+ else
+ {
+ _roleMethListViewer.setSelection( new StructuredSelection(EMPTY_LIST) );
+ }
+
+ java.util.List<MethodMappingElement> baseMapElems = _selectedCallinDecl.getBaseMappingElements();
+ if (baseMapElems.size() == 0)
+ {
+ return;
+ }
+
+ java.util.List<IMember> baseMembs = findCorrespondingIMembers(baseMapElems, _baseMethods);
+ if (baseMembs != null)
+ {
+ _baseMethListViewer.setSelection( new StructuredSelection(baseMembs) );
+ }
+ else
+ {
+ _baseMethListViewer.setSelection( new StructuredSelection(EMPTY_LIST) );
+ }
+
+ _parameterMappings = _selectedCallinDecl.getParameterMappings();
+
+ toggleModifierButtons(_selectedCallinDecl.getCallinModifier(), SELECT_BUTTONS);
+ toggleApplyButton();
+ }
+
+ private List<IMember> findCorrespondingIMembers(List<MethodMappingElement> methodSpecs, IMember[] members)
+ {
+ Hashtable<String, Integer> methodAppearances = getMethodAppearances(members);
+
+ List<IMember> baseMembers = new ArrayList<IMember>();
+ for (Iterator<MethodMappingElement> iter = methodSpecs.iterator(); iter.hasNext();)
+ {
+ MethodMappingElement methodSpec = iter.next();
+
+ IMember foundMethod = findCorrespondingIMember(methodSpec, members, methodAppearances);
+ baseMembers.add(foundMethod);
+ }
+ return baseMembers;
+ }
+
+ private IMember findCorrespondingIMember(MethodMappingElement methodSpec, IMember[] methods, Hashtable<String, Integer> methodAppearances)
+ {
+ if (methodAppearances == null)
+ methodAppearances = getMethodAppearances(methods);
+
+ String methodName = methodSpec.getName().toString();
+ for (int idx = 0; idx < methods.length; idx++)
+ {
+ if (methodName.equals(methods[idx].getElementName()))
+ {
+ Integer value = methodAppearances.get(methodName);
+ if (value.intValue() > 1)
+ {
+ // FIXME(SH): handle field cases:
+ if ( methodSpec instanceof MethodSpec
+ && methods[idx] instanceof IMethod)
+ {
+ List parameters = ((MethodSpec)methodSpec).parameters();
+ String []parameterTypes = ((IMethod)methods[idx]).getParameterTypes();
+
+ if (parameters.size() != parameterTypes.length)
+ {
+ continue;
+ }
+
+ if (validateParameterMatching(parameters, parameterTypes))
+ {
+ return methods[idx];
+ }
+ }
+ }
+ else
+ {
+ return methods[idx];
+ }
+ }
+ }
+ return null;
+ }
+
+ private boolean validateParameterMatching(List parameters, String[] parameterTypes)
+ {
+ boolean totallyMatch = true;
+ int counter = 0;
+ for (Iterator iter = parameters.iterator(); iter.hasNext();)
+ {
+ SingleVariableDeclaration variable = (SingleVariableDeclaration) iter .next();
+ String paramTypeNameFromMethodSpec = null;
+
+ if (variable.getType().isPrimitiveType())
+ {
+ paramTypeNameFromMethodSpec = ((PrimitiveType)variable.getType()).getPrimitiveTypeCode().toString();
+ }
+
+ if (variable.getType().isSimpleType())
+ {
+ ITypeBinding typeBinding =((SimpleType)variable.getType()).resolveBinding();
+ if (typeBinding == null)
+ {
+ paramTypeNameFromMethodSpec = ((SimpleType)variable.getType()).getName().getFullyQualifiedName();
+ }
+ else
+ {
+ paramTypeNameFromMethodSpec = typeBinding.getQualifiedName();
+ }
+ }
+
+ if (variable.getType().isArrayType())
+ {
+ Type arrayType = ((ArrayType)variable.getType()).getComponentType();
+ if (arrayType.isPrimitiveType())
+ {
+ paramTypeNameFromMethodSpec = ((PrimitiveType)arrayType).getPrimitiveTypeCode().toString();
+ }
+
+ if (arrayType.isSimpleType())
+ {
+ ITypeBinding typeBinding =((SimpleType)arrayType).resolveBinding();
+ if (typeBinding == null)
+ {
+ paramTypeNameFromMethodSpec = ((SimpleType)arrayType).getName().getFullyQualifiedName();
+ }
+ else
+ {
+ paramTypeNameFromMethodSpec = typeBinding.getQualifiedName();
+ }
+ }
+ paramTypeNameFromMethodSpec += "[]"; //$NON-NLS-1$
+ }
+
+ //TODO(ike): Find a way to resolved parameters of methodSpecs to get fully qualified names
+ String paramTypeNameFromIMethod = Signature.toString(parameterTypes[counter]);
+ String simpleTypeName = getSimpleParameterName(paramTypeNameFromIMethod);
+ if (!simpleTypeName.equals(paramTypeNameFromMethodSpec))
+ {
+ totallyMatch = false;
+ }
+
+ counter++;
+ }
+ return totallyMatch;
+ }
+
+
+ private String getSimpleParameterName(String parameterName)
+ {
+ String [] simpleNameArray = parameterName.split("\\."); //$NON-NLS-1$
+ if (simpleNameArray.length == 0)
+ return parameterName;
+ else
+ return simpleNameArray[simpleNameArray.length - 1];
+ }
+
+ private Hashtable<String, Integer> getMethodAppearances(IMember[] methods)
+ {
+ Hashtable<String, Integer> appearances = new Hashtable<String, Integer>();
+ for (int idx = 0; idx < methods.length; idx++)
+ {
+ String methodName = methods[idx].getElementName();
+ if (appearances.containsKey(methodName))
+ {
+ Integer value = appearances.get(methodName);
+ int app = value.intValue();
+ app++;
+ appearances.put(methodName, new Integer(app));
+ }
+ else
+ {
+ appearances.put(methodName, new Integer(1));
+ }
+ }
+ return appearances;
+ }
+
+ private void toggleModifierButtons(int modifiers, int selectionLevel)
+ {
+ List<Button> buttonList = getButtonsForModifiers(modifiers);
+
+ switch (selectionLevel)
+ {
+ case SELECT_BUTTONS:
+ for (Iterator<Button> iter = buttonList.iterator(); iter.hasNext();)
+ {
+ Button button = iter.next();
+ _methMapBtnComp.setSelectionButton(button);
+ }
+ break;
+
+ case DESELECT_DISABLE_BUTTONS:
+ if (Modifier.isReplace(modifiers))
+ {
+ _callinReplaceBtn.setEnabled(false);
+ _methMapBtnComp.removeSelectionButton(_callinReplaceBtn);
+ }
+ else
+ {
+ _callinReplaceBtn.setEnabled(true);
+ }
+
+ if (Modifier.isBefore(modifiers))
+ {
+ _callinBeforeBtn.setEnabled(false);
+ _methMapBtnComp.removeSelectionButton(_callinBeforeBtn);
+ }
+ else
+ {
+ _callinBeforeBtn.setEnabled(true);
+ }
+
+ if (Modifier.isAfter(modifiers))
+ {
+ _callinAfterBtn.setEnabled(false);
+ _methMapBtnComp.removeSelectionButton(_callinAfterBtn);
+ }
+ else
+ {
+ _callinAfterBtn.setEnabled(true);
+ }
+
+ if (isCallout(modifiers))
+ {
+ _calloutBtn.setEnabled(false);
+ _methMapBtnComp.removeSelectionButton(_calloutBtn);
+ }
+ else
+ {
+ _calloutBtn.setEnabled(true);
+ }
+
+ if (isCalloutOverride(modifiers))
+ {
+ _calloutOverrideBtn.setEnabled(false);
+ _methMapBtnComp.removeSelectionButton(_calloutOverrideBtn);
+ }
+ else
+ {
+ _calloutOverrideBtn.setEnabled(true);
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ private List<Button> getButtonsForModifiers(int modifiers)
+ {
+ List<Button> buttonList = new ArrayList<Button>();
+
+ if (Modifier.isReplace(modifiers))
+ buttonList.add(_callinReplaceBtn);
+
+ if (Modifier.isBefore(modifiers))
+ buttonList.add(_callinBeforeBtn);
+
+ if (Modifier.isAfter(modifiers))
+ buttonList.add(_callinAfterBtn);
+
+ if (isCallout(modifiers))
+ buttonList.add(_calloutBtn);
+
+ if (isCalloutOverride(modifiers))
+ buttonList.add(_calloutBtn);
+
+ return buttonList;
+ }
+
+ private boolean isCalloutOverride(int modifiers)
+ {
+ return (modifiers & OT_CALLOUT_OVERRIDE) != 0;
+ }
+
+ private boolean isCallout(int modifiers)
+ {
+ return (modifiers & OT_CALLOUT) != 0;
+ }
+
+ private void addButtonListener(Button button)
+ {
+ SelectionListener buttonListener = new SelectionListener() {
+ public void widgetSelected(SelectionEvent evt)
+ {
+ Button selectedButton = (Button)evt.getSource();
+ _methMapBtnComp.doRadioButtonBehavior(selectedButton);
+ toggleApplyButton();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent evt) {}
+ };
+ button.addSelectionListener(buttonListener);
+ }
+
+ private void addApplyButtonListener(Button applyButton)
+ {
+ SelectionListener applyButtonListener = new SelectionAdapter()
+ {
+ public void widgetSelected(SelectionEvent evt)
+ {
+ applyPressed();
+ }
+ };
+ applyButton.addSelectionListener(applyButtonListener);
+ }
+
+ private boolean createMethodMapping()
+ {
+ int methMapModifier = 0;
+ boolean calloutOverride = false;
+ boolean signatureFlag = true;
+ _newCallout = true;
+ Button selectedButton = _methMapBtnComp.getSelectedButton();
+
+ if (_calloutBtn.equals(selectedButton))
+ {
+ methMapModifier = 0;
+ _newCallout = true;
+ }
+ if (_calloutOverrideBtn.equals(selectedButton))
+ {
+ calloutOverride = true;
+ methMapModifier = 0;
+ _newCallout = true;
+ }
+ if (_callinReplaceBtn.equals(selectedButton))
+ {
+ methMapModifier = Modifier.OT_REPLACE_CALLIN;
+ _newCallout = false;
+ }
+ if (_callinBeforeBtn.equals(selectedButton))
+ {
+ methMapModifier = Modifier.OT_BEFORE_CALLIN;
+ _newCallout = false;
+ }
+ if (_callinAfterBtn.equals(selectedButton))
+ {
+ methMapModifier = Modifier.OT_AFTER_CALLIN;
+ _newCallout = false;
+ }
+
+ StructuredSelection selectedRoleMethod = (StructuredSelection)_roleMethListViewer.getSelection();
+ if (selectedRoleMethod.isEmpty())
+ {
+ return false;
+ }
+
+ StructuredSelection selectedBaseMethods = (StructuredSelection)_baseMethListViewer.getSelection();
+ if (selectedBaseMethods.isEmpty())
+ {
+ return false;
+ }
+
+ IMethod roleMethod = (IMethod) selectedRoleMethod.getFirstElement();
+ IMember[] baseMethods = new IMember[selectedBaseMethods.size()];
+ int baseMethodsCount = 0;
+ for (Iterator iter = selectedBaseMethods.iterator(); iter.hasNext();)
+ {
+ IMember baseMethod = (IMember) iter.next();
+ baseMethods[baseMethodsCount++] = baseMethod;
+ }
+
+ AST ast = _selectedRole.getAST();
+
+ if (_newCallout)
+ {
+ return createCalloutMapping(ast, roleMethod, baseMethods[0], methMapModifier, calloutOverride, signatureFlag);
+ }
+ else
+ {
+ return createCallinMapping(ast, roleMethod, baseMethods, methMapModifier, signatureFlag);
+ }
+ }
+
+ private boolean createCallinMapping(AST ast, IMethod roleIMethod, IMember[] baseMethods, int modifier, boolean signatureFlag)
+ {
+ // can only bind methods in callin:
+ for (IMember member : baseMethods)
+ if (!(member instanceof IMethod))
+ return false;
+
+ MethodSpec givenRoleMSpec = null;
+ List<MethodSpec> givenBaseMSpecs = null;
+ if (_selectedCallinDecl != null)
+ {
+ givenRoleMSpec = (MethodSpec)_selectedCallinDecl.getRoleMappingElement();
+ givenBaseMSpecs = _selectedCallinDecl.getBaseMappingElements();
+ }
+
+ IMethod templateForRoleMethodSpec = roleIMethod;
+ if (templateForRoleMethodSpec.getElementName().startsWith(FAKED_METHOD_NAME))
+ templateForRoleMethodSpec = (IMethod)baseMethods[0]; // use the first base method as template for the role method spec
+ // FIXME: support automatic creation of a new role method
+
+ MethodSpec roleMethodSpec = createMethodSpec(ast, templateForRoleMethodSpec, givenRoleMSpec, signatureFlag);
+ if (roleMethodSpec == null)
+ return false;
+
+ List<MethodMappingElement> baseMethodSpecs = new ArrayList<MethodMappingElement>();
+ for (int idx = 0; idx < baseMethods.length; idx++)
+ {
+ IMethod baseIMethod = (IMethod)baseMethods[idx];
+ MethodSpec baseMSpec = null;
+
+ if ((givenBaseMSpecs != null) && baseMethods.length == 1)
+ {
+ baseMSpec = givenBaseMSpecs.get(idx);
+ }
+
+ MethodMappingElement baseMethodSpec = createMethodSpec(ast, baseIMethod, baseMSpec, signatureFlag);
+ if (baseMethodSpec!= null)
+ {
+ baseMethodSpecs.add(baseMethodSpec);
+ }
+ }
+ if (_selectedCallinDecl == null)
+ {
+ _parameterMappings = null;
+ }
+
+ _callinMapping = ASTNodeCreator.createCallinMappingDeclaration(
+ ast,
+ null,
+ modifier,
+ roleMethodSpec,
+ baseMethodSpecs,
+ _parameterMappings);
+
+ return true;
+ }
+
+ private boolean createCalloutMapping(
+ AST ast,
+ IMethod roleMethod,
+ IMember baseMethod,
+ int bindingModifier,
+ boolean calloutOverride,
+ boolean signatureFlag)
+ {
+ MethodSpec selRolMethSpec = null;
+ MethodMappingElement selBasMethSpec = null;
+
+ if (_selectedCalloutDecl != null)
+ {
+ selRolMethSpec = (MethodSpec)_selectedCalloutDecl.getRoleMappingElement();
+ selBasMethSpec = _selectedCalloutDecl.getBaseMappingElement();
+ if (baseMethod instanceof IMethod && !(selBasMethSpec instanceof MethodSpec))
+ return false; // cannot change from method to field.
+ }
+
+ MethodMappingElement baseMethodSpec = null;
+ if (baseMethod instanceof IMethod)
+ baseMethodSpec = createMethodSpec(
+ ast,
+ (IMethod)baseMethod,
+ (MethodSpec)selBasMethSpec,
+ signatureFlag);
+ /* FIXME: implement all other combinations
+ else
+ baseMethodSpec = createFieldAccessSpec(ast, (IField)baseIMember, baseMSpec, signatureFlag);
+ */
+ if (baseMethodSpec == null)
+ {
+ return false;
+ }
+
+ MethodMappingElement roleMethodSpec = null;
+ if (roleMethod.getElementName().startsWith(FAKED_METHOD_NAME))
+ {
+ if (baseMethod instanceof IMethod)
+ roleMethodSpec = createMethodSpec(
+ ast,
+ (IMethod)baseMethod,
+ (MethodSpec)selBasMethSpec,
+ signatureFlag);
+ /* FIXME: implement:
+ else
+ roleMethodSpec = createFieldAccess((IField)baseMethod...);
+ */
+ }
+ else
+ {
+ roleMethodSpec = createMethodSpec(
+ ast,
+ roleMethod,
+ selRolMethSpec,
+ signatureFlag);
+ }
+ if (roleMethodSpec == null)
+ {
+ return false;
+ }
+
+ if (_selectedCalloutDecl == null)
+ {
+ _parameterMappings = null;
+ }
+
+ _calloutMapping = ASTNodeCreator.createCalloutMappingDeclaration(
+ ast,
+ null,
+ 0, // modifiers
+ roleMethodSpec,
+ baseMethodSpec,
+ bindingModifier, // FIXME(SH): not yet provided from caller
+ _parameterMappings,
+ calloutOverride,
+ signatureFlag);
+
+ return true;
+ }
+
+ private MethodSpec createMethodSpec(AST ast, IMethod iMethod, MethodSpec givenMethodSpec, boolean signatureFlag)
+ {
+ String returnTypeString;
+ try
+ {
+ returnTypeString = Signature.toString(iMethod.getReturnType());
+ }
+ catch (JavaModelException e)
+ {
+ return null;
+ }
+
+ Type returnType = ASTNodeCreator.createType(ast, returnTypeString);
+
+ String [] parameterTypes = iMethod.getParameterTypes();
+ String [] parameterNames = null;
+
+ try
+ {
+ parameterNames = iMethod.getParameterNames();
+ }
+ catch (JavaModelException e1)
+ {
+ return null;
+ }
+
+ List mSpecParameters = null;
+ if (givenMethodSpec != null)
+ {
+ mSpecParameters = givenMethodSpec.parameters();
+ }
+
+ java.util.List<SingleVariableDeclaration> methodParameters = new ArrayList<SingleVariableDeclaration>();
+ for (int idx = 0; idx < parameterTypes.length; idx++)
+ {
+ Type parameterType = ASTNodeCreator.createType(
+ ast,
+ Signature.getSimpleName(Signature.toString(parameterTypes[idx])));
+
+ SingleVariableDeclaration roleParameter;
+ if (mSpecParameters != null && mSpecParameters.size()==parameterNames.length)
+ {
+ SingleVariableDeclaration param = (SingleVariableDeclaration)mSpecParameters.get(idx);
+ roleParameter =
+ ASTNodeCreator.createArgument(ast, 0, parameterType, param.getName().toString(), 0, null);
+ }
+ else
+ {
+ roleParameter =
+ ASTNodeCreator.createArgument(ast, 0, parameterType, parameterNames[idx], 0, null);
+ }
+
+ methodParameters.add(roleParameter);
+
+ }
+
+ MethodSpec methodSpec = ASTNodeCreator.createMethodSpec(
+ ast,
+ iMethod.getElementName(),
+ returnType,
+ methodParameters,
+ signatureFlag
+ );
+
+
+ return methodSpec;
+ }
+
+ //copied from org.soothsayer.util.ASTNodeHelper;
+ public static String getMethodSignature(IMethod meth)
+ {
+ StringBuffer result = new StringBuffer();
+
+ if (meth != null)
+ {
+ result.append(meth.getElementName());
+ result.append('(');
+
+ String[] parameterTypes = meth.getParameterTypes();
+ for (int idx = 0; idx < parameterTypes.length; idx++)
+ {
+ String curType = parameterTypes[idx];
+ result.append(curType);
+ if (idx < parameterTypes.length)
+ {
+ result.append(", "); //$NON-NLS-1$
+ }
+ }
+ result.append(')');
+ }
+
+ return result.toString();
+ }
+
+ public void resetLists()
+ {
+ _baseMethListViewer.getTable().removeAll();
+ _roleMethListViewer.getTable().removeAll();
+ _methMapBtnComp.enableAll();
+ _methMapBtnComp.deselectAll();
+ }
+
+ public void setCurrentTeamForMethodFake(IType teamType)
+ {
+ _curTeam = teamType;
+ }
+
+ private void applyPressed()
+ {
+ if (_selectedRole.isRoleFile()) {
+ openErrorDialog(MessageFormat.format(
+ Messages.BindingConfiguration_error_cant_edit_rolefile,
+ _selectedRole.getName().getIdentifier(),
+ _selectedRole.getName().getIdentifier()));
+ return;
+ }
+ RoleTypeDeclaration currentRole= _selectedRole;
+ while (true) {
+ currentRole= (RoleTypeDeclaration)ASTNodes.getParent(currentRole, ASTNode.ROLE_TYPE_DECLARATION);
+ if (currentRole == null)
+ break;
+ if (currentRole.isRoleFile()) {
+ openErrorDialog(MessageFormat.format(
+ Messages.BindingConfiguration_error_cant_edit_rolefile_nested,
+ new Object[]{_selectedRole.getName().getIdentifier(),
+ currentRole.getName().getIdentifier(),
+ currentRole.getName().getIdentifier()}));
+ return;
+ }
+ currentRole= (RoleTypeDeclaration)ASTNodes.getParent(_selectedRole, ASTNode.ROLE_TYPE_DECLARATION);
+ }
+
+ _calloutMapping = null;
+ _callinMapping = null;
+ int selectedIndex = -1;
+
+ if (createMethodMapping())
+ {
+ if (_calloutMapping != null)
+ {
+ if (_selectedCalloutDecl != null)
+ {
+ selectedIndex = _selectedRole.bodyDeclarations().indexOf(_selectedCalloutDecl);
+ _selectedRole.bodyDeclarations().remove(_selectedCalloutDecl);
+ }
+ if (_selectedCallinDecl != null)
+ {
+ selectedIndex = _selectedRole.bodyDeclarations().indexOf(_selectedCallinDecl);
+ _selectedRole.bodyDeclarations().remove(_selectedCallinDecl);
+ }
+
+ if (selectedIndex == -1){
+ _selectedRole.bodyDeclarations().add(_calloutMapping);
+ }
+ else
+ {
+ _selectedRole.bodyDeclarations().add(selectedIndex, _calloutMapping);
+ }
+ }
+
+ if (_callinMapping != null)
+ {
+ if (_selectedCallinDecl != null)
+ {
+ selectedIndex = _selectedRole.bodyDeclarations().indexOf(_selectedCallinDecl);
+ _selectedRole.bodyDeclarations().remove(_selectedCallinDecl);
+
+ }
+ if (_selectedCalloutDecl != null)
+ {
+ selectedIndex = _selectedRole.bodyDeclarations().indexOf(_selectedCalloutDecl);
+ _selectedRole.bodyDeclarations().remove(_selectedCalloutDecl);
+ }
+
+ if (selectedIndex == -1)
+ {
+ _selectedRole.bodyDeclarations().add(_callinMapping);
+ }
+ else
+ {
+ _selectedRole.bodyDeclarations().add(selectedIndex, _callinMapping);
+ }
+ }
+
+ // clear selection
+ _roleMethListViewer.setSelection(new StructuredSelection(EMPTY_LIST));
+ _baseMethListViewer.setSelection(new StructuredSelection(EMPTY_LIST));
+ _roleMethListViewer.refresh();
+ _baseMethListViewer.refresh();
+
+ _bindingEditor.refresh();
+
+ AbstractMethodMappingDeclaration mapping = _callinMapping;
+ if (mapping == null)
+ mapping = _calloutMapping;
+ _bindingEditor.methodBindingAdded(mapping);
+ }
+ else
+ {
+ openErrorDialog(Messages.BindingConfiguration_error_binding_creation_failed);
+
+ _roleMethListViewer.setSelection(new StructuredSelection(EMPTY_LIST));
+ _baseMethListViewer.setSelection(new StructuredSelection(EMPTY_LIST));
+ _roleMethListViewer.refresh();
+ _baseMethListViewer.refresh();
+ _methMapBtnComp.enableAll();
+ _methMapBtnComp.deselectAll();
+
+ _bindingEditor.refresh();
+ }
+ }
+
+ private void openErrorDialog(String message)
+ {
+ MessageDialog.openError(getShell(), Messages.BindingConfiguration_error_unspecific, message);
+ }
+
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/BindingEditor.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/BindingEditor.java
new file mode 100644
index 0000000..5bc696f
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/BindingEditor.java
@@ -0,0 +1,721 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2005, 2007 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: BindingEditor.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.bindingeditor;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.AbstractMethodMappingDeclaration;
+import org.eclipse.jdt.core.dom.CallinMappingDeclaration;
+import org.eclipse.jdt.core.dom.CalloutMappingDeclaration;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.FieldAccessSpec;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.IVariableBinding;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.MethodMappingElement;
+import org.eclipse.jdt.core.dom.Modifier;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.ParameterMapping;
+import org.eclipse.jdt.core.dom.ParameterizedType;
+import org.eclipse.jdt.core.dom.QualifiedType;
+import org.eclipse.jdt.core.dom.RoleTypeDeclaration;
+import org.eclipse.jdt.core.dom.SimpleType;
+import org.eclipse.jdt.core.dom.Type;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.ui.ISharedImages;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.eclipse.objectteams.otdt.core.compiler.IOTConstants;
+import org.eclipse.objectteams.otdt.ui.ImageManager;
+
+/**
+ * The main UI class of the binding editor.
+ *
+ * @author jwloka
+ */
+public class BindingEditor extends Composite
+{
+ private IType _team;
+ final BindingConfiguration bindConfig;
+ private Tree _connTableTree;
+ private TabFolder _tabFolder;
+ private CallinMappingConfiguration _callinMapConfig;
+ private CalloutMappingConfiguration _calloutMapConfig;
+ private TabItem _paraMapItem;
+ private TabItem _methMapItem;
+ // for tab folder switching
+ private final TabItem[] _methMapItems;
+ private final TabItem[] _paraMapItems;
+ final TreeViewer _connTableViewer;
+ private TypeDeclaration _rootTeam;
+
+ /** Map single names to qualified names (only for bases of newly created roles. */
+ HashMap<String,String> _baseClassLookup = new HashMap<String,String>();
+
+ class TreeContentProvider implements IStructuredContentProvider, ITreeContentProvider
+ {
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+ public void dispose() {}
+
+ public Object[] getElements(Object inputElement)
+ {
+ TypeDeclaration decl = (TypeDeclaration)inputElement;
+ return decl.getTypes();
+ }
+
+ public Object[] getChildren(Object parentElement)
+ {
+ ASTNode node = (ASTNode)parentElement;
+ if (node.getNodeType() == ASTNode.ROLE_TYPE_DECLARATION)
+ {
+ RoleTypeDeclaration roleNode = (RoleTypeDeclaration)node;
+ Object[] callouts = roleNode.getCallOuts();
+ Object[] callins = roleNode.getCallIns();
+ Object[] roles = roleNode.getRoles();
+ Object[] result = new Object[roles.length+callouts.length+callins.length];
+ System.arraycopy(roles, 0, result, 0, roles.length);
+ System.arraycopy(callouts, 0, result, roles.length, callouts.length);
+ System.arraycopy(callins, 0, result, roles.length+callouts.length, callins.length);
+ return result;
+ }
+ else if (node.getNodeType() == ASTNode.CALLIN_MAPPING_DECLARATION
+ || node.getNodeType() == ASTNode.CALLOUT_MAPPING_DECLARATION)
+ {
+ AbstractMethodMappingDeclaration mapping =
+ (AbstractMethodMappingDeclaration)node;
+ List pMappings = mapping.getParameterMappings();
+ return pMappings.toArray();
+ }
+ else
+ {
+ return new Object[]{};
+ }
+ }
+
+ public Object getParent(Object element)
+ {
+ return null;
+ }
+
+ public boolean hasChildren(Object element)
+ {
+ return getChildren(element).length > 0;
+ }
+ }
+
+ class LabelProvider extends WorkbenchLabelProvider implements ITableLabelProvider
+ {
+ private static final String INDENT = " "; //$NON-NLS-1$
+ private static final String PARAMETER_MAPPING_RIGHT = "->"; //$NON-NLS-1$
+ private static final String EMPTY_TEXT = ""; //$NON-NLS-1$
+
+ public void addListener(ILabelProviderListener listener) {}
+ public void dispose() {}
+
+ public boolean isLabelProperty(Object element, String property)
+ {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {}
+
+ public Image getColumnImage(Object element, int columnIndex)
+ {
+ ASTNode node = (ASTNode)element;
+ switch (columnIndex) {
+ case 0: // role column
+ if (node.getNodeType() == ASTNode.ROLE_TYPE_DECLARATION) {
+ if (((RoleTypeDeclaration)node).isTeam())
+ return ImageManager.getSharedInstance().get(ImageManager.TEAM_ROLE_IMG);
+ else
+ return ImageManager.getSharedInstance().get(ImageManager.ROLECLASS_IMG);
+ }
+ break;
+ case 2: // base column
+ if (node.getNodeType() == ASTNode.ROLE_TYPE_DECLARATION) {
+ ITypeBinding binding= ((TypeDeclaration)node).resolveBinding();
+ if (binding != null)
+ binding= binding.getBaseClass();
+ if (binding != null) {
+ if (binding.isRole()) {
+ if (binding.isTeam())
+ return ImageManager.getSharedInstance().get(ImageManager.TEAM_ROLE_IMG);
+ else
+ return ImageManager.getSharedInstance().get(ImageManager.ROLECLASS_IMG);
+ } else if (binding.isTeam()) {
+ return ImageManager.getSharedInstance().get(ImageManager.TEAM_IMG);
+ }
+ }
+ return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_CLASS);
+ } else if (node.getNodeType() == ASTNode.CALLOUT_MAPPING_DECLARATION) {
+ MethodMappingElement baseMappingElement = ((CalloutMappingDeclaration)node).getBaseMappingElement();
+ if (baseMappingElement.getNodeType() == ASTNode.FIELD_ACCESS_SPEC)
+ {
+ IVariableBinding field= ((FieldAccessSpec)baseMappingElement).resolveBinding();
+ if (field != null) {
+ if (Modifier.isPublic(field.getModifiers()))
+ return JavaUI.getSharedImages().getImage(ISharedImages.IMG_FIELD_PUBLIC);
+ if (Modifier.isProtected(field.getModifiers()))
+ return JavaUI.getSharedImages().getImage(ISharedImages.IMG_FIELD_PROTECTED);
+ if (Modifier.isPrivate(field.getModifiers()))
+ return JavaUI.getSharedImages().getImage(ISharedImages.IMG_FIELD_PRIVATE);
+ }
+ return JavaUI.getSharedImages().getImage(ISharedImages.IMG_FIELD_DEFAULT);
+ }
+ }
+ break;
+ case 1: // mapping kind column
+ switch (node.getNodeType()) {
+ case ASTNode.CALLIN_MAPPING_DECLARATION:
+ int callinModifier = ((CallinMappingDeclaration)element).getCallinModifier();
+ if (Modifier.isAfter(callinModifier))
+ return ImageManager.getSharedInstance().get(ImageManager.CALLINBINDING_AFTER_IMG);
+ else if(Modifier.isBefore(callinModifier))
+ return ImageManager.getSharedInstance().get(ImageManager.CALLINBINDING_BEFORE_IMG);
+ else
+ return ImageManager.getSharedInstance().get(ImageManager.CALLINBINDING_REPLACE_IMG);
+
+ case ASTNode.CALLOUT_MAPPING_DECLARATION:
+ return ImageManager.getSharedInstance().get(ImageManager.CALLOUTBINDING_IMG);
+
+ case ASTNode.PARAMETER_MAPPING:
+ ParameterMapping mapping = (ParameterMapping)element;
+ if (mapping.getDirection().equals(PARAMETER_MAPPING_RIGHT))
+ return ImageManager.getSharedInstance().get(ImageManager.CALLOUTBINDING_IMG);
+ else
+ return ImageManager.getSharedInstance().get(ImageManager.CALLINBINDING_REPLACE_IMG); // ups ;-)
+ }
+ }
+ return null;
+ }
+
+
+ public String getColumnText(Object element, int columnIndex)
+ {
+ ASTNode node = (ASTNode)element;
+ switch (node.getNodeType())
+ {
+ case ASTNode.ROLE_TYPE_DECLARATION:
+ {
+ RoleTypeDeclaration role = (RoleTypeDeclaration)element;
+ switch (columnIndex)
+ {
+ case 0:
+ return role.getName().getIdentifier();
+ case 1:
+ return EMPTY_TEXT;
+ case 2:
+ Name baseClass = getRoleBaseClass(role);
+ if (baseClass != null)
+ return baseClass.getFullyQualifiedName();
+ else
+ return EMPTY_TEXT;
+ default:
+ return EMPTY_TEXT;
+ }
+ }
+ case ASTNode.CALLIN_MAPPING_DECLARATION:
+ {
+ CallinMappingDeclaration callinDecl = (CallinMappingDeclaration)element;
+ switch (columnIndex)
+ {
+ case 0:
+ return callinDecl.getRoleMappingElement().toString();
+ case 1:
+
+ if (Modifier.isAfter(callinDecl.getCallinModifier()))
+ {
+ return new String(IOTConstants.NAME_AFTER);
+ }
+ else if(Modifier.isBefore(callinDecl.getCallinModifier()))
+ {
+ return new String(IOTConstants.NAME_BEFORE);
+ }
+ else if(Modifier.isReplace(callinDecl.getCallinModifier()))
+ {
+ return new String(IOTConstants.NAME_REPLACE);
+ }
+ else
+ {
+ return EMPTY_TEXT;
+ }
+
+ //orig:
+ //return Modifier.ModifierKeyword.fromFlagValue(callinDecl.getModifiers()).toString();
+ case 2:
+ List baseMappingElements = callinDecl.getBaseMappingElements();
+ String result = INDENT;
+ for (int idx = 0; idx < baseMappingElements.size(); idx ++)
+ {
+ if (idx > 0)
+ {
+ result = result + ", "; //$NON-NLS-1$
+ }
+ result = result + baseMappingElements.get(idx).toString();
+ }
+ return result;
+ default:
+ return EMPTY_TEXT;
+ }
+ }
+ case ASTNode.CALLOUT_MAPPING_DECLARATION:
+ {
+ CalloutMappingDeclaration callout = (CalloutMappingDeclaration)element;
+ switch (columnIndex)
+ {
+ case 0:
+ return callout.getRoleMappingElement().toString();
+ case 1:
+ return EMPTY_TEXT;
+ case 2:
+ return INDENT+callout.getBaseMappingElement().toString();
+ default:
+ return EMPTY_TEXT;
+ }
+ }
+ case ASTNode.PARAMETER_MAPPING:
+ {
+ ParameterMapping mapping = (ParameterMapping)element;
+ switch (columnIndex)
+ {
+ case 0:
+ if (mapping.getDirection().equals(PARAMETER_MAPPING_RIGHT))
+ return mapping.getExpression().toString();
+ else
+ return mapping.getIdentifier().getIdentifier();
+ case 1:
+ return EMPTY_TEXT;
+ case 2:
+ if (mapping.getDirection().equals(PARAMETER_MAPPING_RIGHT))
+ return INDENT+mapping.getIdentifier();
+ else
+ return INDENT+mapping.getExpression().toString();
+ default:
+ return EMPTY_TEXT;
+ }
+ }
+ default:
+ {
+ return EMPTY_TEXT;
+ }
+ }
+ }
+ }
+
+
+ public BindingEditor(final Composite parent, int style, final IType teamType, final CompilationUnit root)
+ {
+ super(parent, style);
+ _team = teamType;
+ calculateRootNode(root);
+
+ setLayout(new FormLayout());
+
+ final Group connDefGroup = new Group(this, SWT.NONE);
+ connDefGroup.setText(Messages.BindingEditor_connector_title);
+ final FormData formData = new FormData();
+ formData.bottom = new FormAttachment(58, 0);
+ formData.right = new FormAttachment(100, -5);
+ formData.top = new FormAttachment(0, 5);
+ formData.left = new FormAttachment(0, 5);
+ connDefGroup.setLayoutData(formData);
+ connDefGroup.setLayout(new FormLayout());
+
+ _connTableViewer = new TreeViewer(connDefGroup, SWT.BORDER);
+ _connTableViewer.setContentProvider(new TreeContentProvider());
+ _connTableViewer.setLabelProvider(new LabelProvider());
+ _connTableViewer.setAutoExpandLevel(2);
+
+ _connTableTree = _connTableViewer.getTree();
+
+ final FormData formData_2 = new FormData();
+ formData_2.bottom = new FormAttachment(84, 0);
+ formData_2.right = new FormAttachment(100, -5);
+ formData_2.top = new FormAttachment(0, 5);
+ formData_2.left = new FormAttachment(0, 5);
+ _connTableTree.setLayoutData(formData_2);
+ _connTableTree.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected(SelectionEvent evt)
+ {
+ bindingTableSelectionChanged();
+ }
+ });
+
+ _connTableTree.setLinesVisible(true);
+ _connTableTree.setHeaderVisible(true);
+
+ final TreeColumn rolesCol = new TreeColumn(_connTableTree, SWT.NONE);
+ rolesCol.setWidth(300);
+ rolesCol.setText(Messages.BindingEditor_role_types_title);
+
+ final TreeColumn methMapColumn = new TreeColumn(_connTableTree, SWT.NONE);
+ methMapColumn.setWidth(80);
+
+ final TreeColumn baseCol = new TreeColumn(_connTableTree, SWT.NONE);
+ baseCol.setWidth(300);
+ baseCol.setText(Messages.BindingEditor_base_types_title);
+
+ // Note(SH): need all columns set before retrieving contents by setInput()
+ _connTableViewer.setInput(_rootTeam);
+
+ final Composite buttonComp = new Composite(connDefGroup, SWT.NONE);
+ final FormData formData_3 = new FormData();
+ formData_3.bottom = new FormAttachment(100, -5);
+ formData_3.right = new FormAttachment(100, -5);
+ formData_3.top = new FormAttachment(_connTableTree, 5, SWT.BOTTOM);
+ formData_3.left = new FormAttachment(_connTableTree, 0, SWT.LEFT);
+ buttonComp.setLayoutData(formData_3);
+ buttonComp.setLayout(new FormLayout());
+
+ final Button addConnBtn = new Button(buttonComp, SWT.NONE);
+ final FormData formData_4 = new FormData();
+ formData_4.top = new FormAttachment(0, 5);
+ formData_4.left = new FormAttachment(0, 5);
+ addConnBtn.setLayoutData(formData_4);
+ addConnBtn.setText(Messages.BindingEditor_add_type_binding_button);
+ addConnBtn.addSelectionListener( new SelectionAdapter()
+ {
+ @SuppressWarnings("unchecked")
+ public void widgetSelected(SelectionEvent evt)
+ {
+ IType roleClass = null;
+
+ AddTypeBindingDialog dlg =
+ AddTypeBindingDialog.create(parent.getShell(), teamType);
+ if (AddTypeBindingDialog.OK == dlg.open())
+ {
+ roleClass = dlg.getRoleType();
+ }
+ else
+ {
+ return;
+ }
+
+ AST ast = _rootTeam.getAST();
+
+ RoleTypeDeclaration role = ast.newRoleTypeDeclaration();
+ role.setName(ast.newSimpleName(roleClass.getElementName()));
+ role.setRole(true);
+ try {
+ int flags = roleClass.getFlags() & ~Modifier.ABSTRACT;
+ role.modifiers().addAll(ast.newModifiers(flags));
+ } catch (JavaModelException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ String qualifiedBaseTypeName = dlg.getBaseTypeName();
+ String[] identifiers = qualifiedBaseTypeName.split("\\."); //$NON-NLS-1$
+
+ // use the single name for playedBy:
+ int len = identifiers.length;
+ String singleName = identifiers[len-1];
+ role.setBaseClassType(ast.newSimpleType(ast.newName(singleName)));
+ BindingEditor.this._baseClassLookup.put(singleName, qualifiedBaseTypeName);
+
+ // add an import using the qualified name:
+ _rootTeam.bodyDeclarations().add(role);
+ ImportDeclaration baseImport = ast.newImportDeclaration();
+ baseImport.setBase(true);
+ baseImport.setName(ast.newName(identifiers));
+ root.imports().add(baseImport);
+
+ refresh();
+ _connTableViewer.setSelection(new StructuredSelection(role));
+ bindingTableSelectionChanged();
+ }
+ });
+
+ final Button remConnBtn = new Button(buttonComp, SWT.NONE);
+ final FormData formData_5 = new FormData();
+ formData_5.top = new FormAttachment(addConnBtn, 0, SWT.TOP);
+ formData_5.left = new FormAttachment(addConnBtn, 5, SWT.RIGHT);
+ remConnBtn.setLayoutData(formData_5);
+ remConnBtn.setText(Messages.BindingEditor_remove_button);
+ remConnBtn.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected(SelectionEvent evt)
+ {
+ removeElementsFromAST();
+ refresh();
+ bindConfig.resetLists();
+ }
+ });
+
+ // TabFolder
+ _tabFolder = new TabFolder(this, SWT.NONE);
+ final FormData formData_1 = new FormData();
+ formData_1.bottom = new FormAttachment(100, -5);
+ formData_1.right = new FormAttachment(100, -5);
+ formData_1.top = new FormAttachment(connDefGroup, 5, SWT.BOTTOM);
+ formData_1.left = new FormAttachment(0, 5);
+ _tabFolder.setLayoutData(formData_1);
+
+ // method mapping tab item
+ bindConfig = new BindingConfiguration(_tabFolder, SWT.NONE);
+ bindConfig.setCurrentTeamForMethodFake(teamType);
+
+ _methMapItem = new TabItem(_tabFolder, SWT.NONE);
+ _methMapItem.setText(Messages.BindingEditor_method_binding_tab);
+ _methMapItem.setControl(bindConfig);
+ _methMapItems = new TabItem[] { _methMapItem };
+
+
+ // parameter mapping tab item
+ _callinMapConfig = new CallinMappingConfiguration(_tabFolder, SWT.NONE);
+ _calloutMapConfig = new CalloutMappingConfiguration(_tabFolder, SWT.NONE);
+
+ _paraMapItem = new TabItem(_tabFolder, SWT.NONE);
+ _paraMapItem.setText(Messages.BindingEditor_param_mapping_tab);
+ _paraMapItem.setControl(_callinMapConfig);
+ _paraMapItems = new TabItem[] { _paraMapItem };
+ }
+
+ private void calculateRootNode(CompilationUnit cu)
+ {
+ // Note: we compare the source-start of the IType's name with the DOM node's simpleName's
+ // source-start, instead of using the type's start-position. This is because the IType's
+ // getSourceRange() method returns a different position than dom.TypeDeclaration.getStartPosition()
+ // depending on the type of comment before the type declaration (/** */ vs. /* */), so they
+ // didn't match.
+
+ try
+ {
+ final TypeDeclaration[] teamDecl = new TypeDeclaration[1];
+ final int teamPos = _team.getNameRange().getOffset();
+
+ ASTVisitor visitor = new org.eclipse.jdt.internal.corext.dom.GenericVisitor() {
+ public boolean visit(CompilationUnit node) {
+ for (Iterator iter = node.types().iterator(); iter.hasNext();) {
+ TypeDeclaration type = (TypeDeclaration) iter.next();
+ if (!visit(type))
+ return false;
+ }
+ return false;
+ }
+
+ public boolean visit(TypeDeclaration node) {
+ int pos = node.getName().getStartPosition();
+ if (pos == teamPos) {
+ teamDecl[0] = node;
+ return false;
+ }
+
+ TypeDeclaration[] memberTypes = node.getTypes();
+ for (int i = 0; i < memberTypes.length; i++) {
+ if (!visit(memberTypes[i]))
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean visit(RoleTypeDeclaration node) {
+ return visit ((TypeDeclaration) node);
+ }
+
+ };
+
+ visitor.visit(cu);
+
+ _rootTeam = teamDecl[0];
+ }
+ catch (JavaModelException ex) {}
+ }
+
+ private void prepareParameterMappingConfiguration(
+ AbstractMethodMappingDeclaration methMap,
+ ParameterMapping paraMap)
+ {
+ if (methMap == null)
+ {
+ _paraMapItem.setControl(null);
+ }
+ else if (methMap instanceof CallinMappingDeclaration)
+ {
+ _paraMapItem.setControl(_callinMapConfig);
+ _callinMapConfig.setFocus(
+ paraMap,
+ (CallinMappingDeclaration)methMap);
+ }
+ else if (methMap instanceof CalloutMappingDeclaration)
+ {
+ _paraMapItem.setControl(_calloutMapConfig);
+ _calloutMapConfig.setFocus(
+ paraMap,
+ (CalloutMappingDeclaration)methMap);
+ }
+ }
+
+ private void removeElementsFromAST()
+ {
+ TreeItem[] selectedItems = _connTableTree.getSelection();
+ ASTNode selectedNode = null;
+
+ for (int idx = 0; idx < selectedItems.length; idx++)
+ {
+ selectedNode = (ASTNode)selectedItems[idx].getData();
+
+ if (selectedNode.getParent() instanceof TypeDeclaration)
+ {
+ removeElementFromAST(selectedNode);
+ }
+ else if(selectedNode.getParent() instanceof AbstractMethodMappingDeclaration)
+ {
+ removeElementFromAST((ParameterMapping)selectedNode);
+ }
+ }
+ }
+
+ /** Removes roles from teams and mappings from roles */
+ private void removeElementFromAST(ASTNode selectedNode)
+ {
+ TypeDeclaration parent = (TypeDeclaration)selectedNode.getParent();
+ parent.bodyDeclarations().remove(selectedNode);
+ }
+
+ /** Removes ParameterMappings from callin or callout */
+ private void removeElementFromAST(ParameterMapping selectedNode)
+ {
+ AbstractMethodMappingDeclaration abstractMethodMappingDeclaration =
+ (AbstractMethodMappingDeclaration)selectedNode.getParent();
+ abstractMethodMappingDeclaration.getParameterMappings().remove(selectedNode);
+ }
+
+ protected void checkSubclass() {}
+
+ private AbstractMethodMappingDeclaration getAbstractMethodMapping(ParameterMapping paraMap)
+ {
+ return (AbstractMethodMappingDeclaration)paraMap.getParent();
+ }
+
+ public void refresh()
+ {
+ _connTableViewer.refresh();
+ }
+
+ public void bindingTableSelectionChanged()
+ {
+ TreeItem[] selectedItems = _connTableTree.getSelection();
+ ASTNode selectedNode = null;
+
+ for (int idx = 0; idx < selectedItems.length; idx++)
+ {
+ selectedNode = (ASTNode)selectedItems[idx].getData();
+ switch (selectedNode.getNodeType())
+ {
+ case ASTNode.ROLE_TYPE_DECLARATION:
+ RoleTypeDeclaration roleTypeDecl =
+ (RoleTypeDeclaration)selectedNode;
+
+ bindConfig.setFocusRole(roleTypeDecl, _team, true);
+ prepareParameterMappingConfiguration(null, null);
+ _tabFolder.setSelection(_methMapItems);
+ break;
+ case ASTNode.CALLOUT_MAPPING_DECLARATION:
+ bindConfig.setCalloutMapping(selectedNode, _team);
+ prepareParameterMappingConfiguration(
+ (AbstractMethodMappingDeclaration)selectedNode,
+ null);
+ _tabFolder.setSelection(_methMapItems);
+ break;
+ case ASTNode.CALLIN_MAPPING_DECLARATION:
+ bindConfig.setCallinMapping(selectedNode, _team);
+ prepareParameterMappingConfiguration(
+ (AbstractMethodMappingDeclaration)selectedNode,
+ null);
+ _tabFolder.setSelection(_methMapItems);
+ break;
+ case ASTNode.PARAMETER_MAPPING:
+ ParameterMapping paraMap =
+ (ParameterMapping)selectedNode;
+
+ AbstractMethodMappingDeclaration methMap =
+ getAbstractMethodMapping(paraMap);
+ prepareParameterMappingConfiguration(methMap, paraMap);
+
+ _tabFolder.setSelection(_paraMapItems);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ public void methodBindingAdded(AbstractMethodMappingDeclaration mapping)
+ {
+ _connTableViewer.expandToLevel(mapping.getParent(), 1);
+ // Note(SH): do not select the new element, because this caused
+ // subsequent creation of method mappings to replace this method mapping.
+ // This problem annoyed us throughout all demos (Chicago) and tutorials (Erfurt, Bonn)!
+ //_connTableViewer.setSelection(new StructuredSelection(mapping));
+ bindingTableSelectionChanged();
+ }
+
+ private Name getRoleBaseClass(RoleTypeDeclaration element) {
+ Name result = null;
+ Type baseType = element.getBaseClassType();
+ if(baseType != null) {
+ if (baseType.isParameterizedType())
+ baseType= ((ParameterizedType)baseType).getType();
+ if(baseType.isSimpleType())
+ result = ((SimpleType)baseType).getName();
+ else
+ if(baseType.isQualifiedType())
+ result = ((QualifiedType)baseType).getName();
+ else
+ assert false; // what's that?
+ }
+ return result;
+ }
+
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/BindingEditorDialog.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/BindingEditorDialog.java
new file mode 100644
index 0000000..44f7dcc
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/BindingEditorDialog.java
@@ -0,0 +1,210 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2005, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: BindingEditorDialog.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.bindingeditor;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IBuffer;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.ui.actions.OrganizeImportsAction;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.text.edits.TextEdit;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IDE;
+
+/**
+ * The Main UI element of the binding editor.
+ *
+ * Created on Feb 7, 2005
+ *
+ * @author jwloka
+ * @version $Id: BindingEditorDialog.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class BindingEditorDialog extends Dialog
+{
+ private String _title;
+ protected IType _team;
+ private BindingEditor _bindingEditor;
+ private CompilationUnit _root;
+ private IDocument _originalDocument;
+
+ public BindingEditorDialog(Shell parentShell, IType teamType)
+ {
+ super(parentShell);
+ super.setShellStyle(getShellStyle() | SWT.RESIZE);
+ _title = Messages.BindingEditorDialog_dialog_title + teamType.getElementName();
+ _team = teamType;
+ }
+
+ public int open()
+ {
+ parseCurrentTeam();
+ openResource((IFile)_team.getCompilationUnit().getResource());
+
+ return super.open();
+ }
+
+ protected void configureShell(Shell shell)
+ {
+ super.configureShell(shell);
+ if (_title != null)
+ shell.setText(_title);
+ }
+
+ protected Control createDialogArea(Composite parent)
+ {
+
+ Composite container = (Composite) super.createDialogArea(parent);
+ container.setLayout(new FormLayout());
+
+ _bindingEditor = new BindingEditor(container, SWT.NONE, _team, _root);
+ final FormData formData = new FormData();
+ formData.bottom = new FormAttachment(100, -5);
+ formData.right = new FormAttachment(100, -5);
+ formData.top = new FormAttachment(0, 5);
+ formData.left = new FormAttachment(0, 5);
+ _bindingEditor.setLayoutData(formData);
+ return container;
+ }
+
+ protected void createButtonsForButtonBar(Composite parent)
+ {
+ createButton(
+ parent,
+ IDialogConstants.OK_ID,
+ IDialogConstants.OK_LABEL,
+ true);
+ createButton(
+ parent,
+ IDialogConstants.CANCEL_ID,
+ IDialogConstants.CANCEL_LABEL,
+ false);
+ }
+
+ protected Point getInitialSize()
+ {
+ Point calced = super.getInitialSize();
+ return new Point(Math.max(calced.x, 881), calced.y);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void okPressed()
+ {
+ setReturnCode(OK);
+
+ IProgressMonitor monitor = new NullProgressMonitor();
+ ICompilationUnit cu = _team.getCompilationUnit();
+ Map<String, String> options = cu.getJavaProject().getOptions(true);
+ // recognize OT/J syntax even in fragments not starting with "team":
+ options.put(org.eclipse.jdt.internal.compiler.impl.CompilerOptions.OPTION_AllowScopedKeywords,
+ org.eclipse.jdt.internal.compiler.impl.CompilerOptions.DISABLED);
+ TextEdit edits = _root.rewrite(_originalDocument, options);
+
+ try
+ {
+ edits.apply(_originalDocument);
+ String newSource = _originalDocument.get();
+ IBuffer buf = cu.getBuffer();
+ buf.setContents(newSource);
+ // TODO(jsv) use "organize imports" also for closed files, this version works only on open file
+ try
+ {
+ IWorkbenchPage activePage = org.eclipse.jdt.internal.ui.JavaPlugin.getActivePage();
+ IWorkbenchSite site = activePage.getActiveEditor().getEditorSite();
+ OrganizeImportsAction organizeImportsAction = new OrganizeImportsAction(site);
+ organizeImportsAction.run(cu);
+ }
+ catch (NullPointerException ex)
+ {
+ org.eclipse.jdt.internal.ui.JavaPlugin.log(ex);
+ }
+
+ buf.save(monitor, false);
+ }
+ catch (Exception ex)
+ {
+ org.eclipse.jdt.internal.ui.JavaPlugin.log(ex);
+ }
+ close();
+ }
+
+ private void openResource(final IFile resource)
+ {
+ try
+ {
+ IDE.openEditor(org.eclipse.jdt.internal.ui.JavaPlugin.getActivePage(), resource, true);
+ }
+ catch (PartInitException ex)
+ {
+ org.eclipse.jdt.internal.ui.JavaPlugin.log(ex);
+ }
+ }
+
+ private void parseCurrentTeam()
+ {
+ try
+ {
+ _originalDocument = new Document(_team.getCompilationUnit().getSource());
+
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+
+ parser.setSource(_team.getCompilationUnit());
+ parser.setResolveBindings(true);
+
+ // tell the ASTConverter to include contained role files.
+ // Note, that currently these role files cannot be modified by the binding editor (Trac #93).
+ HashMap<String, String> options= new HashMap<String, String>(JavaCore.getOptions());
+ options.put(JavaCore.AST_INCLUDES_ROLE_FILES, JavaCore.ENABLED);
+ parser.setCompilerOptions(options);
+
+ _root = (CompilationUnit)parser.createAST(null);
+ _root.recordModifications();
+ }
+ catch (JavaModelException ex)
+ {
+ _originalDocument = null;
+ org.eclipse.jdt.internal.ui.JavaPlugin.log(ex);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/CallinMappingConfiguration.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/CallinMappingConfiguration.java
new file mode 100644
index 0000000..d783361
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/CallinMappingConfiguration.java
@@ -0,0 +1,447 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2005, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: CallinMappingConfiguration.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.bindingeditor;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CallinMappingDeclaration;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.MethodSpec;
+import org.eclipse.jdt.core.dom.Modifier;
+import org.eclipse.jdt.core.dom.ParameterMapping;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.rewrite.ASTNodeCreator;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextViewer;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+
+/**
+ * This is a configuration element for the
+ * parameter mappings of a callin mapping.
+ *
+ * A parameter mapping: identifier "<-" expression
+ * A result mapping: expression "->" "result"
+ *
+ * Created on Feb 7, 2005
+ *
+ * @author jwloka
+ * @version $Id: CallinMappingConfiguration.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class CallinMappingConfiguration extends Group
+{
+
+ // Method mapping declaration context
+ private CallinMappingDeclaration _callin;
+
+ // parameter mapping
+ private ListViewer _paraListViewer;
+ private TextViewer _paraTextViewer;
+
+ // result mapping
+ private ListViewer _resListViewer;
+ private TextViewer _resTextViewer;
+
+ private BindingEditor _bindingEditor;
+ private Group _resMapGrp;
+ private Label _methBindLabel;
+
+ private final Object[] EMPTY = new Object[0];
+ private final static String EMPTY_TEXT = ""; //$NON-NLS-1$
+
+ class RoleMethodParameterContentProvider implements IStructuredContentProvider
+ {
+ public Object[] getElements(Object inputElement)
+ {
+ if (_callin == null)
+ {
+ return EMPTY;
+ }
+
+ java.util.List<String> result = new ArrayList<String>();
+ MethodSpec methSpec = (MethodSpec)_callin.getRoleMappingElement();
+ for (Iterator paramIdx = methSpec.parameters().iterator(); paramIdx.hasNext();) {
+ SingleVariableDeclaration param = (SingleVariableDeclaration) paramIdx.next();
+ result.add(param.getName().toString());
+ }
+ return result.toArray();
+ }
+
+ public void dispose() {}
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+ }
+
+
+ class ResultContentProvider implements IStructuredContentProvider
+ {
+ public Object[] getElements(Object inputElement)
+ {
+ return new Object[] { "result" }; //$NON-NLS-1$
+ }
+
+ public void dispose() {}
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+ }
+
+
+ public CallinMappingConfiguration(Composite parent, int style)
+ {
+ super(parent, style);
+
+ _bindingEditor = (BindingEditor)parent.getParent();
+ setText(OTDTUIPlugin.getResourceString("CallinMappingConfiguration_dialog_title")); //$NON-NLS-1$
+ setLayout(new FormLayout());
+
+ _methBindLabel = new Label(this, SWT.NONE);
+ final FormData formData = new FormData();
+ formData.right = new FormAttachment(100, -5);
+ formData.top = new FormAttachment(0, 5);
+ formData.left = new FormAttachment(0, 10);
+ _methBindLabel.setLayoutData(formData);
+ _methBindLabel.setText(OTDTUIPlugin.getResourceString("MethodMappingConfiguration_no_method_binding_selected")); //$NON-NLS-1$
+ final Group paraMapGrp = new Group(this, SWT.NONE);
+ paraMapGrp.setText(OTDTUIPlugin.getResourceString("MethodMappingConfiguration_param_mapping_group_title")); //$NON-NLS-1$
+ final FormData formData_1 = new FormData();
+ formData_1.bottom = new FormAttachment(50, 0);
+ formData_1.right = new FormAttachment(100, -5);
+ formData_1.top = new FormAttachment(0, 28);
+ formData_1.left = new FormAttachment(0, 5);
+ paraMapGrp.setLayoutData(formData_1);
+ paraMapGrp.setLayout(new FormLayout());
+
+ _paraListViewer = new ListViewer(paraMapGrp, SWT.V_SCROLL | SWT.BORDER | SWT.H_SCROLL);
+ _paraListViewer.setContentProvider(new RoleMethodParameterContentProvider());
+ final List paraList = _paraListViewer.getList();
+ final FormData formData_7 = new FormData();
+ formData_7.bottom = new FormAttachment(100, -5);
+ formData_7.right = new FormAttachment(40, 0);
+ formData_7.top = new FormAttachment(0, 5);
+ formData_7.left = new FormAttachment(0, 5);
+ paraList.setLayoutData(formData_7);
+ _paraListViewer.setInput(new Object());
+ _paraListViewer.addSelectionChangedListener(
+ new ISelectionChangedListener()
+ {
+ public void selectionChanged(SelectionChangedEvent event)
+ {
+ if ( !_paraListViewer.getSelection().isEmpty() )
+ {
+ _resListViewer.setSelection(StructuredSelection.EMPTY);
+ }
+ }
+
+ }
+ );
+
+ _paraTextViewer = new TextViewer(paraMapGrp, SWT.BORDER);
+ _paraTextViewer.setDocument(new Document(EMPTY_TEXT));
+ final StyledText paraText_1 = _paraTextViewer.getTextWidget();
+ final FormData formData_5 = new FormData();
+ formData_5.bottom = new FormAttachment(100, -5);
+ formData_5.top = new FormAttachment(0, 5);
+ formData_5.right = new FormAttachment(100, -5);
+ formData_5.left = new FormAttachment(58, 0);
+ paraText_1.setLayoutData(formData_5);
+ _paraTextViewer.setInput(new Object());
+
+ final Composite paraBtnComp = new Composite(paraMapGrp, SWT.NONE);
+ final FormData formData_6 = new FormData();
+ formData_6.left = new FormAttachment(paraList, 5, SWT.RIGHT);
+ formData_6.right = new FormAttachment(paraText_1, -5, SWT.LEFT);
+ formData_6.bottom = new FormAttachment(100, -5);
+ formData_6.top = new FormAttachment(0, 5);
+ paraBtnComp.setLayoutData(formData_6);
+ paraBtnComp.setLayout(new FormLayout());
+
+ final Button paraMapBtn = new Button(paraBtnComp, SWT.NONE);
+ final FormData formData_2 = new FormData();
+ formData_2.top = new FormAttachment(36, 0);
+ formData_2.right = new FormAttachment(100, -5);
+ formData_2.left = new FormAttachment(0, 5);
+ paraMapBtn.setLayoutData(formData_2);
+ paraMapBtn.setText("<-"); //$NON-NLS-1$
+
+
+ final Button applyBtn = new Button(this, SWT.NONE);
+ final FormData formData_11 = new FormData();
+ formData_11.bottom = new FormAttachment(100, -5);
+ formData_11.right = new FormAttachment(100, -5);
+ applyBtn.setLayoutData(formData_11);
+ applyBtn.setText(OTDTUIPlugin.getResourceString("MethodMappingConfiguration_apply_button_label")); //$NON-NLS-1$
+ applyBtn.addSelectionListener(
+ new SelectionAdapter()
+ {
+ public void widgetSelected(SelectionEvent evt)
+ {
+ applySelectedMapping();
+ }
+ }
+ );
+
+ _resMapGrp = new Group(this, SWT.NONE);
+ _resMapGrp.setText(OTDTUIPlugin.getResourceString("MethodMappingConfiguration_result_mapping_group_title")); //$NON-NLS-1$
+ final FormData formData_4 = new FormData();
+ formData_4.bottom = new FormAttachment(applyBtn, -5, SWT.TOP);
+ formData_4.right = new FormAttachment(100, -5);
+ formData_4.top = new FormAttachment(paraMapGrp, 5, SWT.BOTTOM);
+ formData_4.left = new FormAttachment(0, 5);
+ _resMapGrp.setLayoutData(formData_4);
+ _resMapGrp.setLayout(new FormLayout());
+
+
+
+ // right side "result"
+ _resListViewer = new ListViewer(_resMapGrp, SWT.V_SCROLL | SWT.BORDER | SWT.H_SCROLL);
+ _resListViewer.setContentProvider(new ResultContentProvider());
+ final List resList = _resListViewer.getList();
+ final FormData formData_8 = new FormData();
+ formData_8.bottom = new FormAttachment(100, -5);
+ formData_8.right = new FormAttachment(100, -5);
+ formData_8.top = new FormAttachment(0, 5);
+ formData_8.left = new FormAttachment(58, 0);
+ resList.setLayoutData(formData_8);
+ _resListViewer.setInput(new Object());
+ _resListViewer.addSelectionChangedListener(
+ new ISelectionChangedListener()
+ {
+ public void selectionChanged(SelectionChangedEvent event)
+ {
+ if ( !_resListViewer.getSelection().isEmpty() )
+ {
+ _paraListViewer.setSelection(StructuredSelection.EMPTY);
+ }
+ }
+
+ }
+ );
+
+ // left side
+ _resTextViewer = new TextViewer(_resMapGrp, SWT.BORDER);
+ final StyledText resText_1 = _resTextViewer.getTextWidget();
+ final FormData formData_10 = new FormData();
+ formData_10.bottom = new FormAttachment(100, -5);
+ formData_10.top = new FormAttachment(0, 5);
+ formData_10.right = new FormAttachment(40, 0);
+ formData_10.left = new FormAttachment(0, 5);
+ resText_1.setLayoutData(formData_10);
+ _resTextViewer.setInput(new Object());
+
+ final Composite resBtnComp = new Composite(_resMapGrp, SWT.NONE);
+ final FormData formData_3 = new FormData();
+ formData_3.left = new FormAttachment(resText_1, 5, SWT.RIGHT);
+ formData_3.right = new FormAttachment(resList, -5, SWT.LEFT);
+ formData_3.bottom = new FormAttachment(100, -5);
+ formData_3.top = new FormAttachment(0, 5);
+ resBtnComp.setLayoutData(formData_3);
+ resBtnComp.setLayout(new FormLayout());
+
+ final Button resMapBtn = new Button(resBtnComp, SWT.NONE);
+ final FormData formData_9 = new FormData();
+ formData_9.right = new FormAttachment(100, -5);
+ formData_9.top = new FormAttachment(0, 5);
+ formData_9.left = new FormAttachment(0, 5);
+ resMapBtn.setLayoutData(formData_9);
+ resMapBtn.setText("->"); //$NON-NLS-1$
+ //
+ }
+
+ protected void checkSubclass() {}
+
+
+ private void applySelectedMapping()
+ {
+ IStructuredSelection selection = null;
+ String identifier = null;
+ String expr = null;
+
+ selection = (IStructuredSelection)_paraListViewer.getSelection();
+ if (!selection.isEmpty())
+ {
+ identifier = (String)selection.getFirstElement();
+ IDocument doc = _paraTextViewer.getDocument();
+ if (doc != null)
+ {
+ expr = doc.get();
+ if (!expr.equals(EMPTY_TEXT))
+ {
+ updateParameterMapping(identifier, expr);
+ }
+ }
+ }
+
+ selection = (IStructuredSelection)_resListViewer.getSelection();
+ if (!selection.isEmpty())
+ {
+ identifier = (String)selection.getFirstElement();
+ IDocument doc = _resTextViewer.getDocument();
+ if (doc != null)
+ {
+ expr = doc.get();
+ if (!expr.equals(EMPTY_TEXT))
+ {
+ updateParameterMapping(identifier, expr);
+ }
+ }
+ }
+
+ _bindingEditor.refresh();
+ }
+
+
+
+
+ protected void setFocus(ParameterMapping paraMap, CallinMappingDeclaration callinDecl)
+ {
+ if (!Modifier.isReplace(callinDecl.getCallinModifier()))
+ {
+ _resMapGrp.setVisible(false);
+ }
+ else
+ {
+ _resMapGrp.setVisible(true);
+ }
+ setMethodMapping(callinDecl);
+ setParameterMapping(paraMap);
+ }
+
+ protected void setParameterMapping(ParameterMapping paraMap)
+ {
+ if (paraMap == null)
+ {
+ _resTextViewer.setDocument(new Document(EMPTY_TEXT));
+ _paraTextViewer.setDocument(new Document(EMPTY_TEXT));
+ clearSelections();
+ return;
+ }
+
+ String identifier = paraMap.getIdentifier().getIdentifier();
+ ASTNode expr = paraMap.getExpression();
+ if (paraMap.hasResultFlag())
+ {
+ _paraListViewer.setSelection(StructuredSelection.EMPTY);
+ _resListViewer.setSelection(new StructuredSelection(identifier));
+ _resTextViewer.setDocument(new Document(expr.toString()));
+ }
+ else
+ {
+ _resListViewer.setSelection(StructuredSelection.EMPTY);
+ _paraListViewer.setSelection(new StructuredSelection(identifier));
+ _paraTextViewer.setDocument(new Document(expr.toString()));
+ }
+ }
+
+ protected void setMethodMapping(CallinMappingDeclaration callinDecl)
+ {
+ _callin = callinDecl;
+ String modifier = EMPTY_TEXT;
+
+ if (Modifier.isAfter(_callin.getCallinModifier()))
+ {
+ modifier = "after"; //$NON-NLS-1$
+ }
+ else if (Modifier.isBefore(_callin.getCallinModifier()))
+ {
+ modifier = "before"; //$NON-NLS-1$
+ }
+ else if (Modifier.isReplace(_callin.getCallinModifier()))
+ {
+ modifier = "replace"; //$NON-NLS-1$
+ }
+
+ _methBindLabel.setText(
+ _callin.getRoleMappingElement().toString()
+ + " <- " + modifier + ' ' //$NON-NLS-1$
+ + _callin.getBaseMappingElements().get(0).toString()
+ );
+ _paraListViewer.refresh();
+ }
+
+ protected void updateParameterMapping(String identifier, String expr)
+ {
+ ParameterMapping paraMap = null;
+ Expression exprNode = ASTNodeCreator.createExpression(_callin.getAST(), expr);
+
+ // if parsing of expr fails, ignore this parameter mapping
+ if (exprNode == null)
+ {
+ return;
+ }
+
+ java.util.List<ParameterMapping> paraMaps = _callin.getParameterMappings();
+ for (Iterator<ParameterMapping> mapIdx = paraMaps.iterator(); mapIdx.hasNext();) {
+ ParameterMapping mapping = mapIdx.next();
+ if (identifier.equals(mapping.getIdentifier()))
+ {
+ paraMap = mapping;
+ break;
+ }
+ }
+
+ if (paraMap == null)
+ {
+ paraMap = _callin.getAST().newParameterMapping();
+ paraMaps.add(paraMap);
+ }
+
+ paraMap.setIdentifier(_callin.getAST().newSimpleName(identifier));
+ if (identifier.equals("result")) //$NON-NLS-1$
+ {
+ paraMap.setDirection("->"); //$NON-NLS-1$
+ paraMap.setResultFlag(true);
+ }
+ else
+ {
+ paraMap.setDirection("<-"); //$NON-NLS-1$
+ paraMap.setResultFlag(false);
+ }
+
+ paraMap.setExpression(exprNode);
+ }
+
+ public void clearSelections()
+ {
+ _resListViewer.setSelection(StructuredSelection.EMPTY);
+ _paraListViewer.setSelection(StructuredSelection.EMPTY);
+ _resTextViewer.setSelection(StructuredSelection.EMPTY);
+ _paraTextViewer.setSelection(StructuredSelection.EMPTY);
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/CalloutMappingConfiguration.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/CalloutMappingConfiguration.java
new file mode 100644
index 0000000..d885724
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/CalloutMappingConfiguration.java
@@ -0,0 +1,436 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2005, 2007 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: CalloutMappingConfiguration.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.bindingeditor;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CalloutMappingDeclaration;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.FieldAccessSpec;
+import org.eclipse.jdt.core.dom.MethodMappingElement;
+import org.eclipse.jdt.core.dom.MethodSpec;
+import org.eclipse.jdt.core.dom.ParameterMapping;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.rewrite.ASTNodeCreator;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.TextViewer;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+
+/**
+ * This is a configuration element for the
+ * parameter mappings of a callout mapping.
+ *
+ * A parameter mapping: expression "->" identifier
+ * A result mapping: "result" "<-" expression
+ *
+ * @author jwloka
+ */
+public class CalloutMappingConfiguration extends Group
+{
+ // Method mapping declaration context
+ private CalloutMappingDeclaration _callout;
+
+ // parameter mapping
+ private ListViewer _paraListViewer;
+ private TextViewer _paraTextViewer;
+
+ // result mapping
+ private ListViewer _resListViewer;
+ private TextViewer _resTextViewer;
+
+ private BindingEditor _bindingEditor;
+ private Label _methBindLabel;
+
+ private final Object[] EMPTY = new Object[0];
+ private static final String EMPTY_TEXT = ""; //$NON-NLS-1$
+
+
+ class BaseMethodParameterContentProvider implements IStructuredContentProvider
+ {
+ public Object[] getElements(Object inputElement)
+ {
+ if (_callout == null)
+ {
+ return EMPTY;
+ }
+
+ java.util.List<String> result = new ArrayList<String>();
+ MethodMappingElement baseElement = _callout.getBaseMappingElement();
+ if (baseElement instanceof FieldAccessSpec) {
+ result.add(baseElement.getName().toString());
+ } else if (baseElement instanceof MethodSpec) {
+ MethodSpec methSpec = (MethodSpec)baseElement;
+ for (Iterator paramIdx = methSpec.parameters().iterator(); paramIdx.hasNext();) {
+ SingleVariableDeclaration param = (SingleVariableDeclaration) paramIdx.next();
+ result.add(param.getName().toString());
+ }
+ }
+ return result.toArray();
+
+ }
+
+ public void dispose()
+ {}
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
+ {}
+ }
+
+
+ class ResultContentProvider implements IStructuredContentProvider
+ {
+ public Object[] getElements(Object inputElement)
+ {
+ return new Object[] { "result" }; //$NON-NLS-1$
+ }
+
+ public void dispose()
+ {}
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
+ {}
+ }
+
+
+ public CalloutMappingConfiguration(Composite parent, int style)
+ {
+ super(parent, style);
+ _bindingEditor = (BindingEditor)parent.getParent();
+ setText(OTDTUIPlugin.getResourceString("CalloutMappingConfiguration_dialog_title")); //$NON-NLS-1$
+ setLayout(new FormLayout());
+
+ _methBindLabel = new Label(this, SWT.NONE);
+ final FormData formData = new FormData();
+ formData.right = new FormAttachment(100, -5);
+ formData.top = new FormAttachment(0, 5);
+ formData.left = new FormAttachment(0, 10);
+ _methBindLabel.setLayoutData(formData);
+ _methBindLabel.setText(OTDTUIPlugin.getResourceString("MethodMappingConfiguration_no_method_binding_selected")); //$NON-NLS-1$
+ final Group paraMapGrp = new Group(this, SWT.NONE);
+ paraMapGrp.setText(OTDTUIPlugin.getResourceString("MethodMappingConfiguration_param_mapping_group_title")); //$NON-NLS-1$
+ final FormData formData_1 = new FormData();
+ formData_1.bottom = new FormAttachment(50, 0);
+ formData_1.right = new FormAttachment(100, -5);
+ formData_1.top = new FormAttachment(0, 28);
+ formData_1.left = new FormAttachment(0, 5);
+ paraMapGrp.setLayoutData(formData_1);
+ paraMapGrp.setLayout(new FormLayout());
+
+ // left side, expression
+ _paraTextViewer = new TextViewer(paraMapGrp, SWT.BORDER);
+ _paraTextViewer.setDocument(new Document());
+ final StyledText paraText = _paraTextViewer.getTextWidget();
+ final FormData formData_5 = new FormData();
+ formData_5.right = new FormAttachment(43, 0);
+ formData_5.bottom = new FormAttachment(100, -5);
+ formData_5.top = new FormAttachment(0, 5);
+ formData_5.left = new FormAttachment(0, 5);
+ paraText.setLayoutData(formData_5);
+ _paraTextViewer.setInput(new Object());
+
+ // right side, identiers
+ _paraListViewer = new ListViewer(paraMapGrp, SWT.BORDER);
+ _paraListViewer.setContentProvider(new BaseMethodParameterContentProvider());
+ final List paraList = _paraListViewer.getList();
+ final FormData formData_7 = new FormData();
+ formData_7.bottom = new FormAttachment(100, -5);
+ formData_7.right = new FormAttachment(100, -5);
+ formData_7.top = new FormAttachment(0, 5);
+ formData_7.left = new FormAttachment(59, 0);
+ paraList.setLayoutData(formData_7);
+ _paraListViewer.setInput(new Object());
+
+ _paraListViewer.addSelectionChangedListener(
+ new ISelectionChangedListener()
+ {
+ public void selectionChanged(SelectionChangedEvent event)
+ {
+ if ( !_paraListViewer.getSelection().isEmpty() )
+ {
+ _resListViewer.setSelection(StructuredSelection.EMPTY);
+ }
+ }
+
+ }
+ );
+
+
+
+ final Composite paraBtnComp = new Composite(paraMapGrp, SWT.NONE);
+ final FormData formData_6 = new FormData();
+ formData_6.right = new FormAttachment(paraList, -5, SWT.LEFT);
+ formData_6.bottom = new FormAttachment(100, -5);
+ formData_6.top = new FormAttachment(paraText, 0, SWT.TOP);
+ formData_6.left = new FormAttachment(paraText, 5, SWT.RIGHT);
+ paraBtnComp.setLayoutData(formData_6);
+ paraBtnComp.setLayout(new FormLayout());
+
+ final Button paraMapBtn = new Button(paraBtnComp, SWT.NONE);
+ final FormData formData_2 = new FormData();
+ formData_2.right = new FormAttachment(100, -5);
+ formData_2.top = new FormAttachment(34, 0);
+ formData_2.left = new FormAttachment(0, 5);
+ paraMapBtn.setLayoutData(formData_2);
+ paraMapBtn.setText("->"); //$NON-NLS-1$
+
+
+ final Button applyBtn = new Button(this, SWT.NONE);
+ final FormData formData_11 = new FormData();
+ formData_11.bottom = new FormAttachment(100, -5);
+ formData_11.right = new FormAttachment(100, -5);
+ applyBtn.setLayoutData(formData_11);
+ applyBtn.setText(OTDTUIPlugin.getResourceString("MethodMappingConfiguration_apply_button_label")); //$NON-NLS-1$
+
+ applyBtn.addSelectionListener(
+ new SelectionAdapter()
+ {
+ public void widgetSelected(SelectionEvent evt)
+ {
+ applySelectedMapping();
+ }
+ }
+ );
+
+ final Group resMapGrp = new Group(this, SWT.NONE);
+ resMapGrp.setText(OTDTUIPlugin.getResourceString("MethodMappingConfiguration_result_mapping_group_title")); //$NON-NLS-1$
+ final FormData formData_4 = new FormData();
+ formData_4.bottom = new FormAttachment(applyBtn, -5, SWT.TOP);
+ formData_4.right = new FormAttachment(100, -5);
+ formData_4.top = new FormAttachment(paraMapGrp, 5, SWT.BOTTOM);
+ formData_4.left = new FormAttachment(0, 5);
+ resMapGrp.setLayoutData(formData_4);
+ resMapGrp.setLayout(new FormLayout());
+
+ _resListViewer = new ListViewer(resMapGrp, SWT.BORDER);
+ _resListViewer.setContentProvider(new ResultContentProvider());
+ final List resList = _resListViewer.getList();
+ final FormData formData_8 = new FormData();
+ formData_8.bottom = new FormAttachment(100, -5);
+ formData_8.right = new FormAttachment(43, 0);
+ formData_8.top = new FormAttachment(0, 5);
+ formData_8.left = new FormAttachment(0, 5);
+ resList.setLayoutData(formData_8);
+ _resListViewer.setInput(new Object());
+
+ _resListViewer.addSelectionChangedListener(
+ new ISelectionChangedListener()
+ {
+ public void selectionChanged(SelectionChangedEvent event)
+ {
+ if ( !_resListViewer.getSelection().isEmpty() )
+ {
+ _paraListViewer.setSelection(StructuredSelection.EMPTY);
+ }
+ }
+
+ }
+ );
+
+ _resTextViewer = new TextViewer(resMapGrp, SWT.BORDER);
+ final StyledText resText = _resTextViewer.getTextWidget();
+ final FormData formData_10 = new FormData();
+ formData_10.bottom = new FormAttachment(100, -5);
+ formData_10.right = new FormAttachment(100, -5);
+ formData_10.top = new FormAttachment(0, 5);
+ formData_10.left = new FormAttachment(59, 0);
+ resText.setLayoutData(formData_10);
+ _resTextViewer.setInput(new Object());
+
+ final Composite resBtnComp = new Composite(resMapGrp, SWT.NONE);
+ final FormData formData_3 = new FormData();
+ formData_3.right = new FormAttachment(resText, -5, SWT.LEFT);
+ formData_3.bottom = new FormAttachment(100, -5);
+ formData_3.top = new FormAttachment(resText, 0, SWT.TOP);
+ formData_3.left = new FormAttachment(resList, 5, SWT.RIGHT);
+ resBtnComp.setLayoutData(formData_3);
+ resBtnComp.setLayout(new FormLayout());
+
+ final Button resMapBtn = new Button(resBtnComp, SWT.NONE);
+ final FormData formData_9 = new FormData();
+ formData_9.right = new FormAttachment(100, -5);
+ formData_9.top = new FormAttachment(0, 5);
+ formData_9.left = new FormAttachment(0, 5);
+ resMapBtn.setLayoutData(formData_9);
+ resMapBtn.setText("<-"); //$NON-NLS-1$
+ //
+ }
+
+ public void dispose()
+ {
+ super.dispose();
+ }
+
+ protected void checkSubclass()
+ {}
+
+
+
+ private void applySelectedMapping()
+ {
+ IStructuredSelection selection = null;
+ String identifier = null;
+ String expr = null;
+
+ selection = (IStructuredSelection)_paraListViewer.getSelection();
+ if (!selection.isEmpty())
+ {
+ identifier = (String)selection.getFirstElement();
+ expr = _paraTextViewer.getDocument().get();
+ if (!expr.equals(EMPTY_TEXT))
+ {
+ updateParameterMapping(identifier, expr);
+ }
+ }
+
+ selection = (IStructuredSelection)_resListViewer.getSelection();
+ if (!selection.isEmpty())
+ {
+ identifier = (String)selection.getFirstElement();
+ expr = _resTextViewer.getDocument().get();
+ if (!expr.equals(EMPTY_TEXT))
+ {
+ updateParameterMapping(identifier, expr);
+ }
+ }
+
+ _bindingEditor.refresh();
+ }
+
+
+ protected void setFocus(ParameterMapping paraMap, CalloutMappingDeclaration callout)
+ {
+ setMethodBinding(callout);
+ setParameterMapping(paraMap);
+ }
+
+ protected void setParameterMapping(ParameterMapping paraMap)
+ {
+ if (paraMap == null)
+ {
+ _resTextViewer.setDocument(new Document(EMPTY_TEXT));
+ _paraTextViewer.setDocument(new Document(EMPTY_TEXT));
+ clearSelections();
+ return;
+ }
+
+ String identifier = paraMap.getIdentifier().getIdentifier();
+ ASTNode expr = paraMap.getExpression();
+ if (paraMap.hasResultFlag())
+ {
+ _paraListViewer.setSelection(StructuredSelection.EMPTY);
+ _resListViewer.setSelection(new StructuredSelection(identifier));
+ _resTextViewer.setDocument(new Document(expr.toString()));
+ }
+ else
+ {
+ _resListViewer.setSelection(StructuredSelection.EMPTY);
+ _paraListViewer.setSelection(new StructuredSelection(identifier));
+ _paraTextViewer.setDocument(new Document(expr.toString()));
+ }
+ }
+
+ protected void setMethodBinding(CalloutMappingDeclaration callout)
+ {
+ _callout = callout;
+ _methBindLabel.setText(
+ _callout.getRoleMappingElement().toString()
+ + (_callout.isCalloutOverride() ? "=>" : "->") //$NON-NLS-1$ //$NON-NLS-2$
+ + _callout.getBaseMappingElement().toString()
+ );
+ _paraListViewer.refresh();
+ }
+
+ @SuppressWarnings("unchecked") // AST does not use generics :(
+ protected void updateParameterMapping(String identifier, String expr)
+ {
+ ParameterMapping paraMap = null;
+ Expression exprNode = ASTNodeCreator.createExpression(_callout.getAST(), expr);
+
+ // if parsing of expr fails, ignore this parameter mapping
+ if (exprNode == null)
+ {
+ return;
+ }
+
+ java.util.List<ParameterMapping> paraMaps = _callout.getParameterMappings();
+ for (Iterator<ParameterMapping> mapIdx = paraMaps.iterator(); mapIdx.hasNext();)
+ {
+ ParameterMapping mapping = mapIdx.next();
+ if (identifier.equals(mapping.getIdentifier()))
+ {
+ paraMap = mapping;
+ break;
+ }
+
+ }
+
+ if (paraMap == null)
+ {
+ paraMap = _callout.getAST().newParameterMapping();
+ paraMaps.add(paraMap);
+ }
+
+ paraMap.setIdentifier(_callout.getAST().newSimpleName(identifier));
+ if (identifier.equals("result")) //$NON-NLS-1$
+ {
+ paraMap.setDirection("<-"); //$NON-NLS-1$
+ paraMap.setResultFlag(true);
+ }
+ else
+ {
+ paraMap.setDirection("->"); //$NON-NLS-1$
+ paraMap.setResultFlag(false);
+ }
+
+ paraMap.setExpression(exprNode);
+ }
+
+
+ public void clearSelections()
+ {
+ _resListViewer.setSelection(StructuredSelection.EMPTY);
+ _paraListViewer.setSelection(StructuredSelection.EMPTY);
+ _resTextViewer.setSelection(StructuredSelection.EMPTY);
+ _paraTextViewer.setSelection(StructuredSelection.EMPTY);
+ }
+
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/Messages.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/Messages.java
new file mode 100644
index 0000000..d9286fc
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/Messages.java
@@ -0,0 +1,68 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2005, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id$
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.bindingeditor;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.objectteams.otdt.internal.ui.bindingeditor.Messages"; //$NON-NLS-1$
+
+ public static String AddTypeBindingDialog_no_roles_available_error;
+
+ public static String AddTypeBindingDialog_role_selection_title;
+
+ public static String BindingEditorDialog_dialog_title;
+
+ public static String BindingEditor_connector_title;
+ public static String BindingEditor_role_types_title;
+ public static String BindingEditor_base_types_title;
+ public static String BindingEditor_add_type_binding_button;
+ public static String BindingEditor_remove_button;
+
+ public static String BindingEditor_method_binding_tab;
+ public static String BindingEditor_param_mapping_tab;
+
+ public static String BindingConfiguration_new_method_label;
+ public static String BindingConfiguration_role_methods_label;
+ public static String BindingConfiguration_base_methods_label;
+ public static String BindingConfiguration_apply_button;
+
+ public static String BindingConfiguration_error_unspecific;
+ public static String BindingConfiguration_error_retrieving_role_methods;
+ public static String BindingConfiguration_error_binding_creation_failed;
+
+ public static String OpenBindingEditorAction_error_title;
+ public static String OpenBindingEditorAction_error_no_team_selected;
+
+ public static String BindingConfiguration_error_cant_edit_rolefile;
+
+ public static String BindingConfiguration_error_cant_edit_rolefile_nested;
+
+
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/Messages.properties b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/Messages.properties
new file mode 100644
index 0000000..8c6203e
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/Messages.properties
@@ -0,0 +1,27 @@
+AddTypeBindingDialog_no_roles_available_error=No role types available.
+AddTypeBindingDialog_role_selection_title=Role type selection
+BindingEditorDialog_dialog_title=Bindings for Team:
+
+BindingEditor_connector_title=Connector Definition
+BindingEditor_role_types_title=Role Types
+BindingEditor_base_types_title=Base Types
+BindingEditor_add_type_binding_button=Add Type Binding...
+BindingEditor_remove_button=Remove
+
+BindingEditor_method_binding_tab=Method Binding Configuration
+BindingEditor_param_mapping_tab=Parameter Mapping Configuration
+
+BindingConfiguration_new_method_label=New method
+BindingConfiguration_role_methods_label=Role Methods
+BindingConfiguration_base_methods_label=Base Methods
+BindingConfiguration_apply_button=Apply
+
+BindingConfiguration_error_unspecific=Error in BindingDialog
+BindingConfiguration_error_retrieving_role_methods=Error while trying to get all role-Methods
+BindingConfiguration_error_binding_creation_failed=Creation of Callin-/Calloutbinding failed.
+
+BindingConfiguration_error_cant_edit_rolefile=Sorry, can''t edit role {0}!\nReason: {1} is a role file and the binding editor doesn''t yet support editing role files via their enclosing team.
+BindingConfiguration_error_cant_edit_rolefile_nested=Sorry, can''t edit role {0}!\nReason: Enclosing team {1} is a role file and the binding editor doesn''t yet support editing role files via their enclosing team.\nTo perform this operation please open the binding editor directly for team {2}.
+
+OpenBindingEditorAction_error_title=Binding editor
+OpenBindingEditorAction_error_no_team_selected=Please select a team
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/RadioButtonComposite.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/RadioButtonComposite.java
new file mode 100644
index 0000000..9c0e42e
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/bindingeditor/RadioButtonComposite.java
@@ -0,0 +1,154 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2005, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: RadioButtonComposite.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.bindingeditor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * This composite imitates the radiobutton-behavior.
+ * All children have to be buttons(toggleButtons recommended).
+ *
+ * Created on Mar 21, 2005
+ *
+ * @author ike
+ * @version $Id: RadioButtonComposite.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class RadioButtonComposite extends Composite
+{
+
+ Button _oldSelectedButton;
+
+ public RadioButtonComposite(Composite parent, int style)
+ {
+ super(parent, style);
+ }
+
+ public void doRadioButtonBehavior(Button selectedButton)
+ {
+
+ if (_oldSelectedButton != null && _oldSelectedButton.equals(selectedButton))
+ {
+ selectedButton.setSelection(true);
+ _oldSelectedButton = selectedButton;
+ return;
+ }
+
+ Button [] radioButtons = getButtons();
+ for (int idx = 0; idx < radioButtons.length; idx++)
+ {
+ if (!radioButtons[idx].equals(selectedButton))
+ {
+ radioButtons[idx].setSelection(false);
+ }
+ }
+
+ _oldSelectedButton = selectedButton;
+ }
+
+ public Button getSelectedButton()
+ {
+ Button [] radioButtons = getButtons();
+ for (int idx = 0; idx < radioButtons.length; idx++)
+ {
+ if (radioButtons[idx].getSelection())
+ return radioButtons[idx];
+ }
+
+ return null;
+ }
+
+ public void setSelectionButton(Button button)
+ {
+ Button [] radioButtons = getButtons();
+ for (int idx = 0; idx < radioButtons.length; idx++)
+ {
+ if (radioButtons[idx].equals(button))
+ {
+ radioButtons[idx].setSelection(true);
+ _oldSelectedButton = button;
+ }
+ else
+ {
+ radioButtons[idx].setSelection(false);
+ }
+ }
+ }
+
+ public void removeSelectionButton(Button button)
+ {
+ Button [] radioButtons = getButtons();
+ for (int idx = 0; idx < radioButtons.length; idx++)
+ {
+ if (radioButtons[idx].equals(button) && radioButtons[idx].getSelection())
+ {
+ radioButtons[idx].setSelection(false);
+ _oldSelectedButton = null;
+ }
+ }
+ }
+
+ public void deselectAll()
+ {
+ Button [] radioButtons = getButtons();
+ for (int idx = 0; idx < radioButtons.length; idx++)
+ {
+ if(radioButtons[idx].getSelection())
+ radioButtons[idx].setSelection(false);
+ }
+ }
+
+ public void enableAll()
+ {
+ Button [] radioButtons = getButtons();
+ for (int idx = 0; idx < radioButtons.length; idx++)
+ {
+ if(!radioButtons[idx].isEnabled())
+ radioButtons[idx].setEnabled(true);
+ }
+ }
+
+ public void disableAll()
+ {
+ Button [] radioButtons = getButtons();
+ for (int idx = 0; idx < radioButtons.length; idx++)
+ {
+ if(radioButtons[idx].isEnabled())
+ radioButtons[idx].setEnabled(false);
+ }
+ }
+
+ private Button[] getButtons()
+ {
+ Control [] controls = this.getChildren();
+ List<Button> buttons = new ArrayList<Button>();
+ for (int idx = 0; idx < controls.length; idx++)
+ {
+ if (controls[idx] instanceof Button)
+ buttons.add((Button)controls[idx]);
+ }
+ return buttons.toArray(new Button[buttons.size()]);
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/AbstractMarkable.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/AbstractMarkable.java
new file mode 100644
index 0000000..64a2564
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/AbstractMarkable.java
@@ -0,0 +1,238 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2008 Technical University Berlin, Germany.
+ *
+ * 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
+ * $Id: AbstractMarkable.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.callinmarkers;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.core.search.SearchEngine;
+import org.eclipse.objectteams.otdt.core.compiler.OTNameUtils;
+import org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy;
+
+
+/**
+ * Abstraction for buffers that can hold markers in the ruler:
+ * <ul>
+ * <li>resources representing source files
+ * <li>java elements representing binary class files
+ * </ul>
+ *
+ * @author stephan
+ * @since 1.2.5
+ */
+public abstract class AbstractMarkable {
+
+ final static String PDE_PLUGIN_NATURE_ID = "org.eclipse.pde.PluginNature"; //$NON-NLS-1$ // avoid importing org.eclipse.pde.core
+
+ /** Name of this markable for use in the UI. */
+ abstract String getName();
+
+ /** Remove all callin markers from this markable. */
+ abstract void removeCallinMarkers() throws CoreException;
+
+ abstract IJavaElement getJavaElement();
+
+ abstract IResource getResource();
+
+ /** Create a real marker with the given ID. */
+ abstract IMarker createMarker(String id) throws CoreException;
+
+ /**
+ * Get all types that contribute members to the current markable.
+ * Contribution happens through containment (members) and inheritance.
+ */
+ abstract Set<IType> getAllTypes(IJavaProject[] projects, IProgressMonitor monitor) throws CoreException;
+
+ /**
+ * Get all projects that could be relevant for searching.
+ */
+ abstract IJavaProject[] getProjects() throws JavaModelException;
+
+ /**
+ * Is the given element contained in this markable?
+ */
+ abstract boolean containsElement(IJavaElement element);
+
+ /**
+ * Fetch the member and super types of type and add them to the given sets.
+ * Works recursively.
+ *
+ * @param members all members, direct and indirect, including inherited members.
+ * @param supers all super types of this and its members.
+ * @param type focus type
+ * @param currentProject the project of the current Markable, use this first when searching types.
+ * @param projects where to search for super types which are given by their name
+ * @param monitor
+ * @throws JavaModelException
+ */
+ void addSuperAndMemberTypes(Set<IType> members, Set<IType> supers, IType type, IJavaProject currentProject, IJavaProject[] projects, IProgressMonitor monitor)
+ throws JavaModelException
+ {
+ if (!type.exists())
+ return; // mh?
+
+ IType superType = null;
+ String superclassName = type.getSuperclassName();
+ String packageName = null;
+ String typeName = null;
+ if (superclassName != null) {
+ superclassName = superclassName.replace('$', '.');
+ if (superclassName.indexOf('.') != -1) {
+ // qualified, find the type directly:
+ superType = currentProject.findType(superclassName);
+ } else {
+ // resolve it now:
+ String[][] resolvedSuperName = type.resolveType(superclassName);
+ if (resolvedSuperName != null && resolvedSuperName.length == 1) {
+ packageName = resolvedSuperName[0][0];
+ typeName = resolvedSuperName[0][1];
+ if (!(packageName.equals("java.lang") && typeName.equals("Object"))) //$NON-NLS-1$ //$NON-NLS-2$
+ {
+ superType = currentProject.findType(packageName, typeName, (IProgressMonitor)null);
+
+ if (superType == null)
+ for (IJavaProject prj : projects)
+ if ((superType = prj.findType(packageName, typeName, (IProgressMonitor)null)) != null)
+ break;
+ }
+ }
+ }
+ }
+
+ if (superType != null && !superType.isAnonymous()) {
+ supers.add(superType);
+ if (!members.contains(superType)) // avoid super-member-loop
+ addSuperAndMemberTypes(members, supers, superType, currentProject, projects, monitor);
+ }
+
+ for (IType member : type.getTypes()) {
+ if (member.isInterface()) continue; // not currently bindable
+ if ( Flags.isRole(member.getFlags())
+ && OTNameUtils.isTopConfined(member.getElementName())) continue; // confineds are not bound base
+ members.add(member);
+ if (!supers.contains(member)) // avoid super-member-loop
+ addSuperAndMemberTypes(members, supers, member, currentProject, projects, monitor);
+ }
+ }
+ /**
+ * Get all direct and indirect subtypes of all types in 'types'.
+ * @param types
+ * @param monitor
+ * @return
+ * @throws JavaModelException
+ */
+ Set<IType> getSubTypes(Set<IType> types, IProgressMonitor monitor) throws JavaModelException {
+ monitor.beginTask("base class hierarchy", types.size());
+
+ IJavaSearchScope workspaceScope = SearchEngine.createWorkspaceScope();
+ Set<IType> subTypes = new HashSet<IType>(13);
+ for (IType type: types) {
+ TypeHierarchy hier = new TypeHierarchy(type, null, workspaceScope, true);
+ hier.refresh(monitor);
+ for(IType subType : hier.getSubtypes(type))
+ subTypes.add(subType);
+ monitor.worked(1);
+ }
+ monitor.done();
+ return subTypes;
+ }
+
+ /** Fetch projects from a resource or all workspace projects if resource === null */
+ IJavaProject[] getProjects(IResource resource) {
+ IJavaProject[] projects = null;
+ if (resource != null) {
+ IProject project = resource.getProject();
+ projects = getProjectsToSearch(project);
+ } else {
+ IWorkspace ws = ResourcesPlugin.getWorkspace();
+ ArrayList<IJavaProject> projectList = new ArrayList<IJavaProject>();
+ for (IProject prj : ws.getRoot().getProjects())
+ if (isOTProject(prj) && prj.isOpen()) // FIXME(SH): better project filtering
+ projectList.add(JavaCore.create(prj));
+ projects = projectList.toArray(new IJavaProject[projectList.size()]);
+ }
+ return projects;
+ }
+
+ private IJavaProject[] getProjectsToSearch(IProject baseProject)
+ {
+ Set<IJavaProject> result = new HashSet<IJavaProject>();
+ calculateProjectsToSearch(baseProject, result);
+ return result.toArray(new IJavaProject[result.size()]);
+ }
+
+ private boolean isOTProject(IProject project)
+ {
+ try
+ {
+ return project.hasNature(JavaCore.OTJ_NATURE_ID);
+ }
+ catch (CoreException ex)
+ {
+ return false;
+ }
+ }
+
+ private boolean isPluginProject(IProject project)
+ {
+ try
+ {
+ return project.hasNature(PDE_PLUGIN_NATURE_ID);
+ }
+ catch (CoreException ex)
+ {
+ return false;
+ }
+ }
+
+ private void calculateProjectsToSearch(IProject currentProject, Set<IJavaProject> allProjects)
+ {
+ if (isOTProject(currentProject))
+ {
+ allProjects.add(JavaCore.create(currentProject));
+ }
+
+// if (isPluginProject(currentProject))
+// return; // don't search indirect dependencies of plug-in projects because aspectBindings must be declared directly
+
+ IProject[] referencingProjects = currentProject.getReferencingProjects();
+
+ for (int i = 0; i < referencingProjects.length; i++)
+ {
+ IProject project = referencingProjects[i];
+ calculateProjectsToSearch(project, allProjects);
+ }
+ }
+
+ /** Does this represent a real JavaElement (including existing ancestors)? */
+ public abstract boolean exists();
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/AnnotationHelper.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/AnnotationHelper.java
new file mode 100644
index 0000000..e545dc7
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/AnnotationHelper.java
@@ -0,0 +1,114 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2009 Technical University Berlin, Germany.
+ *
+ * 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
+ * $Id: AnnotationHelper.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.callinmarkers;
+
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IJavaModelMarker;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaAnnotationIterator;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.AnnotationModel;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.MarkerAnnotation;
+
+/**
+ * This class helps the callin marker creator to handle problem annotations/markers.
+ *
+ * @author stephan
+ * @since 1.2.6
+ */
+public class AnnotationHelper {
+ private AnnotationModel fAnnotationModel;
+
+ public AnnotationHelper(IEditorPart targetEditor, IEditorInput editorInput) {
+ ITextEditor textEditor = (ITextEditor) targetEditor.getAdapter(ITextEditor.class);
+ if (textEditor != null) {
+ IDocumentProvider provider= textEditor.getDocumentProvider();
+ fAnnotationModel = (AnnotationModel) provider.getAnnotationModel(editorInput);
+ }
+ }
+
+ /** If a callout binds to an unused private method/field, remove the "unused" warning. */
+ <M> void removeSomeWarnings(IResource resource, ISourceRange nameRange) throws CoreException
+ {
+ if (fAnnotationModel == null)
+ return;
+
+ Iterator annotationIterator = new JavaAnnotationIterator(
+ fAnnotationModel.getAnnotationIterator(nameRange.getOffset(), nameRange.getLength(), false, true),
+ false); // not all, only problems
+ boolean needRemoveMarker = false;
+ annotations:
+ while (annotationIterator.hasNext()) {
+ Object next = annotationIterator.next();
+ if (next instanceof IJavaAnnotation) {
+ IJavaAnnotation javaAnnot = (IJavaAnnotation) next;
+ if (javaAnnot.isProblem() || isProblemMarkerAnnotation(javaAnnot))
+ {
+ switch (javaAnnot.getId()) {
+ case IProblem.UnusedPrivateField:
+ case IProblem.UnusedPrivateMethod:
+ fAnnotationModel.removeAnnotation((Annotation)javaAnnot); // remove from the ruler
+ if (javaAnnot instanceof MarkerAnnotation) {
+ ((MarkerAnnotation) javaAnnot).getMarker().delete(); // remove from problems view
+ } else {
+ needRemoveMarker = true;
+ }
+ break annotations;
+ }
+ }
+ }
+ }
+ if (!needRemoveMarker)
+ return;
+ IMarker[] problems = resource.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_ZERO);
+ if (problems != null) {
+ markers: for (IMarker problem : problems) {
+ int problemStart = problem.getAttribute(IMarker.CHAR_START, -1);
+ if (problemStart >= nameRange.getOffset() && problemStart < (nameRange.getOffset()+nameRange.getLength()))
+ {
+ switch(problem.getAttribute(IJavaModelMarker.ID, -1)) {
+ case IProblem.UnusedPrivateField:
+ case IProblem.UnusedPrivateMethod:
+ problem.delete();
+ break markers;
+ }
+ }
+ }
+ }
+ }
+
+ private static boolean isProblemMarkerAnnotation(IJavaAnnotation annotation) {
+ if (!(annotation instanceof MarkerAnnotation))
+ return false;
+ try {
+ return(((MarkerAnnotation)annotation).getMarker().isSubtypeOf(IMarker.PROBLEM));
+ } catch (CoreException e) {
+ return false;
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarker.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarker.java
new file mode 100644
index 0000000..43ea883
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarker.java
@@ -0,0 +1,119 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2008 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: CallinMarker.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.callinmarkers;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+
+/**
+ * @author gis
+ */
+public class CallinMarker
+{
+ public static final String CALLIN_ID = "org.eclipse.objectteams.otdt.ui.callinMarker"; //$NON-NLS-1$
+ public static final String CALLOUT_ID = "org.eclipse.objectteams.otdt.ui.calloutMarker"; //$NON-NLS-1$
+ public static final String PLAYEDBY_ID = "org.eclipse.objectteams.otdt.ui.playedByMarker"; //$NON-NLS-1$
+ public static final String ATTR_BASE_ELEMENT = "org.eclipse.objectteams.otdt.ui.markerAttr.BaseElement"; //$NON-NLS-1$
+ public static final String ATTR_ROLE_ELEMENTS = "org.eclipse.objectteams.otdt.ui.markerAttr.RoleElements"; //$NON-NLS-1$
+
+ private Map<String, Object> _attribs = new HashMap<String, Object>(11);
+ private String id;
+
+ public CallinMarker(String markerKind)
+ {
+ super();
+ this.id = markerKind;
+ _attribs.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
+ _attribs.put(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_HIGH));
+ }
+
+ public void setLineNumber(int line)
+ {
+ _attribs.put(IMarker.LINE_NUMBER, new Integer(line));
+ }
+
+ public void setNameRange(ISourceRange nameRange) {
+ _attribs.put(IMarker.CHAR_START, nameRange.getOffset());
+ _attribs.put(IMarker.CHAR_END, nameRange.getOffset()+nameRange.getLength());
+ }
+
+ /** define the roles or callin mappings referenced by the base element. */
+ public <M extends IMember> void setRoleElement(Set<M> roleElements)
+ {
+ StringBuffer encoded = new StringBuffer();
+ for (IMember m : roleElements) {
+ encoded.append(m.getHandleIdentifier());
+ encoded.append('\n');
+ }
+ this._attribs.put(CallinMarker.ATTR_ROLE_ELEMENTS, encoded.toString());
+ }
+
+ /** set the base element (class or method) to which this marker is attached. */
+ public void setBaseElement(IMember baseElement)
+ {
+ _attribs.put(CallinMarker.ATTR_BASE_ELEMENT, baseElement.getHandleIdentifier());
+ if (baseElement.getElementType() == IJavaElement.TYPE) {
+ _attribs.put(IMarker.MESSAGE, OTDTUIPlugin.getResourceString("CallinMarker.playedby_tooltip")+' '+baseElement.getElementName()); //$NON-NLS-1$
+ } else if (this.id == CALLIN_ID) {
+ _attribs.put(IMarker.MESSAGE, OTDTUIPlugin.getResourceString("CallinMarker.callin_tooltip")+' '+baseElement.getElementName()+"()"); //$NON-NLS-1$ //$NON-NLS-2$
+ } else if (this.id == CALLOUT_ID) {
+ String baseMemberName = baseElement.getElementName();
+ if (baseElement.getElementType() == IJavaElement.METHOD) // not for callout to field
+ baseMemberName += "()"; //$NON-NLS-1$
+ _attribs.put(IMarker.MESSAGE, OTDTUIPlugin.getResourceString("CallinMarker.callout_tooltip") + ' ' + baseMemberName); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Actually create the marker.
+ * PRE: all relevant attributes have been set before.
+ *
+ * @param target the target element where to attach the marker (based on a resource or a java element)
+ * @throws CoreException thrown when a marker operation failed.
+ */
+ @SuppressWarnings("unchecked") // IMarker.getAttributes() yields raw type
+ public void create(AbstractMarkable target) throws CoreException
+ {
+ IMarker marker = target.createMarker(this.id);
+ Map markerAttributes = marker.getAttributes();
+ if (markerAttributes != null)
+ _attribs.putAll(markerAttributes); // markers for JavaElements have already one attribute
+ marker.setAttributes(_attribs);
+ _attribs.clear(); // clear attributes for reuse of this object
+ }
+
+ public static boolean isTypeMarker(IMarker marker) {
+ try {
+ return marker.getType().equals(PLAYEDBY_ID);
+ } catch (CoreException e) {
+ return false;
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarkerCreator2.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarkerCreator2.java
new file mode 100644
index 0000000..5b938e7
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarkerCreator2.java
@@ -0,0 +1,785 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2008 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: CallinMarkerCreator2.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.callinmarkers;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+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.Status;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IClassFile;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.search.IJavaSearchConstants;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.core.search.SearchMatch;
+import org.eclipse.jdt.core.search.SearchPattern;
+import org.eclipse.jdt.core.search.SearchRequestor;
+import org.eclipse.jface.action.IStatusLineManager;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DefaultLineTracker;
+import org.eclipse.jface.text.ILineTracker;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.objectteams.otdt.core.ICallinMapping;
+import org.eclipse.objectteams.otdt.core.ICalloutMapping;
+import org.eclipse.objectteams.otdt.core.ICalloutToFieldMapping;
+import org.eclipse.objectteams.otdt.core.IMethodMapping;
+import org.eclipse.objectteams.otdt.core.IOTJavaElement;
+import org.eclipse.objectteams.otdt.core.IOTType;
+import org.eclipse.objectteams.otdt.core.IRoleType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.core.search.OTSearchEngine;
+import org.eclipse.objectteams.otdt.internal.ui.preferences.GeneralPreferences;
+import org.eclipse.objectteams.otdt.ui.JavaEditorActivationListener;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartReference;
+
+/**
+ * This class creates Object Teams binding markers of two kinds:
+ * <ul>
+ * <li>playedBy markers marking base classes bound by playedBy
+ * <li>callin markers marking base methods bound by callin.
+ * </ul>
+ * It also monitors editor and resource changes and automatically creates/removes callin
+ * markers for all methods.
+ *
+ * TODO(SH): validate updating for methods and implement something similar for types, too.
+ *
+ * @author carp
+ */
+public class CallinMarkerCreator2 extends JavaEditorActivationListener
+{
+
+ protected CallinMarkerJob _currentJob;
+ private Map<IJavaElement,IType> m_cachedBaseForRole = new HashMap<IJavaElement,IType>();
+ private Set<IResource> m_cachedMarkersForResources = new HashSet<IResource>();
+ private Set<IJavaElement> m_cachedMarkersForJavaElements = new HashSet<IJavaElement>();
+ private boolean m_enabled = false;
+ protected AnnotationHelper annotationHelper;
+
+ /**
+ * Typical usage:
+ * <code>
+ * CallinMarkerCreator creator = OTDTUIPlugin.getCallinMarkerCreator();
+ * creator.updateAllMarkers(myMethod, someProgressMonitor);
+ * </code>
+ */
+ public CallinMarkerCreator2()
+ {
+ IPreferenceStore store = OTDTUIPlugin.getDefault().getPreferenceStore();
+ store.addPropertyChangeListener(new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event)
+ {
+ if (GeneralPreferences.CALLIN_MARKER_ENABLED_BOOL.equals(event.getProperty()))
+ {
+ boolean newValue = ((Boolean) event.getNewValue()).booleanValue();
+ setEnabled(newValue);
+ // FIXME: upon enablement, run callin marker creator for current editor, if any
+ }
+ }
+ });
+
+ setEnabled(store.getBoolean(GeneralPreferences.CALLIN_MARKER_ENABLED_BOOL));
+ }
+
+ public void setEnabled(boolean enable)
+ {
+ if (m_enabled == enable)
+ return;
+
+ if (enable)
+ installListener();
+ else
+ uninstallListener();
+
+ m_enabled = enable;
+ }
+
+ public boolean isEnabled()
+ {
+ return m_enabled;
+ }
+
+ /** API for {@link RoleBindingChangedListener}. */
+ public void updateCallinMarker(final IMember member, IStatusLineManager statusLine)
+ {
+ if (!isEnabled())
+ return;
+
+ if (!isCached(member.getResource()) && !isCreatingMarkersFor(member.getResource()))
+ return;
+
+ final AbstractMarkable target = new ResourceMarkable(member.getResource());
+ CallinMarkerJob job = new CallinMarkerJob(target) {
+ protected void updateMarkers(IProgressMonitor monitor) throws Exception {
+ updateCallinMarker(target, member, monitor);
+ }
+ };
+
+ // updating just one single method will not set current _currentJob
+ schedule(job, statusLine);
+ }
+
+
+ /**
+ * API for {@link RoleBindingChangedListener}.
+ * When some role bindings have changed remove cached information regarding its base.
+ */
+ public void invalidateRole(IType roleType, IType baseClass) {
+ if (baseClass != null)
+ invalidateBase(baseClass);
+ IType cachedBaseClass = this.m_cachedBaseForRole.get(roleType);
+ if ( cachedBaseClass != null
+ && !cachedBaseClass.equals(baseClass))
+ {
+ // playedBy mapping itself has changed
+ this.m_cachedBaseForRole.remove(roleType);
+ invalidateBase(cachedBaseClass);
+ }
+ }
+ void invalidateBase(IJavaElement baseClass) {
+ this.m_cachedMarkersForJavaElements.remove(baseClass);
+ try {
+ IJavaElement cu = baseClass.getAncestor(IJavaElement.COMPILATION_UNIT);
+ if (cu != null) {
+ IResource resource = cu.getCorrespondingResource();
+ if (resource != null)
+ this.m_cachedMarkersForResources.remove(resource);
+ }
+ } catch (JavaModelException e) {
+ // cannot uncache missing resource
+ }
+ }
+
+ /**
+ * When the editor input changed find the markable target and update markers.
+ */
+ protected void activeJavaEditorChanged(IWorkbenchPart editor)
+ {
+ if (!(editor instanceof IEditorPart))
+ {
+ if (editor == null) {
+ this.annotationHelper = null;
+ this.fActiveEditor = null;
+ }
+ return;
+ }
+
+ IEditorPart targetEditor = (IEditorPart) editor;
+ final IEditorInput editorInput = targetEditor.getEditorInput();
+ final IStatusLineManager statusLine = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
+
+ this.fActiveEditor = editor;
+ this.annotationHelper = new AnnotationHelper(targetEditor, editorInput);
+
+ AbstractMarkable target= null;
+ if ((editorInput instanceof IFileEditorInput)) { // source file
+ IResource resource = ((IFileEditorInput)editorInput).getFile();
+ if (resource == null || isCached(resource) || isCreatingMarkersFor(resource))
+ return; // already has markers -- skip it
+ target = new ResourceMarkable(resource);
+ } else { // binary java element
+ IJavaElement element = getInputJavaElement((IEditorPart) editor);
+ if (element == null || isCached(element) || isCreatingMarkersFor(element))
+ return; // already has markers -- skip it
+ target = new JavaElementMarkable(element);
+ }
+
+ if (target.exists())
+ updateCallinMarkers(target, statusLine);
+ }
+
+ // FIXME: listen to classpath changes as well
+ // hint from the news group:
+ // See:
+ // - org.eclipse.jdt.core.JavaCore.addElementChangedListener(IElementChangedListener, int)
+ // - org.eclipse.jdt.core.IJavaElementDelta.F_CLASSPATH_CHANGED
+
+ /**
+ * @param resource the resource in where to look for bound base methods
+ * @param statusLine a status line where errors can be displayed or null if you don't want error messages
+ */
+ public void updateCallinMarkers(final AbstractMarkable target, IStatusLineManager statusLine)
+ {
+ CallinMarkerJob job = new CallinMarkerJob(target) {
+ protected void updateMarkers(IProgressMonitor monitor) throws Exception {
+ updateCallinMarkers(target, monitor);
+ }
+ };
+
+ setCurrentJob(job);
+ schedule(job, statusLine);
+ }
+
+ /**
+ * For a given markable target remove all old markers and create new ones.
+ *
+ * @param target the markable item to create markers for
+ * @param monitor
+ * @throws CoreException thrown when one of the many searches and or lookups failed.
+ */
+ private void updateCallinMarkers(final AbstractMarkable target, IProgressMonitor monitor) throws CoreException
+ {
+ try
+ {
+ if (target == null || !target.exists())
+ return;
+
+ monitor.beginTask(
+ MessageFormat.format(
+ OTDTUIPlugin.getResourceString("CallinMarkerCreator2.updating_for_resource_message"), //$NON-NLS-1$
+ new Object[] { target.getName() }), 62);
+
+ target.removeCallinMarkers();
+ monitor.worked(2);
+
+ // ==== role bindings: ====
+ IJavaProject[] projects = target.getProjects();
+ Set<IType> allTypes = target.getAllTypes(projects, monitor); // 10 ticks
+ Map<IMember, Set<IType>> playedByMap = searchPlayedByBindings(allTypes, projects, new MySubProgressMonitor(monitor, 20));
+ if (playedByMap == null || playedByMap.size() == 0)
+ return;
+
+ createMarkersFor(target, playedByMap, CallinMarker.PLAYEDBY_ID, new MySubProgressMonitor(monitor, 5));
+
+ // collect all roles for use as search scope:
+ IMember[] allRoleTypes = collectRolesAndSubroles(playedByMap, new MySubProgressMonitor(monitor, 10));
+
+ // ==== callin/callout bindings: ====
+ Set<IMember> allMembers = getAllMethodsAndFields(target.getJavaElement());
+ monitor.worked(5);
+ updateMethodMarkers(target, allRoleTypes, allMembers, new SubProgressMonitor(monitor, 10));
+ }
+ finally {
+ monitor.done();
+ }
+ }
+
+ private IMember[] collectRolesAndSubroles(Map<IMember, Set<IType>> playedByMap, IProgressMonitor submon)
+ throws JavaModelException
+ {
+ IMember[] allRoleTypes;
+ Set<IMember> collectedRoleTypes = new HashSet<IMember>();
+ submon.beginTask("Finding sub roles", playedByMap.size()); //$NON-NLS-1$
+ for (Set<IType> value : playedByMap.values()) {
+ collectedRoleTypes.addAll(value);
+ for (IType member : value) {
+ if (member.exists()) {
+ IOTType otType = OTModelManager.getOTElement(member);
+ if (otType != null) {
+ IType[] subtypes = otType.newOTTypeHierarchy(submon).getAllSubtypes(otType);
+ for (IType subtype : subtypes)
+ collectedRoleTypes.add(subtype);
+ }
+ }
+ submon.worked(1);
+ }
+ }
+ allRoleTypes = collectedRoleTypes.toArray(new IMember[collectedRoleTypes.size()]);
+ submon.done();
+ return allRoleTypes;
+ }
+
+ private void updateCallinMarker(AbstractMarkable target, IMember member, IProgressMonitor monitor) throws CoreException
+ {
+ // TODO(SH): in this scenario a search for all callins mentioning method should be faster.
+ try
+ {
+ monitor.beginTask(
+ MessageFormat.format(
+ OTDTUIPlugin.getResourceString("CallinMarkerCreator2.updating_for_method_message"), //$NON-NLS-1$
+ new Object[] { member.getElementName() }), 45);
+
+ IResource resource = member.getResource();
+ if (resource != null) // only called when base class changed -> source only.
+ {
+ CallinMarkerRemover.removeCallinMarker( member, resource );
+ monitor.worked(5);
+
+ // find direct roles:
+ ArrayList<IType> allTypes = new ArrayList<IType>(1);
+ allTypes.add((IType)member.getAncestor(IJavaElement.TYPE)); // TODO(SH): could be IOTType?
+ Map<IMember, Set<IType>> playedByMap = searchPlayedByBindings(allTypes,
+ new IJavaProject[]{member.getJavaProject()},
+ new MySubProgressMonitor(monitor, 20));
+ if (playedByMap == null)
+ return;
+
+ // collect all roles w/ subroles for use as search scope:
+ IMember[] allRoleTypes = collectRolesAndSubroles(playedByMap, new MySubProgressMonitor(monitor, 10));
+
+ ArrayList<IMember> memberSet = new ArrayList<IMember>(1);
+ memberSet.add(member);
+ updateMethodMarkers(target, allRoleTypes, memberSet, new SubProgressMonitor(monitor, 10));
+ }
+ }
+ finally {
+ monitor.done();
+ }
+ }
+
+ private void updateMethodMarkers(AbstractMarkable target, IMember[] allRoleTypes, Collection<IMember> memberSet, IProgressMonitor monitor)
+ {
+ try {
+ monitor.beginTask(null, 40);
+ Map<IMember, Set<IMember>> callinMap = new HashMap<IMember, Set<IMember>>();
+ Map<IMember, Set<IMember>> calloutMap = new HashMap<IMember, Set<IMember>>();
+ searchMemberBindings(memberSet, allRoleTypes, callinMap, calloutMap, new MySubProgressMonitor(monitor, 20));
+ createMarkersFor(target, callinMap, CallinMarker.CALLIN_ID, new MySubProgressMonitor(monitor, 10));
+ createMarkersFor(target, calloutMap, CallinMarker.CALLOUT_ID, new MySubProgressMonitor(monitor, 10));
+ } finally {
+ monitor.done();
+ }
+ }
+
+ private void setCurrentJob(CallinMarkerJob job)
+ {
+ synchronized (this) {
+ if (_currentJob != null) {
+ _currentJob.cancel();
+ }
+
+ _currentJob = job;
+ }
+ }
+
+ // ------ Some of these methods are duplicated to account for the source/binary duality: ------
+ public boolean isCreatingMarkersFor(IResource resource)
+ {
+ synchronized(this) {
+ if (_currentJob == null) return false;
+ IResource jobResource = _currentJob.getResource();
+ return (jobResource != null) && jobResource.equals(resource);
+ }
+ }
+
+ private boolean isCreatingMarkersFor(IJavaElement element)
+ {
+ synchronized(this) {
+ if (_currentJob == null) return false;
+ IJavaElement javaElement = _currentJob.getJavaElement();
+ return (javaElement != null) && javaElement.equals(element);
+ }
+ }
+
+ private boolean isCached(IResource resource)
+ {
+ return m_cachedMarkersForResources.contains(resource);
+ }
+ private boolean isCached(IJavaElement element)
+ {
+ return m_cachedMarkersForJavaElements.contains(element);
+ }
+
+ private void setCached(final IResource resource)
+ {
+ m_cachedMarkersForResources.add(resource);
+ }
+ private void setCached(final IJavaElement element)
+ {
+ m_cachedMarkersForJavaElements.add(element);
+ }
+
+ private void removeFromCache(final IResource resource)
+ {
+ m_cachedMarkersForResources.remove(resource);
+ }
+ private void removeFromCache(final IJavaElement element)
+ {
+ m_cachedMarkersForJavaElements.remove(element);
+ }
+
+ private void removeFromCache(IWorkbenchPartReference ref)
+ {
+ IWorkbenchPart part = ref.getPart(false);
+ if (part instanceof IEditorPart)
+ {
+ IEditorInput input = ((IEditorPart) part).getEditorInput();
+ if (input instanceof IFileEditorInput)
+ removeFromCache(((IFileEditorInput) input).getFile());
+ }
+ }
+
+ public void partClosed(IWorkbenchPartReference ref)
+ {
+ removeFromCache(ref);
+ super.partClosed(ref);
+ }
+
+ /**
+ * Fetch all methods and fields contained in the input.
+ * @param javaElement the corresponding ICompilationUnit, IClassFile or IType
+ */
+ private Set<IMember> getAllMethodsAndFields(IJavaElement javaElement) {
+ if (javaElement == null)
+ return new HashSet<IMember>(0);
+
+ Set<IMember> members = new HashSet<IMember>(13);
+
+ switch (javaElement.getElementType())
+ {
+ case IJavaElement.COMPILATION_UNIT:
+ {
+ ICompilationUnit unit = (ICompilationUnit)javaElement;
+ IType[] types;
+ try {
+
+ types = unit.getTypes();
+ for (int idx = 0; idx < types.length; idx++)
+ members.addAll(getAllMethodsAndFields(types[idx]));
+
+ } catch (JavaModelException e) {
+ // ignore, without types we simply find no methods
+ }
+ break;
+ }
+ case IJavaElement.CLASS_FILE:
+ {
+ IClassFile classFile = (IClassFile)javaElement;
+ members.addAll(getAllMethodsAndFields(classFile.getType()));
+ break;
+ }
+ case IJavaElement.TYPE:
+ {
+ IType type = (IType) javaElement;
+ try {
+
+ members.addAll(Arrays.asList(type.getMethods()));
+ members.addAll(Arrays.asList(type.getFields()));
+ // handle all inner types
+ IType[] memberTypes = type.getTypes();
+ for (int idx = 0; idx < memberTypes.length; idx++)
+ members.addAll(getAllMethodsAndFields(memberTypes[idx]));
+
+ } catch (JavaModelException e) {
+ // ignore, finding methods bailed out but keep those we already found
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ return members;
+ }
+
+ /**
+ * Find all playedBy bindings within a given set of projects refering to one of baseTypes as its baseclass.
+ *
+ * @param baseTypes
+ * @param projects
+ * @param monitor
+ * @return a map indexed by base types containing sets of role types bound to the given base type.
+ * @throws CoreException
+ */
+ private Map<IMember, Set<IType>> searchPlayedByBindings(Collection<IType> baseTypes, IJavaProject[] projects, MySubProgressMonitor monitor)
+ {
+ if (baseTypes == null || baseTypes.size() == 0) {
+ monitor.doneNothing();
+ return null;
+ }
+
+ OTSearchEngine engine = new OTSearchEngine();
+ IJavaSearchScope searchScope = OTSearchEngine.createOTSearchScope(projects, false);
+ final Map<IMember, Set<IType>> resultMap = new HashMap<IMember, Set<IType>>();
+
+ try {
+ monitor.beginTask(OTDTUIPlugin.getResourceString("searching role types"), baseTypes.size()); //$NON-NLS-1$
+
+ for (final IType baseType : baseTypes)
+ {
+ try
+ {
+ IProgressMonitor searchMonitor = new SubProgressMonitor(monitor, 1);
+ if (!baseType.exists()) // ensure it's 'open'
+ continue;
+ if (baseType.isEnum() || baseType.isAnnotation())
+ continue; // no callin-to-enum/annot
+ SearchPattern pattern = SearchPattern.createPattern(baseType, IJavaSearchConstants.PLAYEDBY_REFERENCES);
+ if (pattern == null)
+ OTDTUIPlugin.getDefault().getLog().log(new Status(Status.ERROR, OTDTUIPlugin.UIPLUGIN_ID, "Error creating pattern")); //$NON-NLS-1$
+ else
+ engine.search(
+ pattern,
+ searchScope,
+ new SearchRequestor() {
+ public void acceptSearchMatch(SearchMatch match)
+ throws CoreException
+ {
+ Object element = match.getElement();
+ if (element instanceof IType)
+ {
+ // FIXME(SH): check: if mapping is a role, baseType must be conform to its baseclass
+ IType mapping = (IType) element;
+ addToMapOfSets(resultMap, baseType, mapping);
+ }
+ }
+ },
+ searchMonitor);
+ }
+ catch (CoreException ex)
+ {
+ OTDTUIPlugin.getDefault().getLog().log(new Status(Status.ERROR, OTDTUIPlugin.UIPLUGIN_ID, "Error finding playedBy bindings", ex)); //$NON-NLS-1$
+ }
+ }
+ }
+ finally {
+ monitor.done();
+ }
+
+ return resultMap;
+ }
+
+ /**
+ * Search all callin bindings within allRoleTypes mentioning one of baseMethods as a base method.
+ *
+ * @param baseMembers base methods and fields of interest
+ * @param allRoleTypes roles where to search
+ * @param callinMap store found callin bindings here (one set per base method)
+ * @param calloutMap store found callout bindings here (one set per base method/field)
+ * @param monitor
+ */
+ private void searchMemberBindings(Collection<IMember> baseMembers,
+ IMember[] allRoleTypes,
+ Map<IMember, Set<IMember>> callinMap,
+ Map<IMember, Set<IMember>> calloutMap,
+ MySubProgressMonitor monitor)
+ {
+ if (baseMembers == null || baseMembers.size() == 0) {
+ monitor.doneNothing();
+ return;
+ }
+
+ // given all potential role types, just directly traverse to the callin bindings:
+ for (IMember roleMember : allRoleTypes)
+ {
+ IOTType otType = OTModelManager.getOTElement((IType)roleMember);
+ if (otType == null || !otType.isRole()) continue;
+ IRoleType roleType = (IRoleType)otType;
+
+ for (IMethodMapping mapping : roleType.getMethodMappings())
+ {
+ try {
+ if (mapping.getElementType() == IOTJavaElement.CALLIN_MAPPING)
+ {
+ ICallinMapping callinMapping = (ICallinMapping) mapping;
+ for (IMethod baseMethod : callinMapping.getBoundBaseMethods())
+ if (baseMembers.contains(baseMethod)) // TODO(SH): would comparison of resources suffice??
+ addToMapOfSets(callinMap, baseMethod, mapping);
+ }
+ else if (mapping.getElementType() == IOTJavaElement.CALLOUT_MAPPING) {
+ ICalloutMapping calloutMapping = (ICalloutMapping) mapping;
+ IMethod baseMethod = calloutMapping.getBoundBaseMethod();
+ if (baseMembers.contains(baseMethod) && !isVisibleFor(baseMethod, roleType))
+ addToMapOfSets(calloutMap, baseMethod, mapping);
+ }
+ else if (mapping.getElementType() == IOTJavaElement.CALLOUT_TO_FIELD_MAPPING) {
+ ICalloutToFieldMapping calloutMapping = (ICalloutToFieldMapping) mapping;
+ IField baseField = calloutMapping.getBoundBaseField();
+ if (baseMembers.contains(baseField) && !isVisibleFor(baseField, roleType))
+ addToMapOfSets(calloutMap, baseField, mapping);
+ }
+ } catch (JavaModelException ex) {
+ OTDTUIPlugin.getDefault().getLog().log(new Status(Status.ERROR, OTDTUIPlugin.UIPLUGIN_ID, "Error checking callin/callout binding", ex)); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+ boolean isVisibleFor(IMember baseMember, IType roleType) throws JavaModelException {
+ int flags = baseMember.getFlags();
+ if (Flags.isPrivate(flags))
+ return false;
+ if (Flags.isPublic(flags))
+ return true;
+ String rolePackage = roleType.getPackageFragment().getElementName();
+ return baseMember.getDeclaringType().getPackageFragment().getElementName().equals(rolePackage);
+ }
+
+ /**
+ * add the key->value pair to the given map of sets, creating a new value set if needed.
+ * @param mapOfSets
+ * @param key
+ * @param value
+ */
+ private <M extends IMember> void addToMapOfSets(final Map<IMember, Set<M>> mapOfSets, IMember key, M value)
+ {
+ Set<M> setForType = mapOfSets.get(key);
+ if (setForType == null)
+ mapOfSets.put(key, setForType = new HashSet<M>());
+ setForType.add(value);
+ }
+
+ /**
+ * Create actual markers wrapped by CallinMarkers from the data given as bindingMap.
+ *
+ * @param target where to attach the markers
+ * @param bindingMap data for creating markers: a map from base elements (classes|methods) to role elements (roles|callins) binding to the former.
+ * @param markerKind what kind of marker should be created?
+ * @param monitor
+ */
+ private <M extends IMember> void createMarkersFor(final AbstractMarkable target, final Map<IMember, Set<M>> bindingMap, final String markerKind, MySubProgressMonitor monitor)
+ {
+ if (bindingMap == null) {
+ monitor.doneNothing();
+ return;
+ }
+
+ final Set<IMember> baseElements = bindingMap.keySet();
+ if (baseElements == null || baseElements.size() == 0) {
+ monitor.doneNothing();
+ return;
+ }
+ // freeze this value to avoid shared access to the field:
+ final AnnotationHelper myAnnotationHelper = annotationHelper;
+ if (myAnnotationHelper == null) { // has the active editor been reset to null?
+ if (monitor != null)
+ monitor.setCanceled(true);
+ return;
+ }
+ IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
+ public void run(IProgressMonitor monitor) throws CoreException
+ {
+ monitor.beginTask(OTDTUIPlugin.getResourceString("CallinMarkerCreator2.creating_markers_message"), baseElements.size()); //$NON-NLS-1$
+
+ try {
+ ILineTracker lineTracker = null;
+ final ICompilationUnit compilationUnit = baseElements.iterator().next().getCompilationUnit();
+ if (compilationUnit != null) {
+ lineTracker = new DefaultLineTracker();
+ lineTracker.set(compilationUnit.getSource());
+ }
+ CallinMarker marker = new CallinMarker(markerKind);
+
+ for (IMember baseElement : baseElements)
+ {
+ // ensure type is actually contained in the target, not super/inherited
+ if (baseElement instanceof IType && !target.containsElement(baseElement))
+ continue;
+
+ Set<M> bindings = bindingMap.get(baseElement);
+
+ if (bindings != null && bindings.size() != 0)
+ {
+ if (markerKind == CallinMarker.PLAYEDBY_ID)
+ for (M binding : bindings)
+ CallinMarkerCreator2.this.m_cachedBaseForRole.put(binding, (IType)baseElement);
+
+ try {
+ ISourceRange nameRange = baseElement.getNameRange();
+ if (nameRange.getOffset() >= 0 && nameRange.getLength() >= 0) {
+ if (lineTracker != null) {
+ int line = lineTracker.getLineNumberOfOffset(nameRange.getOffset()) + 1; // one-based
+ marker.setLineNumber(line);
+ } else {
+ marker.setNameRange(nameRange);
+ }
+ if (markerKind.equals(CallinMarker.CALLOUT_ID)) {
+ myAnnotationHelper.removeSomeWarnings(target.getResource(), nameRange);
+ }
+ } else if (!baseElement.isBinary()) {
+ if (nameRange.getOffset() < 0)
+ throw new BadLocationException("Offset must be >= 0, is "+nameRange.getOffset());
+ if (nameRange.getLength() < 0)
+ throw new BadLocationException("Length must be >= 0, is "+nameRange.getLength());
+ }
+ }
+ catch (BadLocationException ex) {
+ OTDTUIPlugin.getExceptionHandler().logException(OTDTUIPlugin.getResourceString("CallinMarkerCreator2.line_number_error_message"), ex); //$NON-NLS-1$
+ }
+ marker.setBaseElement(baseElement);
+ marker.setRoleElement(bindings);
+
+ marker.create(target);
+ }
+ monitor.worked(1);
+ }
+ }
+ finally {
+ monitor.done();
+ }
+ }
+ };
+
+ try {
+ ResourcesPlugin.getWorkspace().run(runnable, null, IWorkspace.AVOID_UPDATE, monitor);
+ } catch (CoreException ex) {
+ OTDTUIPlugin.getExceptionHandler().logException("Error creating markers", ex); //$NON-NLS-1$
+ }
+ }
+
+ protected void schedule(final CallinMarkerJob job, IStatusLineManager statusLine)
+ {
+ job.addJobChangeListener(new JobListener(statusLine) {
+ protected void jobFinished(int status) {
+ synchronized(CallinMarkerCreator2.this) {
+ if (_currentJob == job)
+ _currentJob = null;
+
+ IResource resource = job.getResource();
+ if (resource != null)
+ if (status == IStatus.OK)
+ setCached(resource);
+ else
+ removeFromCache(resource);
+ else {
+ IJavaElement element = job.getJavaElement();
+ if (status == IStatus.OK)
+ setCached(element);
+ else
+ removeFromCache(element);
+ }
+ }
+ }
+ });
+
+ job.setPriority(Job.DECORATE);
+ job.schedule(100); // delay 100ms
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarkerJob.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarkerJob.java
new file mode 100644
index 0000000..7234cb8
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarkerJob.java
@@ -0,0 +1,82 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2008 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: CallinMarkerJob.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.callinmarkers;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+
+/**
+ * @author gis
+ */
+public abstract class CallinMarkerJob extends org.eclipse.core.runtime.jobs.Job
+{
+ private final IResource _resource;
+ private final IJavaElement _javaElement;
+
+ public CallinMarkerJob(final AbstractMarkable target)
+ {
+ super(OTDTUIPlugin.getResourceString("CallinMarkerJob.job_title")); //$NON-NLS-1$
+ if (target instanceof ResourceMarkable) {
+ this._resource = ((ResourceMarkable)target).fResource;
+ this._javaElement= null;
+ } else {
+ this._resource = null;
+ this._javaElement= ((JavaElementMarkable)target).fJavaElement;
+ }
+ // markerRule is normally null, but let's play by the rules:
+ IResource resource = target.getResource();
+ if (resource != null)
+ setRule(resource.getWorkspace().getRuleFactory().markerRule(resource));
+ }
+
+ protected IStatus run(IProgressMonitor monitor)
+ {
+ try {
+ updateMarkers(monitor);
+ }
+ catch (OperationCanceledException ex) {
+ return Status.CANCEL_STATUS;
+ }
+ catch (Exception ex) {
+ return OTDTUIPlugin.createErrorStatus("Exception during marker creation.", ex); //$NON-NLS-1$
+ }
+ catch (Error error) {} // ignore other errors, like Assertions and InternalCompilerErrors
+
+ return Status.OK_STATUS;
+ }
+
+ protected abstract void updateMarkers(IProgressMonitor monitor) throws Exception;
+
+ public final IResource getResource()
+ {
+ return this._resource;
+ }
+
+ public final IJavaElement getJavaElement()
+ {
+ return this._javaElement;
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarkerRemover.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarkerRemover.java
new file mode 100644
index 0000000..70d6085
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarkerRemover.java
@@ -0,0 +1,106 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2008 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: CallinMarkerRemover.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.callinmarkers;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+
+/**
+ * @author gis
+ */
+public class CallinMarkerRemover
+{
+ public static void removeCallinMarkers(IResource resource) throws CoreException
+ {
+ for (String id : new String[] { CallinMarker.PLAYEDBY_ID, CallinMarker.CALLIN_ID, CallinMarker.CALLOUT_ID} )
+ if (resource.exists())
+ resource.deleteMarkers(id, true, IResource.DEPTH_INFINITE);
+ }
+
+ public static synchronized void removeCallinMarker(IMember member, IResource resource)
+ {
+ // we need to pass the resource, as the method might already be removed and hence would
+ // not be able to give us a resource.
+ if (resource.exists())
+ {
+ try
+ {
+ IMarker marker;
+ if (member.getElementType() == IJavaElement.METHOD) {
+ marker = getCallinMarker(member, CallinMarker.CALLIN_ID, resource);
+ if (marker != null)
+ marker.delete();
+ }
+ // method or field:
+ marker = getCallinMarker(member, CallinMarker.CALLOUT_ID, resource);
+ if (marker != null)
+ marker.delete();
+ }
+ catch (CoreException ex)
+ {
+ OTDTUIPlugin.getExceptionHandler().
+ logException("Problems removing callin marker", ex); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
+ * Finds the marker attached to the given method.
+ * Note: may return null if nothing found.
+ */
+ private static synchronized IMarker getCallinMarker(IMember baseElement, String markerKind, IResource resource) throws JavaModelException, CoreException
+ {
+ IMarker[] markers = resource.findMarkers(markerKind, true, IResource.DEPTH_INFINITE);
+
+ String methodId = baseElement.getHandleIdentifier();
+
+ for (int i = 0; i < markers.length; i++)
+ {
+ if (methodId.equals(markers[i].getAttribute(CallinMarker.ATTR_BASE_ELEMENT, null)))
+ return markers[i];
+ }
+ return null;
+ }
+
+
+ public static void removeCallinMarkers(IJavaElement element) throws CoreException
+ {
+ if (element.exists())
+ {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+
+ // FIXME(SH): implement!
+// resource.deleteMarkers(CallinMarker.ID,
+// true,
+// IResource.DEPTH_INFINITE);
+ }
+ }
+
+
+
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/JavaElementMarkable.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/JavaElementMarkable.java
new file mode 100644
index 0000000..03ea62f
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/JavaElementMarkable.java
@@ -0,0 +1,110 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2008 Technical University Berlin, Germany.
+ *
+ * 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
+ * $Id: JavaElementMarkable.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.callinmarkers;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IClassFile;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+
+/**
+ * Implement markable protocol for java elements.
+ *
+ * @author stephan
+ * @since 1.2.5
+ */
+public class JavaElementMarkable extends AbstractMarkable {
+ IJavaElement fJavaElement;
+
+ public JavaElementMarkable(IJavaElement javaElement) {
+ this.fJavaElement = javaElement;
+ }
+
+ public String getName() {
+ return this.fJavaElement.getElementName();
+ }
+
+ public Set<IType> getAllTypes(IJavaProject[] projects, IProgressMonitor monitor) throws JavaModelException {
+ Set<IType> result = new HashSet<IType>(13);
+ if (this.fJavaElement instanceof IClassFile) {
+
+ IType type = ((IClassFile)this.fJavaElement).getType();
+
+ Set<IType> members = new HashSet<IType>(5);
+ Set<IType> supers = new HashSet<IType>(5);
+ members.add(type);
+ addSuperAndMemberTypes(members, supers, type, this.fJavaElement.getJavaProject(), projects, monitor);
+ result.addAll(members);
+ result.addAll(supers);
+ monitor.worked(5);
+
+ result.addAll(getSubTypes(members, new MySubProgressMonitor(monitor, 5)));
+ }
+ monitor.done();
+ return result;
+ }
+
+ public void removeCallinMarkers() throws CoreException {
+ CallinMarkerRemover.removeCallinMarkers(this.fJavaElement);
+ }
+
+ public IJavaElement getJavaElement() {
+ return this.fJavaElement;
+ }
+
+ public IResource getResource() {
+ return this.fJavaElement.getResource();
+ }
+
+ boolean containsElement(IJavaElement element) {
+ IJavaElement current = element;
+ while (current != null) {
+ if (current == this.fJavaElement)
+ return true;
+ current = current.getParent();
+ }
+ return false;
+ }
+
+ public boolean exists() {
+ return this.fJavaElement.exists();
+ }
+
+ IJavaProject[] getProjects() throws JavaModelException {
+ // FIXME(SH): might want to lookup the project from a library??
+ return getProjects(this.fJavaElement.getCorrespondingResource());
+ }
+
+ public IMarker createMarker(String id) throws CoreException {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IMarker marker = root.createMarker(id);
+ ((JavaCore)JavaCore.getPlugin()).configureJavaElementMarker(marker, this.fJavaElement);
+ return marker;
+ }
+
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/JobListener.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/JobListener.java
new file mode 100644
index 0000000..2f147e6
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/JobListener.java
@@ -0,0 +1,62 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2005, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: JobListener.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.callinmarkers;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.jface.action.IStatusLineManager;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+
+
+abstract class JobListener extends JobChangeAdapter
+{
+ private final IStatusLineManager _statusLine;
+
+ public JobListener(IStatusLineManager statusLine)
+ {
+ _statusLine = statusLine;
+ }
+
+ public void done(IJobChangeEvent event)
+ {
+ IStatus status = event.getResult();
+ switch (status.getCode())
+ {
+ case IStatus.ERROR:
+ if (_statusLine != null)
+ _statusLine.setErrorMessage(OTDTUIPlugin.getResourceString("CallinMarkerCreator2.search_failed_message")); //$NON-NLS-1$
+ OTDTUIPlugin.getExceptionHandler().logException(status.getMessage(), status.getException());
+ break;
+ case IStatus.CANCEL:
+ if (_statusLine != null)
+ _statusLine.setMessage(OTDTUIPlugin.getResourceString("CallinMarkerCreator2.search_canceled_message")); //$NON-NLS-1$
+ break;
+ default:
+ case IStatus.OK:
+ break; // do nothing
+ }
+
+ jobFinished(status.getCode());
+ }
+
+ protected abstract void jobFinished(int status);
+}
\ No newline at end of file
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/MySubProgressMonitor.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/MySubProgressMonitor.java
new file mode 100644
index 0000000..6909a61
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/MySubProgressMonitor.java
@@ -0,0 +1,45 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2005, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: MySubProgressMonitor.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.callinmarkers;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.SubProgressMonitor;
+
+public class MySubProgressMonitor extends SubProgressMonitor
+{
+ public MySubProgressMonitor(IProgressMonitor monitor, int ticks)
+ {
+ super(monitor, ticks, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
+ }
+
+ public void doneNothing() {
+ beginTask("", 1); //$NON-NLS-1$
+ done();
+ }
+
+ @Override
+ public void worked(int work) {
+ if (isCanceled())
+ throw new OperationCanceledException();
+ super.worked(work);
+ }
+}
\ No newline at end of file
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/ResourceMarkable.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/ResourceMarkable.java
new file mode 100644
index 0000000..81d98ab
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/ResourceMarkable.java
@@ -0,0 +1,103 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2008 Technical University Berlin, Germany.
+ *
+ * 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
+ * $Id: ResourceMarkable.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.callinmarkers;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+
+/**
+ * Implement the markable protocol for resources.
+ *
+ * @author stephan
+ * @since 1.2.5
+ */
+public class ResourceMarkable extends AbstractMarkable {
+ IResource fResource;
+
+ public ResourceMarkable(IResource resource) {
+ this.fResource = resource;
+ }
+
+ public String getName() {
+ return this.fResource.getName();
+ }
+
+ public Set<IType> getAllTypes(IJavaProject[] projects, IProgressMonitor monitor) throws CoreException {
+ Set<IType> result = new HashSet<IType>(13);
+ IJavaElement element = JavaCore.create(this.fResource);
+ if (element instanceof ICompilationUnit)
+ {
+ Set<IType> members = new HashSet<IType>(5);
+ Set<IType> supers = new HashSet<IType>(5);
+ for (IType type : ((ICompilationUnit) element).getTypes()) {
+ members.add(type);
+ addSuperAndMemberTypes(members, supers, type, JavaCore.create(this.fResource.getProject()), projects, monitor);
+ }
+ result.addAll(members);
+ result.addAll(supers);
+ monitor.worked(5);
+
+ result.addAll(getSubTypes(members, new MySubProgressMonitor(monitor, 5)));
+ }
+ return result;
+ }
+ IJavaProject[] getProjects() throws JavaModelException {
+ return getProjects(this.fResource);
+ }
+
+ public void removeCallinMarkers() throws CoreException {
+ CallinMarkerRemover.removeCallinMarkers(this.fResource);
+ }
+
+ public IJavaElement getJavaElement() {
+ return JavaCore.create(this.fResource);
+ }
+
+ public IResource getResource() {
+ return this.fResource;
+ }
+
+ boolean containsElement(IJavaElement element) {
+ return this.fResource.equals(element.getResource());
+ }
+
+ public boolean exists() {
+ if (!this.fResource.exists()) return false;
+ IJavaElement javaElement = getJavaElement();
+ do {
+ if (!javaElement.exists())
+ return false;
+ javaElement = javaElement.getParent();
+ } while (javaElement.getElementType() != IJavaElement.PACKAGE_FRAGMENT_ROOT);
+ return true;
+ }
+
+ public IMarker createMarker(String id) throws CoreException {
+ return this.fResource.createMarker(id);
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/RoleBindingChangedListener.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/RoleBindingChangedListener.java
new file mode 100644
index 0000000..016f94d
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/RoleBindingChangedListener.java
@@ -0,0 +1,153 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2005, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: RoleBindingChangedListener.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.callinmarkers;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.ElementChangedEvent;
+import org.eclipse.jdt.core.IElementChangedListener;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaElementDelta;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IParent;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.action.IStatusLineManager;
+import org.eclipse.objectteams.otdt.core.IMethodMapping;
+import org.eclipse.objectteams.otdt.core.IOTType;
+import org.eclipse.objectteams.otdt.core.IRoleType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPartSite;
+
+/**
+ * This listener receives notification of changes to any java elements.
+ * It reacts upon:
+ * <ul>
+ * <li>changes to methods inside base classes;
+ * when a bound base method is removed or added
+ * a callin marker is removed or newly created respectively.
+ * <li>changes to a role class;
+ * these trigger that callin markers for its baseclass need to be re-computed.
+ * </ul>
+ *
+ * @author brcan
+ * @version $Id: RoleBindingChangedListener.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class RoleBindingChangedListener implements IElementChangedListener
+{
+ public void elementChanged(ElementChangedEvent event)
+ {
+ updateCallinMarkers(new IJavaElementDelta[] { event.getDelta() });
+ }
+
+ private void updateCallinMarkers(IJavaElementDelta[] deltas)
+ {
+ if (deltas != null)
+ {
+// if (deltas.length > 0)
+// _CallinMarkerCreator2.reset();
+
+ for (int idx = 0; idx < deltas.length; idx++)
+ {
+ IJavaElementDelta curDelta = deltas[idx];
+
+ final IJavaElement curElem = curDelta.getElement();
+
+ // check for nested deltas
+ if (curElem instanceof IParent)
+ {
+ // visit child's deltas recursively
+ updateCallinMarkers(curDelta.getAffectedChildren());
+ }
+ // addition/removal of role types:
+ if ( curElem instanceof IType
+ && ( curDelta.getKind() == IJavaElementDelta.REMOVED
+ || curDelta.getKind() == IJavaElementDelta.ADDED
+ || curDelta.getFlags() == IJavaElementDelta.F_SUPER_TYPES))
+ {
+ IType roleType = (IType)curElem;
+ IOTType otType = OTModelManager.getOTElement(roleType);
+ if (otType != null && otType.isRole())
+ invalidateRole((IRoleType)otType, roleType);
+ }
+ // changes of base methods & fields:
+ if (curElem instanceof IMethod || curElem instanceof IField)
+ {
+ handleDeltaKind(curDelta, (IMember)curElem);
+ }
+ // any changes in method mappings:
+ if (curElem instanceof IMethodMapping) {
+ // changes in method mappings invalidate the current role's baseclass:
+ IJavaElement parent = curElem.getParent();
+ if (parent instanceof IRoleType) {
+ invalidateRole((IRoleType)parent, (IType) ((IRoleType)parent).getCorrespondingJavaElement());
+ }
+ }
+ }
+ }
+ }
+ private void invalidateRole(IRoleType otType, IType roleType) {
+ IType baseClass = null;
+ try {
+ baseClass = otType.getBaseClass();
+ } catch (JavaModelException e) {
+ /* ignore, proceed with null baseclass */
+ }
+ OTDTUIPlugin.getDefault().getCallinMarkerCreator().invalidateRole(roleType, baseClass);
+ }
+
+ private void handleDeltaKind(IJavaElementDelta delta, IMember baseMember)
+ {
+ if (delta.getKind() == IJavaElementDelta.ADDED)
+ {
+ baseMemberAdded(baseMember);
+ }
+ else if (delta.getKind() == IJavaElementDelta.REMOVED)
+ {
+ baseMemberRemoved(baseMember, baseMember.getResource());
+ }
+ }
+
+ // when renaming a method/field, we apparently get first an add-event, then a remove event.
+ private void baseMemberAdded(IMember baseMember)
+ {
+ IStatusLineManager statusLine = null;
+ IWorkbenchPage page = OTDTUIPlugin.getActivePage();
+ if (page != null && page.getActivePart() != null)
+ {
+ IWorkbenchPartSite site = page.getActivePart().getSite();
+ if (site instanceof IViewSite)
+ statusLine = ((IViewSite) site).getActionBars().getStatusLineManager();
+ }
+
+ OTDTUIPlugin.getDefault().getCallinMarkerCreator().updateCallinMarker(baseMember, statusLine);
+ }
+
+ private void baseMemberRemoved(IMember baseMember, IResource resource)
+ {
+ CallinMarkerRemover.removeCallinMarker(baseMember, resource);
+ }
+}
+
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/compare/BaseMethodCompareElement.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/compare/BaseMethodCompareElement.java
new file mode 100644
index 0000000..5c4e8ce
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/compare/BaseMethodCompareElement.java
@@ -0,0 +1,133 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2009, Stephan Herrmann 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
+ * $Id$
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Stephan Herrmann - Initial API and implementation
+ * IBM Corporation - Individual methods and code fragments.
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.compare;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.ISourceReference;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.team.internal.ui.StorageTypedElement;
+import org.eclipse.ui.IEditorInput;
+
+/**
+ * Represents the base method in a compare-bound-methods comparison.
+ * The base method may be binary, this part of the comparison will never be editable.
+ *
+ * @author stephan
+ * @since 1.4.0
+ */
+public class BaseMethodCompareElement extends StorageTypedElement
+{
+ IMethod method = null;
+
+ public BaseMethodCompareElement(IMethod method, String localEncoding) {
+ super(localEncoding);
+ this.method = method;
+ }
+ public Image getImage() {
+ return null; // never displayed in the UI
+ }
+ public String getName() {
+ return this.method.getElementName();
+ }
+ public Object getTypeName() {
+ return this.method.getDeclaringType().getElementName();
+ }
+ public String getType() {
+ // cf. RoleMethodNode#getType()
+ return "java2"; //$NON-NLS-1$
+ }
+ public IResource getResource() {
+ return this.method.getResource();
+ }
+
+ @Override
+ protected IStorage fetchContents(IProgressMonitor monitor) throws CoreException {
+ return new IStorage() {
+ public InputStream getContents() throws CoreException {
+ String contents = getExtendedSource(BaseMethodCompareElement.this.method);
+ byte[] bytes;
+ try {
+ bytes= contents.getBytes(getCharset());
+ } catch (UnsupportedEncodingException e) {
+ bytes= contents.getBytes();
+ }
+ return new ByteArrayInputStream(bytes);
+ }
+ public IPath getFullPath() {
+ return null;
+ }
+ public String getName() {
+ return method.getElementName();
+ }
+ public boolean isReadOnly() {
+ return true;
+ }
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+ };
+ }
+
+ private String getExtendedSource(IMethod method) throws JavaModelException
+ {
+ // get parent
+ IJavaElement parent= method.getParent();
+ if (parent instanceof ISourceReference) {
+ ISourceReference sr= (ISourceReference) parent;
+ String parentContent= sr.getSource();
+ if (parentContent != null) {
+ ISourceRange parentRange= sr.getSourceRange();
+ ISourceRange childRange= method.getSourceRange();
+
+ int start= childRange.getOffset() - parentRange.getOffset();
+ int end= start + childRange.getLength();
+
+ // search backwards for beginning of line
+ while (start > 0) {
+ char c= parentContent.charAt(start-1);
+ if (c == '\n' || c == '\r')
+ break;
+ start--;
+ }
+
+ return parentContent.substring(start, end);
+ }
+ }
+
+ return method.getSource();
+ }
+
+ @Override
+ protected IEditorInput getDocumentKey(Object element) {
+ return null; // base side is not editable, hence no need to make it sharable.
+ }
+
+}
\ No newline at end of file
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/compare/CompareBoundMethodsEditorInput.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/compare/CompareBoundMethodsEditorInput.java
new file mode 100644
index 0000000..11f8cc4
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/compare/CompareBoundMethodsEditorInput.java
@@ -0,0 +1,301 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2009, Stephan Herrmann 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
+ * $Id$
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Stephan Herrmann - Initial API and implementation
+ * IBM Corporation - Individual methods and code fragments.
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.compare;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.ISharedDocumentAdapter;
+import org.eclipse.compare.ITypedElement;
+import org.eclipse.compare.structuremergeviewer.Differencer;
+import org.eclipse.compare.structuremergeviewer.ICompareInput;
+import org.eclipse.compare.structuremergeviewer.IStructureComparator;
+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.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.ui.compare.JavaStructureCreator;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.objectteams.otdt.internal.ui.OTDTUIMessages;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.team.internal.ui.mapping.AbstractCompareInput;
+import org.eclipse.team.internal.ui.mapping.CompareInputChangeNotifier;
+import org.eclipse.team.internal.ui.synchronize.EditableSharedDocumentAdapter;
+import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IWorkbenchPage;
+
+/**
+ * The editor input for comparing bound methods.
+ *
+ * @author stephan
+ * @since 1.4.0
+ */
+public class CompareBoundMethodsEditorInput extends SaveableCompareEditorInput {
+
+ // editable LHS:
+ private ITypedElement left;
+ private IMethod roleMethod;
+ // readonly RHS:
+ private BaseMethodCompareElement right;
+
+ CompareInputChangeNotifier notifier = new CompareInputChangeNotifier() {
+ protected IResource[] getResources(ICompareInput input) {
+ IResource resource = getResource();
+ if (resource == null)
+ return new IResource[0];
+ return new IResource[] { resource };
+ }
+ };
+
+ EditableSharedDocumentAdapter sharedDocumentAdapter;
+
+ // hold on to a control that we want to hide:
+ private Composite outline;
+
+ class MyJavaStructureCreator extends JavaStructureCreator {
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.structuremergeviewer.StructureCreator#createStructureComparator(java.lang.Object, org.eclipse.jface.text.IDocument, org.eclipse.compare.ISharedDocumentAdapter, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected IStructureComparator createStructureComparator(Object element,
+ IDocument document,
+ ISharedDocumentAdapter sharedDocumentAdapter,
+ IProgressMonitor monitor)
+ throws CoreException
+ {
+ if (document != null)
+ return new RoleMethodNode.RootJavaNode(document, element, sharedDocumentAdapter);
+ return null;
+ }
+ }
+
+ /*
+ * Returns <code>true</code> if the other object is of type
+ * <code>CompareBoundMethodsEditorInput</code> and both of their
+ * corresponding left and right objects are identical. The content is not
+ * considered.
+ */
+ public boolean equals(Object obj) {
+ if (obj == this)
+ return true;
+ if (obj instanceof CompareBoundMethodsEditorInput) {
+ CompareBoundMethodsEditorInput other = (CompareBoundMethodsEditorInput) obj;
+ return other.left.equals(this.left)
+ && other.right.equals(this.right);
+ }
+ return false;
+ }
+
+ public class MyDiffNode extends AbstractCompareInput {
+ public MyDiffNode(ITypedElement left, ITypedElement right) {
+ super(Differencer.CHANGE, null, left, right);
+ }
+ public void fireChange() {
+ super.fireChange();
+ }
+ protected CompareInputChangeNotifier getChangeNotifier() {
+ return notifier;
+ }
+ public boolean needsUpdate() {
+ // The base never changes
+ return false;
+ }
+ public void update() {
+ fireChange();
+ }
+ }
+
+ /**
+ * Creates a new CompareBoundMethodsEditorInput.
+ * @param left
+ * @param right
+ * @param page
+ * @throws JavaModelException
+ */
+ public CompareBoundMethodsEditorInput(IMethod roleMethod, IMethod baseMethod, IWorkbenchPage page) throws CoreException {
+ super(new CompareConfiguration(), page);
+ this.roleMethod = roleMethod;
+ this.left = makeJavaNode();
+ this.right = new BaseMethodCompareElement(baseMethod, getEncoding(roleMethod));
+ setTitle(left.getName());
+ }
+
+ private ITypedElement makeJavaNode() throws CoreException
+ {
+ // this structure creator is responsible for setup of a sharedDocumentAdapter while building the root node:
+ MyJavaStructureCreator creator = new MyJavaStructureCreator();
+ IStructureComparator rootNode = creator.createStructure(this, null);
+
+ // create the detail node (role method):
+ ISourceRange sourceRange = this.roleMethod.getSourceRange();
+ return new RoleMethodNode((RoleMethodNode)rootNode, RoleMethodNode.METHOD, this.roleMethod.getElementName(), sourceRange.getOffset(), sourceRange.getLength());
+ }
+
+ private String getEncoding(IMethod method) {
+ IResource resource = method.getResource();
+ if (resource instanceof IFile) {
+ IFile file = (IFile) resource;
+ try {
+ return file.getCharset();
+ } catch (CoreException e) {
+ OTDTUIPlugin.log(e);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Control createOutlineContents(Composite parent, int direction) {
+ // hold on to a control that we want to hide:
+ return this.outline = (Composite) super.createOutlineContents(parent, direction);
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.synchronize.SaveableCompareEditorInput#prepareCompareInput(IProgressMonitor)
+ */
+ protected ICompareInput prepareCompareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ ICompareInput input = createCompareInput();
+ getCompareConfiguration().setLeftEditable(true);
+ getCompareConfiguration().setRightEditable(false);
+ ensureContentsCached(this.right, monitor);
+ initLabels(input);
+ return input;
+ }
+
+ private static void ensureContentsCached(BaseMethodCompareElement right, IProgressMonitor monitor)
+ {
+ if (right != null) {
+ try {
+ right.cacheContents(monitor);
+ } catch (CoreException e) {
+ OTDTUIPlugin.log(e);
+ }
+ }
+ }
+
+ private IResource getResource() {
+ return this.roleMethod.getResource();
+ }
+
+ private ICompareInput createCompareInput() {
+ MyDiffNode input = new MyDiffNode(this.left,this.right);
+ return input;
+ }
+
+ private void initLabels(ICompareInput input) {
+ CompareConfiguration cc = getCompareConfiguration();
+ if (this.left != null) {
+ String leftLabel = NLS.bind(OTDTUIMessages.CompareBoundMethods_role_method_label,
+ new Object[]{this.roleMethod.getDeclaringType().getElementName(), this.roleMethod.getElementName()});
+ cc.setLeftLabel(leftLabel);
+ }
+ if (this.right != null) {
+ String rightLabel = NLS.bind(OTDTUIMessages.CompareBoundMethods_base_method_label,
+ new Object[]{this.right.getTypeName(), this.right.getName()});
+ cc.setRightLabel(rightLabel);
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.CompareEditorInput#getToolTipText()
+ */
+ public String getToolTipText() {
+ Object[] titleObject = new Object[2];
+ titleObject[0] = this.left.getName();
+ titleObject[1] = this.right.getName();
+ return NLS.bind(OTDTUIMessages.CompareBoundMethods_compare_tooltip, titleObject);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.CompareEditorInput#getTitle()
+ */
+ public String getTitle() {
+ Object[] titleObject = new Object[1];
+ titleObject[0] = this.left.getName();
+ return NLS.bind(OTDTUIMessages.CompareBoundMethods_compare_title, titleObject);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.CompareEditorInput#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class adapter) {
+ if (adapter == IFile.class || adapter == IResource.class) {
+ return getResource();
+ }
+ if (adapter == ISharedDocumentAdapter.class) {
+ return getSharedDocumentAdapter();
+ }
+ return super.getAdapter(adapter);
+ }
+
+ private synchronized ISharedDocumentAdapter getSharedDocumentAdapter() {
+ if (this.sharedDocumentAdapter == null)
+ this.sharedDocumentAdapter = new EditableSharedDocumentAdapter(new EditableSharedDocumentAdapter.ISharedDocumentAdapterListener() {
+ public void handleDocumentConnected() { /* ignored */ }
+ public void handleDocumentFlushed() {
+ IEditorInput input = sharedDocumentAdapter.getDocumentKey(getResource());
+ try {
+ if (input != null)
+ sharedDocumentAdapter.saveDocument(input, true, new NullProgressMonitor());
+ } catch (CoreException e) {
+ OTDTUIPlugin.log(e);
+ }
+ }
+ public void handleDocumentDeleted() { /* ignored */ }
+ public void handleDocumentSaved() { /* ignored */ }
+ public void handleDocumentDisconnected() { /* ignored */ }
+ });
+ return this.sharedDocumentAdapter;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.synchronize.LocalResourceCompareEditorInput#fireInputChange()
+ */
+ protected void fireInputChange() {
+ ((MyDiffNode)getCompareResult()).fireChange();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.synchronize.SaveableCompareEditorInput#contentsCreated()
+ */
+ protected void contentsCreated() {
+ super.contentsCreated();
+ this.outline.setVisible(false);
+ this.notifier.initialize();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.synchronize.SaveableCompareEditorInput#handleDispose()
+ */
+ protected void handleDispose() {
+ super.handleDispose();
+ this.notifier.dispose();
+ IEditorInput input = this.sharedDocumentAdapter.getDocumentKey(getResource());
+ if (input != null)
+ this.sharedDocumentAdapter.disconnect(input);
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/compare/RoleMethodNode.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/compare/RoleMethodNode.java
new file mode 100644
index 0000000..685f787
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/compare/RoleMethodNode.java
@@ -0,0 +1,262 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2009, Stephan Herrmann 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
+ * $Id$
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Stephan Herrmann - Initial API and implementation
+ * IBM Corporation - Some individual method and fragments
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.compare;
+
+import java.io.UnsupportedEncodingException;
+
+import org.eclipse.compare.IEditableContent;
+import org.eclipse.compare.IEditableContentExtension;
+import org.eclipse.compare.IEncodedStreamContentAccessor;
+import org.eclipse.compare.ISharedDocumentAdapter;
+import org.eclipse.compare.ITypedElement;
+import org.eclipse.compare.SharedDocumentAdapter;
+import org.eclipse.compare.contentmergeviewer.IDocumentRange;
+import org.eclipse.compare.structuremergeviewer.DocumentRangeNode;
+import org.eclipse.compare.structuremergeviewer.IStructureComparator;
+import org.eclipse.compare.structuremergeviewer.SharedDocumentAdapterWrapper;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.services.IDisposable;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+
+
+/**
+ * Represents the role method of a bound-methods-comparison.
+ *
+ * This class is inspired by class org.eclipse.jdt.internal.ui.compare.JavaNode.
+ *
+ * @author stephan
+ * @since 1.4.0
+ */
+class RoleMethodNode extends DocumentRangeNode implements ITypedElement {
+
+ public static final int CU= 0;
+ public static final int METHOD= 11;
+
+ private static final String COMPILATION_UNIT = "compilationUnit"; //$NON-NLS-1$
+
+ private static final char METHOD_ID= '~';
+ private static final char COMPILATIONUNIT= '{';
+
+ static String buildID(int type, String name) {
+ StringBuffer sb= new StringBuffer();
+ switch (type) {
+ case RoleMethodNode.CU:
+ sb.append(COMPILATIONUNIT);
+ break;
+ case RoleMethodNode.METHOD:
+ sb.append(METHOD_ID);
+ sb.append(name);
+ break;
+ default:
+ Assert.isTrue(false);
+ break;
+ }
+ return sb.toString();
+ }
+
+ /**
+ * The root node of the compilation/document unit containing the role method.
+ * This node is responsible for saving the comparison.
+ */
+ static class RootJavaNode extends RoleMethodNode implements IDisposable {
+
+ private final Object fInput;
+ private final ISharedDocumentAdapter fAdapter;
+
+ RootJavaNode(IDocument document, Object input, ISharedDocumentAdapter adapter) {
+ super(document);
+ fInput= input;
+ fAdapter= adapter;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.structuremergeviewer.DocumentRangeNode#isEditable()
+ */
+ public boolean isEditable() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.structuremergeviewer.DocumentRangeNode#nodeChanged(org.eclipse.compare.structuremergeviewer.DocumentRangeNode)
+ */
+ protected void nodeChanged(DocumentRangeNode node) {
+ save(this, this.fInput);
+ }
+
+ void save(IStructureComparator node, Object input) {
+ if (node instanceof IDocumentRange && input instanceof IEditableContent) {
+ IDocument document= ((IDocumentRange)node).getDocument();
+ // First check to see if we have a shared document
+ final ISharedDocumentAdapter sda = SharedDocumentAdapterWrapper.getAdapter(input);
+ if (sda != null) {
+ IEditorInput key = sda.getDocumentKey(input);
+ if (key != null) {
+ IDocumentProvider provider = SharedDocumentAdapter.getDocumentProvider(key);
+ if (provider != null) {
+ IDocument providerDoc = provider.getDocument(key);
+ // We have to make sure that the document we are saving is the same as the shared document
+ if (providerDoc != null && providerDoc == document) {
+ if (save(provider, document, input, sda, key))
+ return;
+ }
+ }
+ }
+ }
+ IEditableContent bca= (IEditableContent) input;
+ String contents= document.get();
+ String encoding= null;
+ if (input instanceof IEncodedStreamContentAccessor) {
+ try {
+ encoding= ((IEncodedStreamContentAccessor)input).getCharset();
+ } catch (CoreException e1) {
+ // ignore
+ }
+ }
+ if (encoding == null)
+ encoding= ResourcesPlugin.getEncoding();
+ byte[] bytes;
+ try {
+ bytes= contents.getBytes(encoding);
+ } catch (UnsupportedEncodingException e) {
+ bytes= contents.getBytes();
+ }
+ bca.setContent(bytes);
+ }
+ }
+
+ boolean save(final IDocumentProvider provider, final IDocument document,
+ final Object input, final ISharedDocumentAdapter sda, final IEditorInput key) {
+ try {
+ sda.flushDocument(provider, key, document, false);
+ return true;
+ } catch (CoreException e) {
+ OTDTUIPlugin.log(e);
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.services.IDisposable#dispose()
+ */
+ public void dispose() {
+ if (fAdapter != null) {
+ fAdapter.disconnect(fInput);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.structuremergeviewer.DocumentRangeNode#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class adapter) {
+ if (adapter == ISharedDocumentAdapter.class) {
+ return fAdapter;
+ }
+ return super.getAdapter(adapter);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.structuremergeviewer.DocumentRangeNode#isReadOnly()
+ */
+ public boolean isReadOnly() {
+ if (fInput instanceof IEditableContentExtension) {
+ IEditableContentExtension ext = (IEditableContentExtension) fInput;
+ return ext.isReadOnly();
+ }
+ return super.isReadOnly();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.structuremergeviewer.DocumentRangeNode#validateEdit(org.eclipse.swt.widgets.Shell)
+ */
+ public IStatus validateEdit(Shell shell) {
+ if (fInput instanceof IEditableContentExtension) {
+ IEditableContentExtension ext = (IEditableContentExtension) fInput;
+ return ext.validateEdit(shell);
+ }
+ return super.validateEdit(shell);
+ }
+ }
+
+ /**
+ * Creates a RoleMethodNode under the given parent.
+ * @param parent the parent node
+ * @param type the Java elements type. Legal values are from the range CU to METHOD of this class.
+ * @param name the name of the Java element
+ * @param start the starting position of the java element in the underlying document
+ * @param length the number of characters of the java element in the underlying document
+ */
+ public RoleMethodNode(RoleMethodNode parent, int type, String name, int start, int length) {
+ super(parent, type, buildID(type, name), parent.getDocument(), start, length);
+ parent.addChild(this);
+ }
+
+ /**
+ * Creates a RoleMethodNode for a CU. It represents the root of a
+ * RoleMethodNode tree, so its parent is null.
+ * @param document the document which contains the Java element
+ */
+ public RoleMethodNode(IDocument document) {
+ super(CU, buildID(CU, "root"), document, 0, document.getLength()); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns a name which is presented in the UI.
+ * @see ITypedElement#getName()
+ */
+ public String getName() {
+
+ switch (getTypeCode()) {
+ case CU:
+ return COMPILATION_UNIT;
+ }
+ return getId().substring(1); // we strip away the type character
+ }
+
+ /*
+ * @see ITypedElement#getType()
+ */
+ public String getType() {
+ return "java2"; //$NON-NLS-1$
+ }
+
+ /**
+ * Returns a shared image for this Java element.
+ *
+ * see ITypedInput.getImage
+ */
+ public Image getImage() {
+ return null; // never displayed in the UI
+ }
+
+ /*
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return getType() + ": " + getName() //$NON-NLS-1$
+ + "[" + getRange().offset + "+" + getRange().length + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+}
+
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/javaeditor/OTJavaEditorMessages.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/javaeditor/OTJavaEditorMessages.java
new file mode 100644
index 0000000..9a2a0be
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/javaeditor/OTJavaEditorMessages.java
@@ -0,0 +1,41 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2006 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: OTJavaEditorMessages.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.javaeditor;
+
+import org.eclipse.osgi.util.NLS;;
+
+public class OTJavaEditorMessages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.objectteams.otdt.internal.ui.javaeditor.OTJavaEditorMessages"; //$NON-NLS-1$
+
+ public static String RoleOverrideIndicator_open_error_message;
+ public static String RoleOverrideIndicator_open_error_messageHasLogEntry;
+ public static String RoleOverrideIndicator_open_error_title;
+ public static String RoleOverrideIndicator_overrides;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, OTJavaEditorMessages.class);
+ }
+
+ private OTJavaEditorMessages() {
+ }
+
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/javaeditor/OTJavaEditorMessages.properties b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/javaeditor/OTJavaEditorMessages.properties
new file mode 100644
index 0000000..d6ba860
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/javaeditor/OTJavaEditorMessages.properties
@@ -0,0 +1,4 @@
+RoleOverrideIndicator_open_error_message= Could not open the super implementation.
+RoleOverrideIndicator_open_error_messageHasLogEntry= Could not open the super implementation.\nSee the error log for details.
+RoleOverrideIndicator_open_error_title= Open Declaring Role Class
+RoleOverrideIndicator_overrides= overrides {0}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/javaeditor/RoleOverrideIndicatorManager.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/javaeditor/RoleOverrideIndicatorManager.java
new file mode 100644
index 0000000..49e0214
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/javaeditor/RoleOverrideIndicatorManager.java
@@ -0,0 +1,239 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2010 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
+ * $Id$
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.javaeditor;
+
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.ITypeRoot;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.RoleTypeDeclaration;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaSelectAnnotationRulerAction;
+import org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener;
+import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
+import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jdt.ui.SharedASTProvider;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.text.ISynchronizable;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.IAnnotationModelExtension;
+
+/**
+ * Manages the override indicators for the given Java element and annotation model.
+ *
+ * Copied from {@link org.eclipse.jdt.internal.ui.javaeditor.OverrideIndicatorManager} and slightly adjusted.
+ *
+ * Note that inaccessible features preclude that this class were directly integrated into
+ * {@link JavaSelectAnnotationRulerAction}, which is why the jdt.ui.adaptor has to
+ * help (see {@link org.eclipse.objectteams.otdt.internal.ui.javaeditor.AnnotationAdaptor}).
+ *
+ * @author stephan
+ * @since 1.2.8
+ */
+public class RoleOverrideIndicatorManager implements IJavaReconcilingListener {
+
+ /**
+ * Role class override indicator annotation.
+ */
+ public class OverrideIndicator extends Annotation {
+
+ private String fAstNodeKey;
+
+ /**
+ * Creates a new override annotation.
+ *
+ * @param text the text associated with this annotation
+ * @param key the type binding key
+ */
+ OverrideIndicator(String text, String key) {
+ super(ANNOTATION_TYPE, false, text);
+ fAstNodeKey= key;
+ }
+
+ /**
+ * Opens and reveals the defining role (closest tsuper).
+ */
+ public void open() {
+ CompilationUnit ast= SharedASTProvider.getAST(fJavaElement, SharedASTProvider.WAIT_ACTIVE_ONLY, null);
+ if (ast != null) {
+ ASTNode node= ast.findDeclaringNode(fAstNodeKey);
+//{ObjectTeams: specific search strategy for a role's tsupers:
+ if (node instanceof TypeDeclaration) {
+ try {
+ ITypeBinding typeBinding = ((TypeDeclaration)node).resolveBinding();
+ ITypeBinding[] tsuperRoles = typeBinding.getSuperRoles();
+ if (tsuperRoles != null && tsuperRoles.length > 0) {
+ IJavaElement definingRole = tsuperRoles[0].getJavaElement();
+ if (definingRole!= null) {
+// SH}
+ JavaUI.openInEditor(definingRole, true, true);
+ return;
+ }
+ }
+ } catch (CoreException e) {
+ ExceptionHandler.handle(e, OTJavaEditorMessages.RoleOverrideIndicator_open_error_title, OTJavaEditorMessages.RoleOverrideIndicator_open_error_messageHasLogEntry);
+ return;
+ }
+ }
+ }
+ String title= OTJavaEditorMessages.RoleOverrideIndicator_open_error_title;
+ String message= OTJavaEditorMessages.RoleOverrideIndicator_open_error_message;
+ MessageDialog.openError(JavaPlugin.getActiveWorkbenchShell(), title, message);
+ }
+ }
+
+ static final String ANNOTATION_TYPE= "org.eclipse.objectteams.otdt.ui.roleOverrideIndicator"; //$NON-NLS-1$
+
+ private IAnnotationModel fAnnotationModel;
+ private Object fAnnotationModelLockObject;
+ private Annotation[] fOverrideAnnotations;
+ private ITypeRoot fJavaElement;
+
+
+ public RoleOverrideIndicatorManager(IAnnotationModel annotationModel, ITypeRoot javaElement, CompilationUnit ast) {
+ Assert.isNotNull(annotationModel);
+ Assert.isNotNull(javaElement);
+
+ fJavaElement= javaElement;
+ fAnnotationModel=annotationModel;
+ fAnnotationModelLockObject= getLockObject(fAnnotationModel);
+
+ updateAnnotations(ast, new NullProgressMonitor());
+ }
+
+ /**
+ * Returns the lock object for the given annotation model.
+ *
+ * @param annotationModel the annotation model
+ * @return the annotation model's lock object
+ */
+ private Object getLockObject(IAnnotationModel annotationModel) {
+ if (annotationModel instanceof ISynchronizable) {
+ Object lock= ((ISynchronizable)annotationModel).getLockObject();
+ if (lock != null)
+ return lock;
+ }
+ return annotationModel;
+ }
+
+ /**
+ * Updates the override annotations based on the given AST.
+ *
+ * @param ast the compilation unit AST
+ * @param progressMonitor the progress monitor
+ */
+ protected void updateAnnotations(CompilationUnit ast, IProgressMonitor progressMonitor) {
+
+ if (ast == null || progressMonitor.isCanceled())
+ return;
+
+ final Map<OverrideIndicator, Position> annotationMap= new HashMap<OverrideIndicator, Position>(10);
+
+ ast.accept(new ASTVisitor(false) {
+ /*
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.RoleTypeDeclaration)
+ */
+ public boolean visit(RoleTypeDeclaration node) {
+ ITypeBinding binding= node.resolveBinding();
+ if (binding != null) {
+//{ObjectTeams: different search for super implementation:
+ ITypeBinding[] definingRoles= binding.getSuperRoles();
+ if (definingRoles != null && definingRoles.length > 0) {
+ ITypeBinding definingRole = definingRoles[0];
+// SH}
+ ITypeBinding definingType= definingRole.getDeclaringClass();
+ String qualifiedRoleName= definingType.getQualifiedName() + "." + binding.getName(); //$NON-NLS-1$
+
+ String text= MessageFormat.format(OTJavaEditorMessages.RoleOverrideIndicator_overrides, new Object[] {BasicElementLabels.getJavaElementName(qualifiedRoleName)});
+
+ SimpleName name= node.getName();
+ Position position= new Position(name.getStartPosition(), name.getLength());
+
+ annotationMap.put(new OverrideIndicator(text, binding.getKey()), position);
+ }
+ }
+ return true;
+ }
+ });
+
+ if (progressMonitor.isCanceled())
+ return;
+
+ synchronized (fAnnotationModelLockObject) {
+ if (fAnnotationModel instanceof IAnnotationModelExtension) {
+ ((IAnnotationModelExtension)fAnnotationModel).replaceAnnotations(fOverrideAnnotations, annotationMap);
+ } else {
+ removeAnnotations();
+ Iterator<Map.Entry<OverrideIndicator, Position>> iter= annotationMap.entrySet().iterator();
+ while (iter.hasNext()) {
+ Map.Entry<OverrideIndicator, Position> mapEntry= iter.next();
+ fAnnotationModel.addAnnotation(mapEntry.getKey(), mapEntry.getValue());
+ }
+ }
+ fOverrideAnnotations= annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
+ }
+ }
+
+ /**
+ * Removes all override indicators from this manager's annotation model.
+ */
+ //FIXME: made public to workaround IllegalAccessError with split package access
+ // from bundle org.eclipse.objectteams.otdt.jdt.ui(x-friends not working)
+ public void removeAnnotations() {
+ if (fOverrideAnnotations == null)
+ return;
+
+ synchronized (fAnnotationModelLockObject) {
+ if (fAnnotationModel instanceof IAnnotationModelExtension) {
+ ((IAnnotationModelExtension)fAnnotationModel).replaceAnnotations(fOverrideAnnotations, null);
+ } else {
+ for (int i= 0, length= fOverrideAnnotations.length; i < length; i++)
+ fAnnotationModel.removeAnnotation(fOverrideAnnotations[i]);
+ }
+ fOverrideAnnotations= null;
+ }
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#aboutToBeReconciled()
+ */
+ public void aboutToBeReconciled() {
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#reconciled(CompilationUnit, boolean, IProgressMonitor)
+ */
+ public void reconciled(CompilationUnit ast, boolean forced, IProgressMonitor progressMonitor) {
+ updateAnnotations(ast, progressMonitor);
+ }
+}
+
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/CompilerConfigurationBlock.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/CompilerConfigurationBlock.java
new file mode 100644
index 0000000..f7f3c48
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/CompilerConfigurationBlock.java
@@ -0,0 +1,382 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2005, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: CompilerConfigurationBlock.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.preferences;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock;
+import org.eclipse.jdt.internal.ui.preferences.PreferencesMessages;
+import org.eclipse.jdt.internal.ui.preferences.ScrolledPageContent;
+import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
+import org.eclipse.jface.dialogs.ControlEnableState;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.objectteams.otdt.core.ext.OTDTPlugin;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+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.ui.forms.widgets.ExpandableComposite;
+import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
+
+/**
+ * Partly copied from org.eclipse.jdt.internal.ui.preferences.CompilerConfigurationBlock.
+ *
+ * This class defines all configurable options of the OT/J compiler.
+ * + private static final Key PREF_PB_
+ * also add in getKeys()
+ * + createCompilerPreferenceTabContent() -> create label
+ * -> use OTPreferencesMessages
+ *
+ * Other classes/methods involved are (Problem reporting):
+ * + CompilerOptions:
+ * - constant "String OPTION_ReportXxx"
+ * - constant "long Xxx" bit for use in mask
+ * - default "warningThreshold": include Xxx-bit if appropriate
+ * - getMap(): transfer severity (bitset) to optionsMap
+ * - set(Map): transfer from optionsMap to severity (bitset)
+ * - toString()
+ * + ProblemReporter
+ * - getIrritant: map problemId (from IProblem) to irritant (=option)
+ * - individual report-methods: don't hardcode severity!
+ * + DefaultCodeFormatter.getDefaultCompilerOptions()
+ *
+ * Integration into the plugin:
+ * + OTDTPlugin.OT_COMPILER_XXX: constants for configurable options (sync with OPTION_ReportXxx)
+ * + OTCompilerPreferencePage
+ * (basically unchanged except for reference to CompilerConfigurationBlock and one ID)
+ * + plugin.xml:
+ * define preference/property-page extensions
+ *
+ * For enable/disable options these differences apply:
+ * + CompilerOptions:
+ * - no longs/masks but a boolean field
+ *
+ * Created on Sep 11, 2005
+ *
+ * @author stephan
+ * @version $Id: CompilerConfigurationBlock.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class CompilerConfigurationBlock extends OptionsConfigurationBlock {
+
+ // Preference store keys, see JavaCore.getOptions
+ /* Note(SH):
+ * We must use the JDTCoreKeys in order to store our preferences in the same preference store (and thus file).
+ * Only keys from this store will be passed to the compiler
+ */
+
+ // proplem severities:
+ private static final Key PREF_PB_BASECALL = getJDTCoreKey(OTDTPlugin.OT_COMPILER_BASE_CALL);
+ private static final Key PREF_PB_UNSAFE_ROLE_INSTANTIATION = getJDTCoreKey(OTDTPlugin.OT_COMPILER_UNSAFE_ROLE_INSTANTIATION);
+
+// private static final Key PREF_PB_EFFECTLESS_FIELDACCESS = getJDTCoreKey(OTDTPlugin.OT_COMPILER_EFFECTLESS_FIELDACCESS);
+ private static final Key PREF_PB_FRAGILE_CALLIN = getJDTCoreKey(OTDTPlugin.OT_COMPILER_FRAGILE_CALLIN);
+// private static final Key PREF_PB_UNUSED_PARAMMAP = getJDTCoreKey(OTDTPlugin.OT_COMPILER_UNUSED_PARAMMAP);
+
+ private static final Key PREF_PB_POTENTIAL_AMBIGUOUS_PLAYEDBY = getJDTCoreKey(OTDTPlugin.OT_COMPILER_POTENTIAL_AMBIGUOUS_PLAYEDBY);
+ private static final Key PREF_PB_ABSTRACT_POTENTIAL_RELEVANT_ROLE = getJDTCoreKey(OTDTPlugin.OT_COMPILER_ABSTRACT_POTENTIAL_RELEVANT_ROLE);
+
+ private static final Key PREF_PB_DECAPSULATION = getJDTCoreKey(OTDTPlugin.OT_COMPILER_DECAPSULATION);
+
+ private static final Key PREF_PB_DEPRECATED_PATH_SYNTAX = getJDTCoreKey(OTDTPlugin.OT_COMPILER_DEPRECATED_PATH_SYNTAX);
+
+ private static final Key PREF_PB_BINDING_CONVENTIONS = getJDTCoreKey(OTDTPlugin.OT_COMPILER_BINDING_CONVENTIONS);
+
+ private static final Key PREF_PB_INFERRED_CALLOUT = getJDTCoreKey(OTDTPlugin.OT_COMPILER_INFERRED_CALLOUT);
+
+ private static final Key PREF_PB_WEAVE_INTO_SYSTEM_CLASS = getJDTCoreKey(OTDTPlugin.OT_COMPILER_WEAVE_INTO_SYSTEM_CLASS);
+
+ private static final Key PREF_PB_OVERRIDE_FINAL_ROLE = getJDTCoreKey(OTDTPlugin.OT_COMPILER_OVERRIDE_FINAL_ROLE);
+
+ private static final Key PREF_PB_EXCEPTION_IN_GUARD = getJDTCoreKey(OTDTPlugin.OT_COMPILER_EXCEPTION_IN_GUARD);
+
+ private static final Key PREF_PB_AMBIGUOUS_LOWERING = getJDTCoreKey(OTDTPlugin.OT_COMPILER_AMBIGUOUS_LOWERING);
+
+ private static final Key PREF_PB_ADAPTING_DEPRECATED = getJDTCoreKey(OTDTPlugin.OT_COMPILER_ADAPTING_DEPRECATED);
+
+// private static final Key PREF_PB_INCOMPLETE_BUILD = getJDTCoreKey(OTDTPlugin.OT_COMPILER_INCOMPLETE_BUILD);
+
+ // feature enablement:
+ private static final Key PREF_OPT_SCOPED_KEYWORDS = getJDTCoreKey(OTDTPlugin.OT_COMPILER_SCOPED_KEYWORDS);
+
+ // values
+ private static final String ERROR= JavaCore.ERROR;
+ private static final String WARNING= JavaCore.WARNING;
+ private static final String IGNORE= JavaCore.IGNORE;
+
+ private static final String ENABLED= JavaCore.ENABLED;
+ private static final String DISABLED= JavaCore.DISABLED;
+
+ private static final String SETTINGS_SECTION_NAME = null; // ?? see ProblemSeveritiesConfigurationBlock
+
+ // would be needed if some controls are enabled/disabled programmatically:
+ // private IStatus fComplianceStatus;
+ // private ArrayList fComplianceControls;
+ private Composite fControlsComposite;
+ private ControlEnableState fBlockEnableState;
+
+ public CompilerConfigurationBlock(IStatusChangeListener context, IProject project, IWorkbenchPreferenceContainer container) {
+ super(context, project, getKeys(), container);
+
+ fBlockEnableState= null;
+ // currently unused:
+ //fComplianceControls= new ArrayList();
+ //ComplianceStatus= new StatusInfo();
+
+ }
+
+ private static Key[] getKeys() {
+ return new Key[] {
+ PREF_PB_BASECALL, PREF_PB_UNSAFE_ROLE_INSTANTIATION,
+// PREF_PB_EFFECTLESS_FIELDACCESS,
+ PREF_PB_FRAGILE_CALLIN,
+// PREF_PB_UNUSED_PARAMMAP,
+ PREF_PB_POTENTIAL_AMBIGUOUS_PLAYEDBY, PREF_PB_ABSTRACT_POTENTIAL_RELEVANT_ROLE,
+ PREF_PB_DECAPSULATION,
+ PREF_PB_BINDING_CONVENTIONS,
+ PREF_PB_DEPRECATED_PATH_SYNTAX,
+ PREF_PB_INFERRED_CALLOUT,
+ PREF_PB_ADAPTING_DEPRECATED,
+ PREF_PB_WEAVE_INTO_SYSTEM_CLASS,
+ PREF_PB_OVERRIDE_FINAL_ROLE,
+ PREF_PB_EXCEPTION_IN_GUARD,
+ PREF_PB_AMBIGUOUS_LOWERING,
+// PREF_PB_INCOMPLETE_BUILD,
+ PREF_OPT_SCOPED_KEYWORDS
+ };
+ }
+
+ /*
+ * @see org.eclipse.jface.preference.PreferencePage#createContents(Composite)
+ */
+ protected Control createContents(Composite parent) {
+ setShell(parent.getShell());
+
+ Composite complianceComposite= createCompilerPreferenceTabContent(parent);
+
+ validateSettings(null, null, null);
+
+ return complianceComposite;
+ }
+
+ public void enablePreferenceContent(boolean enable) {
+ if (fControlsComposite != null && !fControlsComposite.isDisposed()) {
+ if (enable) {
+ if (fBlockEnableState != null) {
+ fBlockEnableState.restore();
+ fBlockEnableState= null;
+ }
+ } else {
+ if (fBlockEnableState == null) {
+ fBlockEnableState= ControlEnableState.disable(fControlsComposite);
+ }
+ }
+ }
+ }
+
+
+ private Composite createCompilerPreferenceTabContent(Composite folder) {
+ String[] errorWarningIgnore= new String[] { ERROR, WARNING, IGNORE };
+
+ String[] errorWarningIgnoreLabels= new String[] {
+ PreferencesMessages.ProblemSeveritiesConfigurationBlock_error,
+ PreferencesMessages.ProblemSeveritiesConfigurationBlock_warning,
+ PreferencesMessages.ProblemSeveritiesConfigurationBlock_ignore
+ };
+
+ String[] enabledDisabled= new String[] { ENABLED, DISABLED };
+
+
+ // widget layout mainly copied from ProblemSeveritiesConfigurationBlock:
+ int nColumns= 3;
+ final ScrolledPageContent sc1 = new ScrolledPageContent(folder);
+
+ Composite composite= sc1.getBody();
+ GridLayout layout= new GridLayout(nColumns, false);
+ layout.marginHeight= 0;
+ layout.marginWidth= 0;
+ composite.setLayout(layout);
+
+ Label description= new Label(composite, SWT.LEFT | SWT.WRAP);
+ description.setFont(description.getFont());
+ description.setText(OTPreferencesMessages.OTCompilerConfiguration_common_description);
+ description.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false, nColumns - 1, 1));
+
+ Composite inner;
+ String label;
+
+ // --- Problem configuration ---
+ inner = myCreateSection(nColumns, composite, OTPreferencesMessages.OTCompilerProblemConfiguration_description);
+
+ label= OTPreferencesMessages.OTCompilerProblemConfiguration_otjld_ref_description;
+ addLabel(inner, nColumns, label, SWT.ITALIC);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_not_exactly_one_basecall_label;
+ addComboBox(inner, label, PREF_PB_BASECALL, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_unsafe_role_instantiation_label;
+ addComboBox(inner, label, PREF_PB_UNSAFE_ROLE_INSTANTIATION, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+// label= OTPreferencesMessages.OTCompilerConfigurationBlock_effectless_fieldaccess_label;
+// addComboBox(inner, label, PREF_PB_EFFECTLESS_FIELDACCESS, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_fragile_callin_label;
+ addComboBox(inner, label, PREF_PB_FRAGILE_CALLIN, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+// label= OTPreferencesMessages.OTCompilerConfigurationBlock_unused_parammap_label;
+// addComboBox(inner, label, PREF_PB_UNUSED_PARAMMAP, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_potential_ambiguous_playedby_label;
+ addComboBox(inner, label, PREF_PB_POTENTIAL_AMBIGUOUS_PLAYEDBY, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_ambiguous_lowering_label;
+ addComboBox(inner, label, PREF_PB_AMBIGUOUS_LOWERING, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_abstract_potential_relevant_role_label;
+ addComboBox(inner, label, PREF_PB_ABSTRACT_POTENTIAL_RELEVANT_ROLE, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_decapsulation_label;
+ addComboBox(inner, label, PREF_PB_DECAPSULATION, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_bindingconventions_label;
+ addComboBox(inner, label, PREF_PB_BINDING_CONVENTIONS, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_deprecated_path_syntax_label;
+ addComboBox(inner, label, PREF_PB_DEPRECATED_PATH_SYNTAX, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_inferred_callout_label;
+ addComboBox(inner, label, PREF_PB_INFERRED_CALLOUT, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_adapting_deprecated_label;
+ addComboBox(inner, label, PREF_PB_ADAPTING_DEPRECATED, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_binding_to_system_class;
+ addComboBox(inner, label, PREF_PB_WEAVE_INTO_SYSTEM_CLASS, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_override_final_role;
+ addComboBox(inner, label, PREF_PB_OVERRIDE_FINAL_ROLE, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_exception_in_guard;
+ addComboBox(inner, label, PREF_PB_EXCEPTION_IN_GUARD, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+// label= OTPreferencesMessages.OTCompilerConfigurationBlock_incomplete_build_label;
+// addComboBox(inner, label, PREF_PB_INCOMPLETE_BUILD, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ // ---- Feature enablement ----
+ inner = myCreateSection(nColumns, composite, OTPreferencesMessages.OTCompilerFeatureEnablement_description);
+
+ label= OTPreferencesMessages.OTCompilerConfigurationBlock_opt_scoped_keywords;
+ addCheckBox(inner, label, PREF_OPT_SCOPED_KEYWORDS, enabledDisabled, 0);
+
+ // not sure whether this works
+ IDialogSettings section= JavaPlugin.getDefault().getDialogSettings().getSection(SETTINGS_SECTION_NAME);
+ restoreSectionExpansionStates(section);
+
+ // store in this field in order to support enabling/disabling via enablePreferenceContent()
+ fControlsComposite = composite;
+ return composite;
+ }
+
+ private Composite myCreateSection(int nColumns, Composite composite, String label) {
+ ExpandableComposite excomposite = createStyleSection(composite, label, nColumns);
+ Composite inner= new Composite(excomposite, SWT.NONE);
+ inner.setFont(composite.getFont());
+ inner.setLayout(new GridLayout(nColumns, false));
+ excomposite.setClient(inner);
+ return inner;
+ }
+
+ private void addLabel(Composite composite, int nColumns, String descriptionText, int fontStyle)
+ {
+ Label description= new Label(composite, SWT.WRAP);
+ description.setText(descriptionText);
+ if (fontStyle != SWT.NORMAL) {
+ Font f = composite.getFont();
+ FontData[] datas = f.getFontData();
+ datas[0].setStyle(fontStyle);
+ description.setFont(new Font(f.getDevice(), datas[0]));
+ }
+ GridData gd= new GridData();
+ gd.horizontalSpan= nColumns;
+ //gd.widthHint= fPixelConverter.convertWidthInCharsToPixels(60);
+ description.setLayoutData(gd);
+ }
+
+ /* (non-javadoc)
+ * Update fields and validate.
+ * @param changedKey Key that changed, or null, if all changed.
+ */
+ protected void validateSettings(Key changedKey, String olValue, String newValue) {
+
+ if (changedKey != null) {
+ if (PREF_PB_BASECALL.equals(changedKey) || PREF_PB_DECAPSULATION.equals(changedKey))
+ {
+ // not yet used really.
+ updateEnableStates();
+ } else {
+ return;
+ }
+ } else {
+ updateEnableStates();
+ }
+ }
+
+
+ private void updateEnableStates() {
+ // TODO(SH): enable check boxes for details:
+// boolean enableBasecall = !checkValue(PREF_PB_BASECALL, IGNORE);
+// getCheckBox(PREF_PB_DEPRECATION_IN_DEPRECATED_CODE).setEnabled(enableDeprecation);
+// getCheckBox(PREF_PB_DEPRECATION_WHEN_OVERRIDING).setEnabled(enableDeprecation);
+
+ // TODO(SH): enable check boxes for details:
+// boolean enableDecapsulation = !checkValue(PREF_PB_DECAPSULATION, IGNORE);
+// getCheckBox(PREF_PB_DEPRECATION_IN_DEPRECATED_CODE).setEnabled(enableDeprecation);
+// getCheckBox(PREF_PB_DEPRECATION_WHEN_OVERRIDING).setEnabled(enableDeprecation);
+
+ }
+
+
+ protected String[] getFullBuildDialogStrings(boolean workspaceSettings) {
+ String title= PreferencesMessages.ComplianceConfigurationBlock_needsbuild_title;
+
+ String message;
+ if (workspaceSettings) {
+ message= PreferencesMessages.ComplianceConfigurationBlock_needsfullbuild_message;
+ } else {
+ message= PreferencesMessages.ComplianceConfigurationBlock_needsprojectbuild_message;
+ }
+ return new String[] { title, message };
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#dispose()
+ */
+ public void dispose() {
+ IDialogSettings section= JavaPlugin.getDefault().getDialogSettings().addNewSection(SETTINGS_SECTION_NAME);
+ storeSectionExpansionStates(section);
+ super.dispose();
+ }
+
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/GeneralPreferences.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/GeneralPreferences.java
new file mode 100644
index 0000000..10fd6f9
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/GeneralPreferences.java
@@ -0,0 +1,37 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2008 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: GeneralPreferences.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.preferences;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+
+/**
+ * @author gis
+ */
+public class GeneralPreferences
+{
+ public static String CALLIN_MARKER_ENABLED_BOOL = "prefs.ot.callinmarker.enabled"; //$NON-NLS-1$
+
+//TODO (haebor): use mechanisms that are defined by DefaultPreferences
+ public static void initDefaults(IPreferenceStore prefs)
+ {
+ prefs.setDefault(CALLIN_MARKER_ENABLED_BOOL, true);
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/OTCompilerPreferencePage.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/OTCompilerPreferencePage.java
new file mode 100644
index 0000000..5877523
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/OTCompilerPreferencePage.java
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * 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
+ * $Id: OTCompilerPreferencePage.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Fraunhofer FIRST - extended API and implementation
+ * Technical University Berlin - extended API and implementation
+ *******************************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.preferences;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IAdaptable;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
+
+import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+
+import org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage;
+
+/**
+ * OT_COPY_PASTE
+ * The page to configure the compiler options.
+ * Copied from org.eclipse.jdt.internal.ui.preferences.CompliancePreferencePage
+ *
+ * This page is used by "Window->Preferences->Java->Compiler (OT/J)"
+ *
+ * Created on Sep 11, 2005
+ *
+ * @author stephan
+ */
+public class OTCompilerPreferencePage extends PropertyAndPreferencePage {
+
+ // sync with ids in plugin.xml:
+ // id of the page in the org.eclipse.ui.preferencePages extension
+ public static final String PREF_ID= "org.eclipse.objectteams.otdt.ui.preferences.CompilerPreferencePage"; //$NON-NLS-1$
+ // id of the pages in the org.eclipse.ui.propertyPages extension
+ public static final String PROP_ID= "org.eclipse.objectteams.otdt.ui.propertyPages.CompilerPreferencePage"; //$NON-NLS-1$
+
+ private CompilerConfigurationBlock fConfigurationBlock;
+
+ public OTCompilerPreferencePage() {
+ setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore());
+ // only shown on the preference page:
+ //setDescription(OTPreferencesMessages.CompilerConfigurationBlock_common_description);
+
+ // only used when page is shown programatically
+ setTitle(OTPreferencesMessages.OTCompilerPreferencePage_title);
+ }
+
+ /*
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+ IWorkbenchPreferenceContainer container= (IWorkbenchPreferenceContainer) getContainer();
+ fConfigurationBlock= new CompilerConfigurationBlock(getNewStatusChangedListener(), getProject(), container);
+
+ super.createControl(parent);
+
+ // TODO(SH): do we have more appropriate help?
+ if (isProjectPreferencePage()) {
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.COMPILER_PROPERTY_PAGE);
+ } else {
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.COMPILER_PREFERENCE_PAGE);
+ }
+ }
+
+ protected Control createPreferenceContent(Composite composite) {
+ return fConfigurationBlock.createContents(composite);
+ }
+
+ protected boolean hasProjectSpecificOptions(IProject project) {
+ return fConfigurationBlock.hasProjectSpecificOptions(project);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#getPreferencePageID()
+ */
+ protected String getPreferencePageID() {
+ return PREF_ID;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#getPropertyPageID()
+ */
+ protected String getPropertyPageID() {
+ return PROP_ID;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.DialogPage#dispose()
+ */
+ public void dispose() {
+ if (fConfigurationBlock != null) {
+ fConfigurationBlock.dispose();
+ }
+ super.dispose();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#enableProjectSpecificSettings(boolean)
+ */
+ protected void enableProjectSpecificSettings(boolean useProjectSpecificSettings) {
+ super.enableProjectSpecificSettings(useProjectSpecificSettings);
+ if (fConfigurationBlock != null) {
+ fConfigurationBlock.useProjectSpecificSettings(useProjectSpecificSettings);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#enablePreferenceContent(boolean)
+ */
+ protected void enablePreferenceContent(boolean enable) {
+ if (fConfigurationBlock != null) {
+ fConfigurationBlock.enablePreferenceContent(enable);
+ }
+ }
+
+ /*
+ * @see org.eclipse.jface.preference.IPreferencePage#performDefaults()
+ */
+ protected void performDefaults() {
+ super.performDefaults();
+ if (fConfigurationBlock != null) {
+ fConfigurationBlock.performDefaults();
+ }
+ }
+
+ /*
+ * @see org.eclipse.jface.preference.IPreferencePage#performOk()
+ */
+ public boolean performOk() {
+ if (fConfigurationBlock != null && !fConfigurationBlock.performOk()) {
+ return false;
+ }
+ return super.performOk();
+ }
+
+ /*
+ * @see org.eclipse.jface.preference.IPreferencePage#performApply()
+ */
+ public void performApply() {
+ if (fConfigurationBlock != null) {
+ fConfigurationBlock.performApply();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#setElement(org.eclipse.core.runtime.IAdaptable)
+ */
+ public void setElement(IAdaptable element) {
+ super.setElement(element);
+ setDescription(null); // no description for property page
+ }
+
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/OTGeneralPreferencePage.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/OTGeneralPreferencePage.java
new file mode 100644
index 0000000..3908971
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/OTGeneralPreferencePage.java
@@ -0,0 +1,99 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2008 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: OTGeneralPreferencePage.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.preferences;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.swt.SWT;
+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.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * @author gis
+ */
+public class OTGeneralPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
+{
+ private Button _callinMarkerButton;
+
+ public OTGeneralPreferencePage()
+ {
+ super(OTPreferencesMessages.preferences_general_title);
+ }
+
+ protected IPreferenceStore doGetPreferenceStore()
+ {
+ return OTDTUIPlugin.getDefault().getPreferenceStore();
+ }
+
+ protected Control createContents(Composite parent)
+ {
+ Composite result = new Composite(parent, SWT.NULL);
+ result.setLayout(new GridLayout(2, false));
+
+ _callinMarkerButton = new Button(result, SWT.CHECK);
+ _callinMarkerButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ _callinMarkerButton.setText(OTPreferencesMessages.preferences_general_callinmarker_label);
+
+ // km: (TPX-432) read and set values before any eventhandler is registered
+ initValues();
+
+ return result;
+ }
+
+ protected void initValues()
+ {
+ IPreferenceStore prefs = getPreferenceStore();
+ _callinMarkerButton.setSelection(prefs.getBoolean(GeneralPreferences.CALLIN_MARKER_ENABLED_BOOL));
+ }
+
+ protected void initDefaults()
+ {
+ IPreferenceStore prefs = getPreferenceStore();
+ _callinMarkerButton.setSelection(prefs.getDefaultBoolean(GeneralPreferences.CALLIN_MARKER_ENABLED_BOOL));
+ }
+
+ @Override
+ public boolean performOk()
+ {
+ IPreferenceStore prefs = getPreferenceStore();
+ prefs.setValue(GeneralPreferences.CALLIN_MARKER_ENABLED_BOOL, _callinMarkerButton.getSelection());
+ return true;
+ }
+
+ protected void performDefaults()
+ {
+ IPreferenceStore prefs = getPreferenceStore();
+ GeneralPreferences.initDefaults(prefs);
+ initDefaults();
+
+ super.performDefaults();
+ }
+
+ public void init(IWorkbench workbench) {
+ // nothing to do
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/OTPreferencesMessages.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/OTPreferencesMessages.java
new file mode 100644
index 0000000..3bed612
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/OTPreferencesMessages.java
@@ -0,0 +1,78 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2005, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: OTPreferencesMessages.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.preferences;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * This class integrates OT-specific messages for the property/preference pages
+ * with those provided by the JDT (OT-specific messages have precedence).
+ *
+ * Created on Sep 11, 2005
+ *
+ * @author stephan
+ * @version $Id: OTPreferencesMessages.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class OTPreferencesMessages {
+
+ private static final String BUNDLE_NAME= "org.eclipse.objectteams.otdt.internal.ui.preferences.OTPreferencesMessages";//$NON-NLS-1$
+
+
+ private OTPreferencesMessages() {
+ }
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, OTPreferencesMessages.class);
+ }
+
+ public static String OTCompilerPreferencePageName;
+ public static String OTCompilerPropertyPageName;
+
+ public static String OTCompilerPreferencePage_title;
+
+ public static String OTCompilerConfiguration_common_description;
+ public static String OTCompilerProblemConfiguration_description;
+ public static String OTCompilerProblemConfiguration_otjld_ref_description;
+ public static String OTCompilerFeatureEnablement_description;
+
+ public static String OTCompilerConfigurationBlock_not_exactly_one_basecall_label;
+ public static String OTCompilerConfigurationBlock_unsafe_role_instantiation_label;
+ public static String OTCompilerConfigurationBlock_effectless_fieldaccess_label;
+ public static String OTCompilerConfigurationBlock_fragile_callin_label;
+ public static String OTCompilerConfigurationBlock_unused_parammap_label;
+ public static String OTCompilerConfigurationBlock_potential_ambiguous_playedby_label;
+ public static String OTCompilerConfigurationBlock_ambiguous_lowering_label;
+ public static String OTCompilerConfigurationBlock_abstract_potential_relevant_role_label;
+ public static String OTCompilerConfigurationBlock_decapsulation_label;
+ public static String OTCompilerConfigurationBlock_bindingconventions_label;
+ public static String OTCompilerConfigurationBlock_deprecated_path_syntax_label;
+ public static String OTCompilerConfigurationBlock_inferred_callout_label;
+ public static String OTCompilerConfigurationBlock_adapting_deprecated_label;
+ public static String OTCompilerConfigurationBlock_incomplete_build_label;
+ public static String OTCompilerConfigurationBlock_binding_to_system_class;
+ public static String OTCompilerConfigurationBlock_override_final_role;
+ public static String OTCompilerConfigurationBlock_exception_in_guard;
+ public static String OTCompilerConfigurationBlock_opt_scoped_keywords;
+
+ public static String preferences_general_title;
+ public static String preferences_general_callinmarker_label;
+ public static String preferences_general_debugfilters_label;
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/OTPreferencesMessages.properties b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/OTPreferencesMessages.properties
new file mode 100644
index 0000000..fdf21d1
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/preferences/OTPreferencesMessages.properties
@@ -0,0 +1,52 @@
+##########################################################################
+# This file is part of "Obect Teams Development Tooling"-Software.
+#-------------------------------------------------------------------------
+# Messages for configurable compiler options
+#
+# Author: Stephan Herrmann
+##########################################################################
+# the following two names resemble the original JDT-names in order to list
+# them next to each other:
+OTCompilerPreferencePageName=Compiler (OT/J)
+OTCompilerPropertyPageName=Java Compiler (OT/J)
+
+OTCompilerPreferencePage_title=OT/J Compiler
+
+OTCompilerConfiguration_common_description=Configurable options of the OT/J compiler
+
+OTCompilerProblemConfiguration_description=Select the severity level for the following problems:
+OTCompilerProblemConfiguration_otjld_ref_description=(numbers refer to paragraphs in the OTJLD)
+
+OTCompilerConfigurationBlock_not_exactly_one_basecall_label=Missing or multiple basecalls in callin method (\u00a74.3(b,c))
+OTCompilerConfigurationBlock_unsafe_role_instantiation_label=Unsafe role instantiation (\u00a72.4.1(c), \u00a72.4.3)
+
+OTCompilerConfigurationBlock_effectless_fieldaccess_label=Effectless callout to field (\u00a73.5(b))
+OTCompilerConfigurationBlock_fragile_callin_label=Fragile callin binding (\u00a74.3(e))
+OTCompilerConfigurationBlock_unused_parammap_label=Unused parameter mapping (\u00a73.2)
+
+OTCompilerConfigurationBlock_potential_ambiguous_playedby_label=Potentially ambiguous role-base binding (\u00a72.3.4(a))
+OTCompilerConfigurationBlock_ambiguous_lowering_label=Ambiguity between lowering and upcast (\u00a72.2(f))
+OTCompilerConfigurationBlock_abstract_potential_relevant_role_label=Abstract role is potentially relevant (\u00a72.5(b))
+
+OTCompilerConfigurationBlock_decapsulation_label=Decapsulation (overriding access restrictions) (\u00a7 3.4)
+
+OTCompilerConfigurationBlock_bindingconventions_label=Violations of binding conventions (\u00a7 2.1.2(d) et al)
+OTCompilerConfigurationBlock_deprecated_path_syntax_label=Using deprecated path syntax for externalized roles (\u00a7 1.2.2(b))
+
+OTCompilerConfigurationBlock_inferred_callout_label=Inferring callout bindings for inherited abstract methods (\u00a7 3.1(j))
+OTCompilerConfigurationBlock_adapting_deprecated_label=Adapting a deprecated type / method
+
+OTCompilerConfigurationBlock_incomplete_build_label=Report if incremental build generates incomplete code (requiring a full build).
+OTCompilerConfigurationBlock_binding_to_system_class=Report if trying to bind a role to a system class.
+OTCompilerConfigurationBlock_override_final_role=Report if overriding a final role (experimental feature).
+OTCompilerConfigurationBlock_exception_in_guard=Report if a guard throws a checked exception (\u00a7 5.4(c)).
+
+OTCompilerFeatureEnablement_description=Select which experimental features should be enabled:
+
+OTCompilerConfigurationBlock_opt_scoped_keywords=Allow scoped keywords (\u00a7A.0.1)
+
+preferences_general_title=Object Teams
+preferences_general_callinmarker_label=Show markers for playedBy, callin and callout bindings in the editor of each bound base class.
+preferences_general_debugfilters_label=Enable filtering of generated code when debugging
+
+
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/templates/ParameterMappingTemplateResolver.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/templates/ParameterMappingTemplateResolver.java
new file mode 100644
index 0000000..31042e2
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/templates/ParameterMappingTemplateResolver.java
@@ -0,0 +1,112 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2008 Technical University Berlin, Germany.
+ *
+ * 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
+ * $Id: ParameterMappingTemplateResolver.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.templates;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.corext.template.java.JavaContext;
+import org.eclipse.jface.text.templates.TemplateContext;
+import org.eclipse.jface.text.templates.TemplateVariable;
+import org.eclipse.jface.text.templates.TemplateVariableResolver;
+import org.eclipse.objectteams.otdt.core.ICallinMapping;
+import org.eclipse.objectteams.otdt.core.ICalloutMapping;
+import org.eclipse.objectteams.otdt.core.IMethodMapping;
+import org.eclipse.objectteams.otdt.core.IOTJavaElement;
+import org.eclipse.objectteams.otdt.core.util.MethodData;
+
+/**
+ * This resolver proposes the parameter names to be used in a callin/callout parameter mapping
+ * created from a completion template.
+ *
+ * @author stephan
+ * @since 1.2.4
+ */
+public class ParameterMappingTemplateResolver extends TemplateVariableResolver {
+
+ // types of this resolver:
+ private static final String CALLIN_PARAMETER_NAME = "callin_parameter_name"; //$NON-NLS-1$
+ private static final String CALLOUT_PARAMETER_NAME = "callout_parameter_name"; //$NON-NLS-1$
+
+ private static final String VOID = "V";//$NON-NLS-1$
+
+ // special expansions:
+ private static final String RESULT = "result"; //$NON-NLS-1$
+ private static final String NOT_APPLICABLE = "$not applicable$"; //$NON-NLS-1$
+
+ @Override
+ public void resolve(TemplateVariable variable, TemplateContext context) {
+ if (context instanceof JavaContext) {
+ IMethodMapping methodMapping = findEnclosingMethodMapping((JavaContext)context);
+ if (methodMapping != null) {
+ variable.setValue(NOT_APPLICABLE);
+ String[] argumentNames = null;
+ if (!methodMapping.hasSignature()) {
+ return;
+ } else if (this.getType().equals(CALLIN_PARAMETER_NAME) && methodMapping.getElementType() == IOTJavaElement.CALLIN_MAPPING)
+ {
+ MethodData method = methodMapping.getRoleMethodHandle();
+ argumentNames = method.getArgumentNames();
+ } else if (this.getType().equals(CALLOUT_PARAMETER_NAME) && methodMapping.getElementType() == IOTJavaElement.CALLOUT_MAPPING)
+ {
+ MethodData method = ((ICalloutMapping) methodMapping).getBaseMethodHandle();
+ argumentNames = method.getArgumentNames();
+ } else {
+ if (isResultMappingSupported(methodMapping))
+ variable.setValue(RESULT);
+ else
+ variable.setResolved(false);
+ return;
+ }
+ if (argumentNames != null && argumentNames.length > 0)
+ variable.setValues(argumentNames);
+ else
+ variable.setResolved(false);
+ }
+ }
+ }
+
+
+ private IMethodMapping findEnclosingMethodMapping(JavaContext jContext) {
+ IJavaElement callinMapping = jContext.findEnclosingElement(IOTJavaElement.CALLIN_MAPPING);
+ if (callinMapping != null)
+ return (IMethodMapping) callinMapping;
+ return (IMethodMapping) jContext.findEnclosingElement(IOTJavaElement.CALLOUT_MAPPING);
+ }
+
+ /* Only propose a result mapping if a result value is actually expected. */
+ private boolean isResultMappingSupported(IMethodMapping element)
+ {
+ if (element.getElementType() == IOTJavaElement.CALLOUT_MAPPING)
+ return !element.getRoleMethodHandle().getReturnType().equals(VOID);
+
+ if (element.getElementType() == IOTJavaElement.CALLIN_MAPPING) {
+ if (((ICallinMapping) element).getCallinKind() != ICallinMapping.KIND_REPLACE)
+ return false;
+ try {
+ for (IMethod boundBaseMethod : ((ICallinMapping) element).getBoundBaseMethods())
+ if (boundBaseMethod.getReturnType().equals(VOID))
+ return false;
+ } catch (JavaModelException e) {
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewRoleCreationWizard.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewRoleCreationWizard.java
new file mode 100644
index 0000000..84ea629
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewRoleCreationWizard.java
@@ -0,0 +1,107 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: NewRoleCreationWizard.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards;
+
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation.RoleCreator;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation.RoleTypeInfo;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation.TypeCreator;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation.TypeInfo;
+import org.eclipse.objectteams.otdt.ui.ImageConstants;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+
+/**
+ * A wizard for creating a new role.
+ *
+ * @author brcan
+ * @version $Id: NewRoleCreationWizard.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class NewRoleCreationWizard extends NewTypeCreationWizard
+{
+
+ private NewRoleWizardPage _rolePage;
+
+
+ public NewRoleCreationWizard()
+ {
+ super();
+
+ setDefaultPageImageDescriptor(
+ OTDTUIPlugin.getDefault().getImageRegistry().getDescriptor(
+ ImageConstants.NEW_ROLE));
+ setDialogSettings(JavaPlugin.getDefault().getDialogSettings());
+ setWindowTitle(OTNewWizardMessages.NewRoleCreationWizard_title);
+ }
+
+ /*
+ * @see Wizard#createPages
+ */
+ public void addPages()
+ {
+ super.addPages();
+ _rolePage = new NewRoleWizardPage();
+ addPage(_rolePage);
+ _rolePage.init(getSelection());
+ }
+
+ /**
+ * @return The page referenced by this wizard. This is an object of type
+ * org.eclipse.objectteams.otdt.internal.ui.wizards.NewRoleWizardPage
+ */
+ public NewTypeWizardPage getPage()
+ {
+ return _rolePage;
+ }
+
+ /**
+ * @return A new object of type org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation.RoleCreator
+ */
+ protected TypeCreator createTypeCreator()
+ {
+ return new RoleCreator();
+ }
+
+ protected TypeInfo setTypeData(TypeCreator creator)
+ {
+ TypeInfo typeInfo = super.setTypeData(creator);
+
+ if ( (typeInfo instanceof RoleTypeInfo) && (getPage() instanceof NewRoleWizardPage) )
+ {
+ setRoleSpecificTypeData( (RoleTypeInfo)typeInfo, (NewRoleWizardPage)getPage() );
+ }
+ return typeInfo;
+ }
+
+ private void setRoleSpecificTypeData(RoleTypeInfo roleInfo, NewRoleWizardPage rolePage)
+ {
+ roleInfo.setBaseTypeName( rolePage.getBaseClassName() );
+ }
+
+ protected TypeInfo createTypeInfo()
+ {
+ NewTypeWizardPage page = getPage();
+
+ return new RoleTypeInfo(page.getTypeName(),
+ page.getPackageFragmentRoot(),
+ page.getPackageFragment());
+ }
+}
+
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewRoleWizardPage.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewRoleWizardPage.java
new file mode 100644
index 0000000..57db644
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewRoleWizardPage.java
@@ -0,0 +1,273 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: NewRoleWizardPage.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.internal.corext.refactoring.StubTypeContext;
+import org.eclipse.jdt.internal.ui.dialogs.TextFieldNavigationHandler;
+import org.eclipse.jdt.internal.ui.refactoring.contentassist.CompletionContextRequestor;
+import org.eclipse.jdt.internal.ui.refactoring.contentassist.ControlContentAssistHelper;
+import org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaTypeCompletionProcessor;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFieldGroup;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonStatusDialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.NewRoleWizardPageListener;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.NewTypeWizardPageListener;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * The class <code>NewRoleWizardPage</code> contains controls
+ * for a 'New Role WizardPage'.
+ *
+ * @author brcan
+ * @version $Id: NewRoleWizardPage.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class NewRoleWizardPage extends NewTypeWizardPage
+{
+ private static final int CREATE_INHERITED_INDEX = 0;
+
+ private StringDialogField _implicitSuperclassDialogField;
+ private StringButtonDialogField _baseClassDialogField;
+
+
+ public NewRoleWizardPage()
+ {
+ super("NewRoleWizardPage"); //$NON-NLS-1$
+
+ setTitle(OTNewWizardMessages.NewRoleWizardPage_title);
+ setDescription(OTNewWizardMessages.NewRoleWizardPage_description);
+
+ _baseClassDialogField = createBaseClassDialogField(getListener());
+ _implicitSuperclassDialogField = createImplicitSuperclassDialogField();
+ }
+
+ /**
+ * @return the baseclass name
+ */
+ public String getBaseClassName()
+ {
+ return getBaseClassDialogField().getText();
+ }
+
+ public String getImplicitSuperclassName()
+ {
+ return getImplicitSuperclassDialogField().getText();
+ }
+
+ /**
+ * @param name the new baseclass name
+ */
+ public void setBaseClassName(String name)
+ {
+ getBaseClassDialogField().setText(name);
+ }
+
+ public void setImplicitSuperclassName(String name)
+ {
+ getImplicitSuperclassDialogField().setText(name);
+ }
+
+ /**
+ * @return false
+ * a role instance always depends on a team instance
+ * thats why having a main method makes no sense
+ */
+ public boolean isCreateMainSelected()
+ {
+ return false;
+ }
+
+ public boolean isCreateInheritedSelected()
+ {
+ return getMethodStubsButtons().getSelectionButton(CREATE_INHERITED_INDEX).getSelection();
+ }
+
+ /**
+ * @return false
+ * in the majority of cases roles don't have any constructor
+ */
+ public boolean isCreateConstructorsSelected()
+ {
+ return false;
+ }
+
+ public StringButtonDialogField getBaseClassDialogField()
+ {
+ return _baseClassDialogField;
+ }
+
+ public StringDialogField getImplicitSuperclassDialogField()
+ {
+ return _implicitSuperclassDialogField;
+ }
+
+ protected NewTypeWizardPageListener createPageListener()
+ {
+ return new NewRoleWizardPageListener(this);
+ }
+
+ protected StringButtonStatusDialogField createPackageDialogField(NewTypeWizardPageListener listener)
+ {
+ return null;
+ }
+
+ protected void createPackageControls(Composite composite, int nColumns)
+ {
+ //do nothing
+ }
+
+ protected SelectionButtonDialogFieldGroup createBindingEditorButtons()
+ {
+ //do nothing
+ return null;
+ }
+
+ protected StringButtonDialogField createSuperClassDialogField(NewTypeWizardPageListener adapter)
+ {
+ StringButtonDialogField result = super.createSuperClassDialogField(adapter);
+ result.setLabelText(OTNewWizardMessages.NewRoleWizardPage_superclass_explicit_label);
+
+ return result;
+ }
+
+ protected void createInheritanceControls(Composite composite, int nColumns)
+ {
+ createImplicitSuperclassControls(composite, nColumns);
+ super.createInheritanceControls(composite, nColumns);
+ createBaseClassControls(composite, nColumns);
+ }
+
+ protected SelectionButtonDialogFieldGroup createMethodStubsButtons()
+ {
+ String[] buttonName = new String[] { NewWizardMessages.NewClassWizardPage_methods_inherited };
+ SelectionButtonDialogFieldGroup result = new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonName, 1);
+ result.setLabelText(NewWizardMessages.NewClassWizardPage_methods_label);
+
+ return result;
+ }
+
+ /**
+ * Creates the controls for the baseclass name 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 createBaseClassControls(Composite composite, int nColumns)
+ {
+ _baseClassDialogField.doFillIntoGrid(composite, nColumns);
+
+ Text text= _baseClassDialogField.getTextControl(null);
+ LayoutUtil.setWidthHint(text, getMaxFieldWidth());
+
+ JavaTypeCompletionProcessor baseClassCompletionProcessor= new JavaTypeCompletionProcessor(false, false);
+ baseClassCompletionProcessor.setCompletionContextRequestor(new CompletionContextRequestor() {
+ public StubTypeContext getStubTypeContext() {
+ return getSuperClassStubTypeContext();
+ }
+ });
+
+ ControlContentAssistHelper.createTextContentAssistant(text, baseClassCompletionProcessor);
+ TextFieldNavigationHandler.install(text);
+ }
+
+ protected void initTypePage(IJavaElement elem)
+ {
+ super.initTypePage(elem);
+ getEnclosingTypeSelectionField().setSelection(true);
+ getEnclosingTypeSelectionField().setEnabled(false);
+ setImplicitSuperclassName(""); //$NON-NLS-1$
+ setSuperTypeName("java.lang.Object"); //$NON-NLS-1$
+ getInlineSelectionDialogField().setSelection(true); // default to inline roles
+ getInlineSelectionDialogField().setEnabled(true);
+ }
+
+ protected void initAccessModifierButtons()
+ {
+ // Note(SH): we are still creating all selection buttons to stay consistent
+ // with other type creation wizards. (As long as the strange order
+ // "public, default, private, protected" is pertained, we even MUST create
+ // all four buttons, since we need the last one..).
+ getAccessModifierButtons().setSelection(PUBLIC_INDEX, false);
+ getAccessModifierButtons().enableSelectionButton(DEFAULT_INDEX, false);
+ getAccessModifierButtons().enableSelectionButton(PRIVATE_INDEX, false);
+ getAccessModifierButtons().setSelection(PROTECTED_INDEX, true);
+ }
+
+ protected void initMethodStubButtons()
+ {
+ getMethodStubsButtons().setSelection(CREATE_INHERITED_INDEX, true);
+ getMethodStubsButtons().setEnabled(true);
+ }
+
+ private StringButtonDialogField createBaseClassDialogField(NewTypeWizardPageListener listener)
+ {
+ StringButtonDialogField result = new StringButtonDialogField(listener);
+ result.setDialogFieldListener(listener);
+ result.setLabelText(OTNewWizardMessages.NewRoleWizardPage_baseclass_label);
+ result.setButtonLabel(OTNewWizardMessages.NewRoleWizardPage_baseclass_selection_button);
+
+ return result;
+ }
+
+ private StringDialogField createImplicitSuperclassDialogField()
+ {
+ StringDialogField result = new StringDialogField();
+ result.setLabelText(OTNewWizardMessages.NewRoleWizardPage_superclass_implicit_label);
+ result.setEnabled(false);
+
+ return result;
+ }
+
+ /**
+ * Creates the controls for the type name field. Expects a <code>GridLayout</code> with at
+ * least 2 columns.
+ *
+ * @param composite the parent composite
+ * @param nColumns number of columns to span
+ */
+ private void createImplicitSuperclassControls(Composite composite, int nColumns)
+ {
+ _implicitSuperclassDialogField.doFillIntoGrid(composite, nColumns - 1);
+ DialogField.createEmptySpace(composite);
+ LayoutUtil.setWidthHint(_implicitSuperclassDialogField.getTextControl(null), getMaxFieldWidth());
+ }
+
+ protected void initBindingEditorButtons()
+ {
+ }
+
+ public boolean isOpenBindingEditorSelected()
+ {
+ return false;
+ }
+
+ @Override
+ protected String getEnclosingTypeLabel() {
+ return OTNewWizardMessages.NewRoleWizardPage_enclosingtype_label;
+ }
+}
\ No newline at end of file
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewTeamCreationWizard.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewTeamCreationWizard.java
new file mode 100644
index 0000000..984438b
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewTeamCreationWizard.java
@@ -0,0 +1,110 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: NewTeamCreationWizard.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.objectteams.otdt.internal.ui.bindingeditor.BindingEditorDialog;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation.TeamCreator;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation.TypeCreator;
+import org.eclipse.objectteams.otdt.ui.ImageManager;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.swt.widgets.Display;
+
+
+/**
+ * A wizard for creating a new team.
+ *
+ * @author brcan
+ * @version $Id: NewTeamCreationWizard.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class NewTeamCreationWizard extends NewTypeCreationWizard
+{
+
+ private NewTeamWizardPage _teamPage;
+
+
+ public NewTeamCreationWizard()
+ {
+ super();
+
+ setDefaultPageImageDescriptor(
+ OTDTUIPlugin.getDefault().getImageRegistry().getDescriptor(
+ ImageManager.NEW_TEAM));
+ setDialogSettings(JavaPlugin.getDefault().getDialogSettings());
+ setWindowTitle(OTNewWizardMessages.NewTeamCreationWizard_title);
+ }
+
+ /*
+ * @see Wizard#createPages
+ */
+ public void addPages()
+ {
+ super.addPages();
+ _teamPage = new NewTeamWizardPage();
+ addPage(_teamPage);
+ _teamPage.init(getSelection());
+ }
+
+ /**
+ * @return The page referenced by this wizard. This is an object of type
+ * org.eclipse.objectteams.otdt.internal.ui.wizards.NewTeamWizardPage
+ */
+ public NewTypeWizardPage getPage()
+ {
+ return _teamPage;
+ }
+
+
+ protected void finishPage(IProgressMonitor monitor)
+ throws InterruptedException, CoreException
+ {
+ super.finishPage(monitor);
+
+ if (getPage().isOpenBindingEditorSelected())
+ {
+ final IType createdTeam = getCreatedType();
+ if (createdTeam == null)
+ {
+ // something went wrong, bail out
+ return;
+ }
+
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ BindingEditorDialog dlg = new BindingEditorDialog(getShell(), createdTeam);
+ dlg.open();
+ }
+ });
+
+ }
+ }
+
+ /**
+ * @return A new object of type org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation.TeamCreator
+ */
+ protected TypeCreator createTypeCreator()
+ {
+ return new TeamCreator();
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewTeamWizardPage.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewTeamWizardPage.java
new file mode 100644
index 0000000..47c5115
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewTeamWizardPage.java
@@ -0,0 +1,156 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: NewTeamWizardPage.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards;
+
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFieldGroup;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.NewTeamWizardPageListener;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.NewTypeWizardPageListener;
+import org.eclipse.swt.SWT;
+
+/**
+ * The class <code>NewTeamWizardPage</code> contains controls
+ * for a 'New Team WizardPage'.
+ *
+ * @author brcan
+ * @version $Id: NewTeamWizardPage.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class NewTeamWizardPage extends NewTypeWizardPage
+{
+ private static final int CREATE_MAIN_INDEX = 0;
+ private static final int CREATE_CONSTRUCTOR_INDEX = 1;
+ private static final int CREATE_INHERITED_INDEX = 2;
+ private static final int CREATE_BINDINGEDITOR_INDEX = 0;
+
+
+ public NewTeamWizardPage()
+ {
+ super("NewTeamWizardPage"); //$NON-NLS-1$
+
+ setTitle(OTNewWizardMessages.NewTeamWizardPage_title);
+ setDescription(OTNewWizardMessages.NewTeamWizardPage_description);
+ }
+
+ protected StringButtonDialogField createSuperClassDialogField(NewTypeWizardPageListener adapter)
+ {
+ StringButtonDialogField result = super.createSuperClassDialogField(adapter);
+ result.setLabelText(OTNewWizardMessages.NewTeamWizardPage_superclass_label);
+
+ return result;
+ }
+
+ protected SelectionButtonDialogFieldGroup createMethodStubsButtons()
+ {
+ String[] buttonNames3 = new String[]
+ {
+ NewWizardMessages.NewClassWizardPage_methods_main,
+ OTNewWizardMessages.NewTeamWizardPage_methods_constructors,
+ NewWizardMessages.NewClassWizardPage_methods_inherited
+ };
+
+ SelectionButtonDialogFieldGroup result = new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames3, 1);
+ result.setLabelText(NewWizardMessages.NewClassWizardPage_methods_label);
+
+ return result;
+ }
+
+ protected SelectionButtonDialogFieldGroup createBindingEditorButtons()
+ {
+ String[] buttonNames1 = new String[]
+ {
+ OTNewWizardMessages.NewTeamWizardPage_BindingEditor_selection
+ };
+
+ SelectionButtonDialogFieldGroup result = new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames1, 1);
+ result.setLabelText(OTNewWizardMessages.NewTeamWizardPage_BindingEditor_description);
+
+ return result;
+ }
+
+ protected void initTypePage(IJavaElement elem)
+ {
+ super.initTypePage(elem);
+ setSuperTypeName("org.objectteams.Team"); //$NON-NLS-1$
+ }
+
+ protected void initAccessModifierButtons()
+ {
+ getAccessModifierButtons().setSelection(PUBLIC_INDEX, true);
+ getAccessModifierButtons().enableSelectionButton(DEFAULT_INDEX, true);
+
+ getAccessModifierButtons().enableSelectionButton(PRIVATE_INDEX, false);
+ getAccessModifierButtons().enableSelectionButton(PROTECTED_INDEX, true);
+ }
+
+
+ /**
+ * Sets the selection state of the method stub checkboxes.
+ */
+ protected void initMethodStubButtons()
+ {
+ getMethodStubsButtons().setSelection(CREATE_MAIN_INDEX, false);
+ getMethodStubsButtons().setSelection(CREATE_CONSTRUCTOR_INDEX, false);
+ getMethodStubsButtons().setSelection(CREATE_INHERITED_INDEX, true);
+
+ getMethodStubsButtons().setEnabled(true);
+ }
+
+ public boolean isCreateMainSelected()
+ {
+ return getMethodStubsButtons().getSelectionButton(CREATE_MAIN_INDEX).getSelection();
+ }
+
+ public boolean isCreateInheritedSelected()
+ {
+ return getMethodStubsButtons().getSelectionButton(CREATE_INHERITED_INDEX).getSelection();
+ }
+
+ public boolean isCreateConstructorsSelected()
+ {
+ return getMethodStubsButtons().getSelectionButton(CREATE_CONSTRUCTOR_INDEX).getSelection();
+ }
+
+
+ protected void initBindingEditorButtons()
+ {
+ getBindingEditorButtons().setSelection(CREATE_BINDINGEDITOR_INDEX, false);
+
+ getBindingEditorButtons().setEnabled(false);
+ }
+
+ public boolean isOpenBindingEditorSelected()
+ {
+ return getBindingEditorButtons().getSelectionButton(CREATE_BINDINGEDITOR_INDEX).getSelection();
+ }
+
+ protected NewTypeWizardPageListener createPageListener()
+ {
+ return new NewTeamWizardPageListener(this);
+ }
+
+ @Override
+ public int getModifiers() {
+ return super.getModifiers() + Flags.AccTeam;
+ }
+}
\ No newline at end of file
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewTypeCreationWizard.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewTypeCreationWizard.java
new file mode 100644
index 0000000..3729977
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewTypeCreationWizard.java
@@ -0,0 +1,148 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: NewTypeCreationWizard.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.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.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.internal.ui.wizards.NewElementWizard;
+import org.eclipse.objectteams.otdt.core.IOTType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation.TypeCreator;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation.TypeInfo;
+
+
+/**
+ * @author kaschja
+ * @version $Id: NewTypeCreationWizard.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public abstract class NewTypeCreationWizard extends NewElementWizard
+{
+ private IType _createdType;
+
+
+ public NewTypeCreationWizard()
+ {
+ }
+
+
+ public boolean performFinish()
+ {
+ warnAboutTypeCommentDeprecation();
+ return super.performFinish();
+ }
+
+ // finishPage() is run as a WorkspaceRunnable. We need access to the SWT-thread though,
+ // so we need to stay in our thread.
+ protected boolean canRunForked()
+ {
+ return false;
+ }
+
+ protected void finishPage(IProgressMonitor monitor)
+ throws InterruptedException, CoreException
+ {
+ TypeCreator creator = createTypeCreator();
+ setTypeData(creator);
+
+ IType createdType = creator.createType(monitor);
+ ICompilationUnit createdCompUnit = createdType.getCompilationUnit();
+ ICompilationUnit cu = createdCompUnit == null ? null : createdCompUnit.getPrimary();
+
+
+ if (cu != null)
+ {
+ IResource resource = cu.getResource();
+ selectAndReveal(resource);
+ openResource((IFile) resource);
+
+ _createdType = cu.getType(createdType.getElementName());
+ }
+ }
+
+ public IType getCreatedType()
+ {
+ return _createdType;
+ }
+
+ /*
+ * Hook methods.
+ */
+ protected abstract NewTypeWizardPage getPage();
+ protected abstract TypeCreator createTypeCreator();
+
+ protected TypeInfo createTypeInfo()
+ {
+ NewTypeWizardPage page = getPage();
+
+ return new TypeInfo(page.getTypeName(),
+ page.getPackageFragmentRoot(),
+ page.getPackageFragment());
+ }
+
+
+ protected TypeInfo setTypeData(TypeCreator creator)
+ {
+ NewTypeWizardPage page = getPage();
+ TypeInfo typeInfo = createTypeInfo();
+
+ typeInfo.setEnclosingTypeName(page.getEnclosingTypeName());
+ typeInfo.setSuperClassName(page.getSuperTypeName());
+ typeInfo.setSuperInterfacesNames(page.getSuperInterfaces());
+ typeInfo.setModifier(page.getModifiers());
+ typeInfo.setCurrentType(page.getCurrentType());
+
+ if (page instanceof NewTeamWizardPage)
+ {
+ IType enclosingType = page.getEnclosingType();
+ if ( (enclosingType != null) && enclosingType.exists() )
+ {
+ IOTType enclosingOTType = OTModelManager.getOTElement(enclosingType);
+ if (enclosingOTType != null)
+ {
+ typeInfo.setIsRole(true);
+ }
+ }
+ }
+ else // if (page instanceof NewRoleWizardPage)
+ {
+ typeInfo.setIsRole(true);
+ }
+
+ typeInfo.setInline(page.isInlineTypeSelected());
+
+ typeInfo.setCreateMainMethod(page.isCreateMainSelected());
+ typeInfo.setCreateConstructor(page.isCreateConstructorsSelected());
+ typeInfo.setCreateAbstractInheritedMethods(page.isCreateInheritedSelected());
+
+ creator.setTypeInfo(typeInfo);
+ return typeInfo;
+ }
+
+ public IJavaElement getCreatedElement() {
+ return _createdType;
+ }
+
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewTypeWizardPage.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewTypeWizardPage.java
new file mode 100644
index 0000000..447fb63
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/NewTypeWizardPage.java
@@ -0,0 +1,1418 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2008 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: NewTypeWizardPage.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaConventions;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ParameterizedType;
+import org.eclipse.jdt.core.dom.Type;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
+import org.eclipse.jdt.internal.corext.refactoring.StubTypeContext;
+import org.eclipse.jdt.internal.corext.refactoring.TypeContextChecker;
+import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
+import org.eclipse.jdt.internal.corext.util.Messages;
+import org.eclipse.jdt.internal.corext.util.Resources;
+import org.eclipse.jdt.internal.ui.JavaPluginImages;
+import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
+import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
+import org.eclipse.jdt.internal.ui.dialogs.TableTextCellEditor;
+import org.eclipse.jdt.internal.ui.dialogs.TextFieldNavigationHandler;
+import org.eclipse.jdt.internal.ui.refactoring.contentassist.CompletionContextRequestor;
+import org.eclipse.jdt.internal.ui.refactoring.contentassist.ControlContentAssistHelper;
+import org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaPackageCompletionProcessor;
+import org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaTypeCompletionProcessor;
+import org.eclipse.jdt.internal.ui.util.SWTUtil;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFieldGroup;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonStatusDialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
+import org.eclipse.jdt.ui.wizards.NewContainerWizardPage;
+import org.eclipse.jface.contentassist.SubjectControlContentAssistant;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.objectteams.otdt.core.IOTType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.NewTypeWizardPageListener;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.accessibility.AccessibleAdapter;
+import org.eclipse.swt.accessibility.AccessibleEvent;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.graphics.Image;
+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.Item;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.contentassist.ContentAssistHandler;
+
+/**
+ * The class <code>NewTypeWizardPage</code> contains controls for a
+ * 'New ObjectTeams-Type WizardPage'. It is intended to serve as base class of
+ * team and role creation wizards.
+ *
+ * @see org.eclipse.objectteams.otdt.internal.ui.wizards.NewTeamWizardPage
+ * @see org.eclipse.objectteams.otdt.internal.ui.wizards.NewRoleWizardPage
+ *
+ * @author kaschja
+ * @version $Id: NewTypeWizardPage.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public abstract class NewTypeWizardPage extends org.eclipse.jdt.ui.wizards.NewTypeWizardPage
+{
+ public static final int PUBLIC_INDEX = 0;
+ public static final int DEFAULT_INDEX = 1;
+ public static final int PRIVATE_INDEX = 2;
+ public static final int PROTECTED_INDEX = 3;
+
+ public static final int ABSTRACT_INDEX = 0;
+ public static final int FINAL_INDEX = 1;
+ public static final int STATIC_INDEX = 2;
+
+ private StringButtonStatusDialogField _packageDialogField;
+
+ private SelectionButtonDialogField _enclosingTypeSelection;
+ private StringButtonDialogField _enclosingTypeDialogField;
+
+ private SelectionButtonDialogFieldGroup _accessModifierButtons;
+ private SelectionButtonDialogFieldGroup _otherModifierButtons;
+ private StringButtonDialogField _superTypeDialogField;
+ private StringDialogField _typeNameDialogField;
+ private ListDialogField _superInterfacesDialogField;
+ private SelectionButtonDialogFieldGroup _methodStubsButtons;
+ private SelectionButtonDialogFieldGroup _bindingEditorButtons;
+ private SelectionButtonDialogField _inlineSelectionDialogField;
+
+ private JavaPackageCompletionProcessor _currPackageCompletionProcessor;
+ private JavaTypeCompletionProcessor _enclosingTypeCompletionProcessor;
+
+ private NewTypeWizardPageListener _listener;
+
+ private IPackageFragment _currentPackage;
+ private IType _enclosingType;
+ private IType _superType;
+ private IType _currentType;
+
+ private boolean _canModifyPackage;
+ private boolean _canModifyEnclosingType;
+
+ private StubTypeContext _superClassStubTypeContext;
+ private StubTypeContext _superInterfaceStubTypeContext;
+
+// ------------------------------------------------------------------------------
+// start of innerclass definitions
+//------------------------------------------------------------------------------
+
+ public static class InterfaceWrapper {
+ public String interfaceName;
+
+ public InterfaceWrapper(String interfaceName) {
+ this.interfaceName= interfaceName;
+ }
+
+ public int hashCode() {
+ return interfaceName.hashCode();
+ }
+
+ public boolean equals(Object obj) {
+ return obj != null && getClass().equals(obj.getClass()) && ((InterfaceWrapper) obj).interfaceName.equals(interfaceName);
+ }
+ }
+
+
+ private static class InterfacesListLabelProvider extends LabelProvider {
+ private Image fInterfaceImage;
+
+ public InterfacesListLabelProvider() {
+ fInterfaceImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_INTERFACE);
+ }
+
+ public String getText(Object element) {
+ return ((InterfaceWrapper) element).interfaceName;
+ }
+
+ public Image getImage(Object element) {
+ return fInterfaceImage;
+ }
+ }
+
+ public NewTypeWizardPage(String pageName)
+ {
+ super(CLASS_TYPE, pageName);
+
+ _listener = createPageListener();
+
+ _packageDialogField = createPackageDialogField(_listener);
+
+ _enclosingTypeSelection= new SelectionButtonDialogField(SWT.CHECK);
+ _enclosingTypeSelection.setDialogFieldListener(_listener);
+ _enclosingTypeSelection.setLabelText(getEnclosingTypeLabel());
+
+ _enclosingTypeDialogField = createEnclosingTypeDialogField(_listener);
+
+ _typeNameDialogField = createTypeNameDialogField(_listener);
+ _superTypeDialogField = createSuperClassDialogField(_listener);
+ _superInterfacesDialogField = createSuperInterfacesDialogField(_listener,_listener);
+ _accessModifierButtons = createAccessModifierButtons(_listener);
+ _otherModifierButtons = createOtherModifierButtons(_listener);
+ _methodStubsButtons = createMethodStubsButtons();
+ _bindingEditorButtons = createBindingEditorButtons();
+ _inlineSelectionDialogField = createInlineSelectionDialogField(_listener);
+
+ _currPackageCompletionProcessor= new JavaPackageCompletionProcessor();
+ _enclosingTypeCompletionProcessor= new JavaTypeCompletionProcessor(false, false);
+
+ _canModifyPackage = true;
+ _canModifyEnclosingType = true;
+ updateEnableState();
+
+ }
+
+ protected abstract NewTypeWizardPageListener createPageListener();
+
+//------------------------------------------------------------------------------
+//creation of page elements (dialog fields, selection buttons, ...)
+//------------------------------------------------------------------------------
+
+ protected SelectionButtonDialogFieldGroup createOtherModifierButtons(NewTypeWizardPageListener listener)
+ {
+ SelectionButtonDialogFieldGroup result;
+ String[] buttonNames = new String[]
+ {
+ /* 0 == ABSTRACT_INDEX */ NewWizardMessages.NewTypeWizardPage_modifiers_abstract,
+ /* 1 == FINAL_INDEX */ NewWizardMessages.NewTypeWizardPage_modifiers_final,
+ /* 2 == STATIC_INDEX*/ NewWizardMessages.NewTypeWizardPage_modifiers_static
+ };
+
+ result = new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames, 4);
+ result.setDialogFieldListener(listener);
+
+ return result;
+ }
+
+ protected SelectionButtonDialogFieldGroup createAccessModifierButtons(NewTypeWizardPageListener listener)
+ {
+ String[] buttonNames = new String[]
+ {
+ /* 0 == PUBLIC_INDEX */ NewWizardMessages.NewTypeWizardPage_modifiers_public,
+ /* 1 == DEFAULT_INDEX */ NewWizardMessages.NewTypeWizardPage_modifiers_default,
+ /* 2 == PRIVATE_INDEX */ NewWizardMessages.NewTypeWizardPage_modifiers_private,
+ /* 3 == PROTECTED_INDEX*/ NewWizardMessages.NewTypeWizardPage_modifiers_protected
+ };
+ SelectionButtonDialogFieldGroup result = new SelectionButtonDialogFieldGroup(SWT.RADIO, buttonNames, 4);
+ result.setDialogFieldListener(listener);
+ result.setLabelText(NewWizardMessages.NewTypeWizardPage_modifiers_acc_label);
+ result.setSelection(0, true);
+
+ return result;
+ }
+
+ protected ListDialogField createSuperInterfacesDialogField(IListAdapter listlistener,
+ IDialogFieldListener fieldlistener)
+ {
+ ListDialogField result = null;
+
+ String[] buttonNames = new String[]
+ {
+ /* 0 */ NewWizardMessages.NewTypeWizardPage_interfaces_add,
+ /* 1 */ null,
+ /* 2 */ NewWizardMessages.NewTypeWizardPage_interfaces_remove
+ };
+
+ result = new ListDialogField(listlistener, buttonNames, new InterfacesListLabelProvider());
+ result.setDialogFieldListener(fieldlistener);
+
+ String interfaceLabel = NewWizardMessages.NewTypeWizardPage_interfaces_class_label;
+
+ result.setLabelText(interfaceLabel);
+ result.setRemoveButtonIndex(2);
+
+ return result;
+ }
+
+ protected StringButtonDialogField createSuperClassDialogField(NewTypeWizardPageListener listener)
+ {
+ StringButtonDialogField result = new StringButtonDialogField(listener);
+ result.setDialogFieldListener(listener);
+ result.setLabelText(NewWizardMessages.NewTypeWizardPage_superclass_label);
+ result.setButtonLabel(NewWizardMessages.NewTypeWizardPage_superclass_button);
+
+ return result;
+ }
+
+ protected StringDialogField createTypeNameDialogField(NewTypeWizardPageListener listener)
+ {
+ StringDialogField result = new StringDialogField();
+ result.setDialogFieldListener(listener);
+ result.setLabelText(NewWizardMessages.NewTypeWizardPage_typename_label);
+
+ return result;
+ }
+
+ protected StringButtonDialogField createEnclosingTypeDialogField(NewTypeWizardPageListener listener)
+ {
+ StringButtonDialogField result = new StringButtonDialogField(listener);
+ result.setDialogFieldListener(listener);
+ result.setButtonLabel(NewWizardMessages.NewTypeWizardPage_enclosing_button);
+
+ return result;
+
+ }
+
+ protected StringButtonStatusDialogField createPackageDialogField(NewTypeWizardPageListener listener)
+ {
+ StringButtonStatusDialogField result = new StringButtonStatusDialogField(listener);
+ result.setDialogFieldListener(listener);
+ result.setLabelText(NewWizardMessages.NewTypeWizardPage_package_label);
+ result.setButtonLabel(NewWizardMessages.NewTypeWizardPage_package_button);
+ result.setStatusWidthHint(NewWizardMessages.NewTypeWizardPage_default);
+
+ return result;
+ }
+
+ protected SelectionButtonDialogField createInlineSelectionDialogField(NewTypeWizardPageListener listener)
+ {
+ SelectionButtonDialogField result = new SelectionButtonDialogField(SWT.CHECK);
+ result.setDialogFieldListener(listener);
+ result.setLabelText(OTNewWizardMessages.NewRoleWizardPage_inlined_checkbox_label);
+
+ return result;
+ }
+
+ protected abstract SelectionButtonDialogFieldGroup createMethodStubsButtons();
+
+ protected abstract SelectionButtonDialogFieldGroup createBindingEditorButtons();
+
+//------------------------------------------------------------------------------
+// creation of controls - visual arrangement of page elements
+//------------------------------------------------------------------------------
+
+ public void createControl(Composite parent)
+ {
+ initializeDialogUnits(parent);
+
+ Composite composite= new Composite(parent, SWT.NONE);
+
+ int nColumns= 4;
+
+ GridLayout layout= new GridLayout();
+ layout.numColumns= nColumns;
+ composite.setLayout(layout);
+
+ createContainerControls(composite, nColumns);
+ createPackageControls(composite, nColumns);
+ createEnclosingTypeControls(composite, nColumns);
+ createInlineSelectionControls(composite, nColumns);
+ createSeparator(composite, nColumns);
+ createTypeNameControls(composite, nColumns);
+ createModifierControls(composite, nColumns);
+ createInheritanceControls(composite,nColumns);
+ createSuperInterfacesControls(composite, nColumns);
+ createMethodStubSelectionControls(composite, nColumns);
+ createBindingEditorControls(composite, nColumns);
+ createCommentControls(composite, nColumns);
+ setAddComments(StubUtility.doAddComments(getJavaProject()), true);
+ enableCommentControl(true);
+
+ setControl(composite);
+ Dialog.applyDialogFont(composite);
+ }
+
+ protected void createInheritanceControls(Composite composite, int nColumns)
+ {
+ createSuperTypeControls(composite,nColumns);
+ }
+
+ protected void createInlineSelectionControls(Composite composite, int nColumns)
+ {
+ DialogField.createEmptySpace(composite);
+ _inlineSelectionDialogField.doFillIntoGrid(composite, nColumns-1);
+ }
+
+ /**
+ * Creates the controls for the package name field. Expects a <code>GridLayout</code> with at
+ * least 4 columns.
+ *
+ * @param composite the parent composite
+ * @param nColumns number of columns to span
+ */
+ protected void createPackageControls(Composite composite, int nColumns)
+ {
+ _packageDialogField.doFillIntoGrid(composite, nColumns);
+ Text text= _packageDialogField.getTextControl(null);
+ LayoutUtil.setWidthHint(text, getMaxFieldWidth());
+ LayoutUtil.setHorizontalGrabbing(text);
+
+ ControlContentAssistHelper.createTextContentAssistant(text, _currPackageCompletionProcessor);
+ TextFieldNavigationHandler.install(text);
+ }
+
+ /**
+ * Creates the controls for the enclosing type name field. Expects a <code>GridLayout</code> with at
+ * least 4 columns.
+ *
+ * @param composite the parent composite
+ * @param nColumns number of columns to span
+ */
+ protected void createEnclosingTypeControls(Composite composite, int nColumns)
+ {
+ // #6891
+ Composite tabGroup= new Composite(composite, SWT.NONE);
+ GridLayout layout= new GridLayout();
+ layout.marginWidth= 0;
+ layout.marginHeight= 0;
+ tabGroup.setLayout(layout);
+
+ _enclosingTypeSelection.doFillIntoGrid(tabGroup, 1);
+
+ Text text= _enclosingTypeDialogField.getTextControl(composite);
+ text.getAccessible().addAccessibleListener(new AccessibleAdapter() {
+ public void getName(AccessibleEvent e) {
+ e.result= NewWizardMessages.NewTypeWizardPage_enclosing_field_description;
+ }
+ });
+ GridData gd= new GridData(GridData.FILL_HORIZONTAL);
+ gd.widthHint= getMaxFieldWidth();
+ gd.horizontalSpan= 2;
+ text.setLayoutData(gd);
+
+ Button button= _enclosingTypeDialogField.getChangeControl(composite);
+ gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
+ gd.widthHint = SWTUtil.getButtonWidthHint(button);
+ button.setLayoutData(gd);
+ ControlContentAssistHelper.createTextContentAssistant(text, _enclosingTypeCompletionProcessor);
+ TextFieldNavigationHandler.install(text);
+ }
+
+ /**
+ * Creates the controls for the type name field. Expects a <code>GridLayout</code> with at
+ * least 2 columns.
+ *
+ * @param composite the parent composite
+ * @param nColumns number of columns to span
+ */
+ protected void createTypeNameControls(Composite composite, int nColumns)
+ {
+ _typeNameDialogField.doFillIntoGrid(composite, nColumns - 1);
+ DialogField.createEmptySpace(composite);
+
+ LayoutUtil.setWidthHint(_typeNameDialogField.getTextControl(null), getMaxFieldWidth());
+ }
+
+ /**
+ * Creates the controls for the modifiers radio/ceckbox 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 createModifierControls(Composite composite, int nColumns)
+ {
+ LayoutUtil.setHorizontalSpan(_accessModifierButtons.getLabelControl(composite), 1);
+
+ Control control= _accessModifierButtons.getSelectionButtonsGroup(composite);
+ GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
+ gd.horizontalSpan= nColumns - 2;
+ control.setLayoutData(gd);
+
+ DialogField.createEmptySpace(composite);
+
+ DialogField.createEmptySpace(composite);
+
+ control= _otherModifierButtons.getSelectionButtonsGroup(composite);
+ gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
+ gd.horizontalSpan= nColumns - 2;
+ control.setLayoutData(gd);
+
+ DialogField.createEmptySpace(composite);
+ }
+
+ /**
+ * Creates the controls for the superclass name 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 createSuperTypeControls(Composite composite, int nColumns)
+ {
+ _superTypeDialogField.doFillIntoGrid(composite, nColumns);
+ Text text= _superTypeDialogField.getTextControl(null);
+ LayoutUtil.setWidthHint(text, getMaxFieldWidth());
+
+ JavaTypeCompletionProcessor superClassCompletionProcessor= new JavaTypeCompletionProcessor(false, false);
+ superClassCompletionProcessor.setCompletionContextRequestor(new CompletionContextRequestor() {
+ public StubTypeContext getStubTypeContext() {
+ return getSuperClassStubTypeContext();
+ }
+ });
+
+ ControlContentAssistHelper.createTextContentAssistant(text, superClassCompletionProcessor);
+ TextFieldNavigationHandler.install(text);
+ }
+
+ StubTypeContext getSuperClassStubTypeContext() {
+ if (_superClassStubTypeContext == null) {
+ String typeName;
+ if (_currentType != null) {
+ typeName= getTypeName();
+ } else {
+ typeName= JavaTypeCompletionProcessor.DUMMY_CLASS_NAME;
+ }
+ _superClassStubTypeContext = TypeContextChecker.createSuperClassStubTypeContext(typeName, getEnclosingType(), getPackageFragment());
+ }
+ return _superClassStubTypeContext;
+ }
+
+ /**
+ * Hook method that gets called when the type name has changed. The method validates the
+ * type name and 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 typeNameChanged() {
+ super.typeNameChanged();
+
+ StatusInfo status= new StatusInfo();
+ _currentType= null;
+ String typeNameWithParameters= getTypeName();
+ // must not be empty
+ if (typeNameWithParameters.length() == 0) {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_EnterTypeName);
+ return status;
+ }
+
+ String typeName= getTypeNameWithoutParameters();
+ if (typeName.indexOf('.') != -1) {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_QualifiedName);
+ return status;
+ }
+ IStatus val= validateJavaTypeName(typeName, getJavaProject());
+ if (val.getSeverity() == IStatus.ERROR) {
+ status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, val.getMessage()));
+ return status;
+ } else if (val.getSeverity() == IStatus.WARNING) {
+ status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_TypeNameDiscouraged, val.getMessage()));
+ // continue checking
+ }
+
+ // must not exist
+ if (!isEnclosingTypeSelected()) {
+ IPackageFragment pack= getPackageFragment();
+ if (pack != null) {
+ ICompilationUnit cu= pack.getCompilationUnit(getCompilationUnitName(typeName));
+ _currentType= cu.getType(typeName);
+ IResource resource= cu.getResource();
+
+ if (resource.exists()) {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
+ return status;
+ }
+ URI location= resource.getLocationURI();
+ if (location != null) {
+ try {
+ IFileStore store= EFS.getStore(location);
+ if (store.fetchInfo().exists()) {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExistsDifferentCase);
+ return status;
+ }
+ } catch (CoreException e) {
+ status.setError(Messages.format(
+ NewWizardMessages.NewTypeWizardPage_error_uri_location_unkown,
+ Resources.getLocationString(resource)));
+ }
+ }
+ }
+ } else {
+ IType type= getEnclosingType();
+ if (type != null) {
+ _currentType= type.getType(typeName);
+ if (_currentType.exists()) {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
+ return status;
+ }
+ }
+ }
+
+ if (typeNameWithParameters != typeName) {
+ IPackageFragmentRoot root= getPackageFragmentRoot();
+ if (root != null) {
+ if (!JavaModelUtil.is50OrHigher(root.getJavaProject())) {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeParameters);
+ return status;
+ }
+ String typeDeclaration= "class " + typeNameWithParameters + " {}"; //$NON-NLS-1$//$NON-NLS-2$
+ ASTParser parser= ASTParser.newParser(AST.JLS3);
+ parser.setSource(typeDeclaration.toCharArray());
+ parser.setProject(root.getJavaProject());
+ CompilationUnit compilationUnit= (CompilationUnit) parser.createAST(null);
+ IProblem[] problems= compilationUnit.getProblems();
+ if (problems.length > 0) {
+ status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, problems[0].getMessage()));
+ return status;
+ }
+ }
+ }
+ return status;
+ }
+
+ private String getTypeNameWithoutParameters() {
+ String typeNameWithParameters= getTypeName();
+ int angleBracketOffset= typeNameWithParameters.indexOf('<');
+ if (angleBracketOffset == -1) {
+ return typeNameWithParameters;
+ } else {
+ return typeNameWithParameters.substring(0, angleBracketOffset);
+ }
+ }
+
+
+ /**
+ * Creates the controls for the superclass name 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 createSuperInterfacesControls(Composite composite, int nColumns)
+// {
+// _superInterfacesDialogField.doFillIntoGrid(composite, nColumns);
+// GridData gd = (GridData)_superInterfacesDialogField.getListControl(null).getLayoutData();
+// gd.heightHint = convertHeightInCharsToPixels(3);
+// gd.grabExcessVerticalSpace = false;
+// gd.widthHint = getMaxFieldWidth();
+// }
+
+ /**
+ * Creates the controls for the superclass name 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 createSuperInterfacesControls(Composite composite, int nColumns) {
+ final String INTERFACE= "interface"; //$NON-NLS-1$
+ _superInterfacesDialogField.doFillIntoGrid(composite, nColumns);
+ final TableViewer tableViewer= _superInterfacesDialogField.getTableViewer();
+ tableViewer.setColumnProperties(new String[] {INTERFACE});
+
+ TableTextCellEditor cellEditor= new TableTextCellEditor(tableViewer, 0) {
+ protected void doSetFocus() {
+ if (text != null) {
+ text.setFocus();
+ text.setSelection(text.getText().length());
+ checkSelection();
+ checkDeleteable();
+ checkSelectable();
+ }
+ }
+ };
+ JavaTypeCompletionProcessor superInterfaceCompletionProcessor= new JavaTypeCompletionProcessor(false, false);
+ superInterfaceCompletionProcessor.setCompletionContextRequestor(new CompletionContextRequestor() {
+ public StubTypeContext getStubTypeContext() {
+ return getSuperInterfacesStubTypeContext();
+ }
+ });
+ SubjectControlContentAssistant contentAssistant= ControlContentAssistHelper.createJavaContentAssistant(superInterfaceCompletionProcessor);
+ Text cellEditorText= cellEditor.getText();
+ ContentAssistHandler.createHandlerForText(cellEditorText, contentAssistant);
+ TextFieldNavigationHandler.install(cellEditorText);
+ cellEditor.setContentAssistant(contentAssistant);
+
+ tableViewer.setCellEditors(new CellEditor[] { cellEditor });
+ tableViewer.setCellModifier(new ICellModifier() {
+ public void modify(Object element, String property, Object value) {
+ if (element instanceof Item)
+ element = ((Item) element).getData();
+
+ ((InterfaceWrapper) element).interfaceName= (String) value;
+ _superInterfacesDialogField.elementChanged(element);
+ }
+ public Object getValue(Object element, String property) {
+ return ((InterfaceWrapper) element).interfaceName;
+ }
+ public boolean canModify(Object element, String property) {
+ return true;
+ }
+ });
+ tableViewer.getTable().addKeyListener(new KeyAdapter() {
+ public void keyPressed(KeyEvent event) {
+ if (event.keyCode == SWT.F2 && event.stateMask == 0) {
+ ISelection selection= tableViewer.getSelection();
+ if (! (selection instanceof IStructuredSelection))
+ return;
+ IStructuredSelection structuredSelection= (IStructuredSelection) selection;
+ tableViewer.editElement(structuredSelection.getFirstElement(), 0);
+ }
+ }
+ });
+ GridData gd= (GridData) _superInterfacesDialogField.getListControl(null).getLayoutData();
+
+ gd.heightHint= convertHeightInCharsToPixels(3);
+
+ gd.grabExcessVerticalSpace= false;
+ gd.widthHint= getMaxFieldWidth();
+ }
+
+ private StubTypeContext getSuperInterfacesStubTypeContext() {
+ if (_superInterfaceStubTypeContext == null) {
+ String typeName;
+ if (_currentType != null) {
+ typeName= getTypeName();
+ } else {
+ typeName= JavaTypeCompletionProcessor.DUMMY_CLASS_NAME;
+ }
+ _superInterfaceStubTypeContext= TypeContextChecker.createSuperInterfaceStubTypeContext(typeName, getEnclosingType(), getPackageFragment());
+ }
+ return _superInterfaceStubTypeContext;
+ }
+
+ protected void createMethodStubSelectionControls(Composite composite, int nColumns)
+ {
+ Control labelControl = _methodStubsButtons.getLabelControl(composite);
+ LayoutUtil.setHorizontalSpan(labelControl, nColumns);
+
+ DialogField.createEmptySpace(composite);
+
+ Control buttonGroup = _methodStubsButtons.getSelectionButtonsGroup(composite);
+ LayoutUtil.setHorizontalSpan(buttonGroup, nColumns - 1);
+ }
+
+ protected void createBindingEditorControls(Composite composite, int nColumns)
+ {
+ if (_bindingEditorButtons != null)
+ {
+ DialogField.createEmptySpace(composite);
+ Control labelControl = _bindingEditorButtons.getLabelControl(composite);
+ LayoutUtil.setHorizontalSpan(labelControl, nColumns);
+
+ DialogField.createEmptySpace(composite);
+
+ Control buttonGroup = _bindingEditorButtons.getSelectionButtonsGroup(composite);
+ LayoutUtil.setHorizontalSpan(buttonGroup, nColumns - 1);
+ }
+ }
+
+ /**
+ * Creates the controls for the baseclass name field. Expects a <code>GridLayout</code>
+ * with at least 3 columns.
+ * This method gets called by createControls.
+ * It is intended to be overridden by the subclass
+ * org.eclipse.objectteams.otdt.internal.ui.wizards.NewRoleWizardPage.
+ *
+ * @param composite the parent composite
+ * @param nColumns number of columns to span
+ */
+ protected void createBaseClassControls(Composite composite, int nColumns){}
+
+//------------------------------------------------------------------------------
+// start of init and set methods
+//------------------------------------------------------------------------------
+
+ /**
+ * 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)
+ {
+ IJavaElement jelem = getInitialJavaElement(selection);
+ initContainerPage(jelem);
+ initTypePage(jelem);
+ }
+
+ /**
+ * Initializes all fields provided by the page with a given selection.
+ *
+ * @param elem the selection used to intialize this page or <code>
+ * null</code> if no selection was available
+ */
+ protected void initTypePage(IJavaElement elem)
+ {
+ getInlineSelectionDialogField().setEnabled(false);
+
+ initAccessModifierButtons();
+ initOtherModifierButtons();
+ initMethodStubButtons();
+ initBindingEditorButtons();
+
+ IJavaProject project= null;
+ if (elem != null)
+ {
+ project= elem.getJavaProject();
+ initPackageAndEnclosingType(elem);
+ }
+ setTypeName(""); //$NON-NLS-1$
+ setSuperInterfaces(new ArrayList(5));
+ setAddComments(StubUtility.doAddComments(project), true); // from project or workspace
+ }
+
+
+ /**
+ * initializes the package and enclosing type dialog fields
+ * depending on the given initial selected IJavaElement
+ * (that is the IJavaElement which was selected in the Package Explorer,
+ * when the request to open the wizard occured)
+ */
+ protected void initPackageAndEnclosingType(IJavaElement initialSelectedElem)
+ {
+ IType potentialEnclosingType = null;
+ IType typeInCU = (IType) initialSelectedElem.getAncestor(IJavaElement.TYPE);
+
+ if (typeInCU != null)
+ {
+ if (typeInCU.getCompilationUnit() != null)
+ {
+ potentialEnclosingType = typeInCU;
+ }
+ }
+ else
+ {
+ ICompilationUnit cu = (ICompilationUnit) initialSelectedElem.getAncestor(IJavaElement.COMPILATION_UNIT);
+ if (cu != null)
+ {
+ potentialEnclosingType = cu.findPrimaryType();
+ }
+ }
+
+ //default case
+ IPackageFragment packageFragment = (IPackageFragment) initialSelectedElem.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
+ String packName = (packageFragment == null)
+ ? "" //$NON-NLS-1$
+ : packageFragment.getElementName();
+ setPackageFragmentName(packName);
+ setEnclosingTypeName(""); //$NON-NLS-1$
+
+ if (potentialEnclosingType != null)
+ {
+ if (OTModelManager.hasOTElementFor(potentialEnclosingType))
+ {
+ IOTType potentialEnclosingOTType = OTModelManager.getOTElement(potentialEnclosingType);
+
+ boolean hasChanges = false;
+ if (potentialEnclosingOTType.isTeam())
+ {
+ handleTeamSelected(potentialEnclosingOTType);
+ hasChanges = true;
+ }
+ else //if potentialEnclosingOTType.isRole()
+ {
+ handleRoleSelected(potentialEnclosingOTType);
+ hasChanges = true;
+ }
+
+ if (hasChanges)
+ {
+ }
+ }
+ else try
+ {
+ if (potentialEnclosingType.isClass())
+ {
+ handleClassSelected(potentialEnclosingType);
+ }
+ }
+ catch (JavaModelException ex)
+ {
+ OTDTUIPlugin.getExceptionHandler().logCoreException(null,ex);
+ }
+ }
+ }
+
+ /**
+ * sets the enclosing type to be the given team class and
+ * the package fragment to be the package fragment of that team
+ * @param potentialEnclosingTeam - isTeam must be true
+ */
+ private void handleTeamSelected(IOTType potentialEnclosingTeam)
+ {
+ IType enclosingTeam = null;
+ IPackageFragment packageFragment = null;
+
+ if (potentialEnclosingTeam != null)
+ {
+//{OTModelUpdate
+ enclosingTeam = (IType) potentialEnclosingTeam.getCorrespondingJavaElement();
+//haebor}
+ packageFragment = enclosingTeam.getPackageFragment();
+ }
+
+ String enclosingTeamName = (enclosingTeam == null) ? "" : enclosingTeam.getFullyQualifiedName('.'); //$NON-NLS-1$
+ setEnclosingTypeName(enclosingTeamName);
+
+ String packName = (packageFragment == null) ? "" : packageFragment.getElementName(); //$NON-NLS-1$
+ setPackageFragmentName(packName);
+ }
+
+ /**
+ * sets the enclosing type to be the enclosing team of the given role class and
+ * the package fragment to be the package fragment of that team
+ * @param potentialEnclosingRole - isRole() must be true
+ */
+ private void handleRoleSelected(IOTType potentialEnclosingRole)
+ {
+ IType enclosingTeam = null;
+ IPackageFragment packageFragment = null;
+
+ if (potentialEnclosingRole != null) {
+ if (potentialEnclosingRole.isRole())
+ {
+ IJavaElement parent = potentialEnclosingRole.getParent();
+ if (parent instanceof IOTType) {
+ enclosingTeam = (IType)((IOTType)parent).getCorrespondingJavaElement();
+ packageFragment = enclosingTeam.getPackageFragment();
+ }
+ }
+ if (packageFragment == null) {
+ packageFragment = potentialEnclosingRole.getPackageFragment();
+ }
+ }
+
+ String enclosingTeamName = (enclosingTeam == null) ? "" : enclosingTeam.getFullyQualifiedName('.'); //$NON-NLS-1$
+ setEnclosingTypeName(enclosingTeamName);
+
+ String packName = (packageFragment == null) ? "" : packageFragment.getElementName(); //$NON-NLS-1$
+ setPackageFragmentName(packName);
+ }
+
+ /**
+ * sets the enclosing type to be null and
+ * the package fragment to be the package fragment of the given class
+ */
+ private void handleClassSelected(IType potentialEnclosingType)
+ {
+ setEnclosingTypeName(""); //$NON-NLS-1$
+
+ IPackageFragment pack = potentialEnclosingType.getPackageFragment();
+ String packName = (pack == null) ? "" : pack.getElementName(); //$NON-NLS-1$
+ setPackageFragmentName(packName);
+ }
+
+ protected abstract void initAccessModifierButtons();
+
+ protected void initOtherModifierButtons()
+ {
+ _otherModifierButtons.enableSelectionButton(STATIC_INDEX, false);
+ _otherModifierButtons.enableSelectionButton(FINAL_INDEX, true);
+ }
+
+ /**
+ * Sets the selection state of the method stub checkboxes.
+ */
+ protected abstract void initMethodStubButtons();
+
+ /**
+ * Sets the selection state of the bindingeditor checkbox.
+ */
+ protected abstract void initBindingEditorButtons();
+
+ /**
+ * Sets the enclosing type. The method updates the underlying model
+ * and the text of the control.
+ *
+ * @param type the enclosing type
+ * @param canBeModified if <code>true</code> the enclosing type field is
+ * editable; otherwise it is read-only.
+ */
+ public void setEnclosingType(IType type, boolean canBeModified) {
+ super.setEnclosingType(type, canBeModified);
+
+ _enclosingType= type;
+ _canModifyEnclosingType= canBeModified;
+ updateEnableState();
+ }
+
+ public void setEnclosingTypeName(String qualifiedName)
+ {
+ getEnclosingTypeDialogField().setText(qualifiedName);
+ }
+
+ /**
+ * Sets the package fragment to the given value. The method updates the model.
+ * It does NOT update the text of the control the text of the control.
+ *
+ * @param pack the package fragment to be set
+ */
+ public void setPackageFragment(IPackageFragment pack, boolean canBeModified) {
+ _currentPackage = pack;
+ _canModifyPackage= canBeModified;
+ updateEnableState();
+ }
+
+ public void setPackageFragmentName(String packageName)
+ {
+ if (getPackageDialogField() != null)
+ {
+ getPackageDialogField().setText(packageName);
+ }
+ }
+
+ /**
+ * Sets the type name input field's text to the given value. Method doesn't update
+ * the model.
+ *
+ * @param name the new type name
+ */
+ public void setTypeName(String name)
+ {
+ _typeNameDialogField.setText(name);
+ _typeNameDialogField.setEnabled(true);
+ }
+
+ /**
+ * Sets the super interfaces.
+ *
+ * @param interfacesNames a list of super interface. The method requires that
+ * the list's elements are of type <code>String</code>
+ */
+ public void setSuperInterfaces(List interfacesNames)
+ {
+ _superInterfacesDialogField.setElements(interfacesNames);
+ _superInterfacesDialogField.setEnabled(true);
+ }
+
+ public void setSuperType(IType type)
+ {
+ _superType = type;
+ }
+
+ public void setSuperTypeName(String name)
+ {
+ getSuperTypeDialogField().setText(name);
+ getSuperTypeDialogField().setEnabled(true);
+ }
+
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ if (visible) {
+ setFocus();
+ IStatus status = StatusUtil.getMostSevere(((NewTypeWizardPageListener)this._listener).getRelevantStates(true/*ignoreFirstField*/));
+ if (!status.isOK())
+ StatusUtil.applyToStatusLine(this, status);
+ }
+ }
+
+ /**
+ * Sets the focus on the type name input field.
+ */
+ protected void setFocus()
+ {
+ _typeNameDialogField.setFocus();
+ }
+
+
+//------------------------------------------------------------------------------
+// start of get methods
+//-----------------------------------------------------------------------------
+
+ public SelectionButtonDialogFieldGroup getAccessModifierButtons()
+ {
+ return _accessModifierButtons;
+ }
+
+ public SelectionButtonDialogFieldGroup getOtherModifierButtons()
+ {
+ return _otherModifierButtons;
+ }
+
+ public SelectionButtonDialogFieldGroup getMethodStubsButtons()
+ {
+ return _methodStubsButtons;
+ }
+
+ public abstract boolean isCreateMainSelected();
+
+ public abstract boolean isCreateInheritedSelected();
+
+ public abstract boolean isCreateConstructorsSelected();
+
+
+ public SelectionButtonDialogFieldGroup getBindingEditorButtons()
+ {
+ return _bindingEditorButtons;
+ }
+
+ public abstract boolean isOpenBindingEditorSelected();
+
+ public NewTypeWizardPageListener getListener()
+ {
+ return _listener;
+ }
+
+ public StringButtonStatusDialogField getPackageDialogField()
+ {
+ return _packageDialogField;
+ }
+
+ public StringDialogField getTypeNameDialogField()
+ {
+ return _typeNameDialogField;
+ }
+
+ public StringButtonDialogField getEnclosingTypeDialogField()
+ {
+ return _enclosingTypeDialogField;
+ }
+
+ public StringButtonDialogField getSuperTypeDialogField()
+ {
+ return _superTypeDialogField;
+ }
+
+ public SelectionButtonDialogField getInlineSelectionDialogField()
+ {
+ return _inlineSelectionDialogField;
+ }
+
+ public ListDialogField getSuperInterfacesDialogField()
+ {
+ return _superInterfacesDialogField;
+ }
+
+ public SelectionButtonDialogField getEnclosingTypeSelectionField() {
+ return _enclosingTypeSelection;
+ }
+
+ public String getTypeName()
+ {
+ return getTypeNameDialogField().getText();
+ }
+
+ public IPackageFragment getPackageFragment()
+ {
+ return _currentPackage;
+ }
+
+ public String getPackageName()
+ {
+ if (_packageDialogField != null)
+ {
+ return _packageDialogField.getText();
+ }
+ else
+ {
+ return ""; //$NON-NLS-1$
+ }
+ }
+
+ public IType getEnclosingType()
+ {
+ return _enclosingType;
+ }
+
+ public String getEnclosingTypeName()
+ {
+ return getEnclosingTypeDialogField().getText();
+ }
+
+ public boolean isInlineTypeSelected()
+ {
+ return getInlineSelectionDialogField().isSelected();
+ }
+
+ public IType getSuperType()
+ {
+ return _superType;
+ }
+
+ public String getSuperTypeName()
+ {
+ return getSuperTypeDialogField().getText();
+ }
+
+ /**
+ * Returns the chosen super interfaces.
+ *
+ * @return a list of chosen super interfaces. The list's elements
+ * are of type <code>String</code>
+ */
+ @SuppressWarnings("unchecked") // ListDialogField uses raw List
+ public List getSuperInterfaces() {
+ List interfaces= _superInterfacesDialogField.getElements();
+ ArrayList result= new ArrayList(interfaces.size());
+ for (Iterator iter= interfaces.iterator(); iter.hasNext();) {
+ InterfaceWrapper wrapper= (InterfaceWrapper) iter.next();
+ result.add(wrapper.interfaceName);
+ }
+ return result;
+ }
+ /**
+ * Hook method that gets called when the list of super interface has changed. The method
+ * validates the super interfaces and 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 superInterfacesChanged() {
+ StatusInfo status= new StatusInfo();
+
+ IPackageFragmentRoot root= getPackageFragmentRoot();
+ _superInterfacesDialogField.enableButton(0, root != null);
+
+ if (root != null) {
+ List elements= _superInterfacesDialogField.getElements();
+ int nElements= elements.size();
+ for (int i= 0; i < nElements; i++) {
+ String intfname= ((InterfaceWrapper) elements.get(i)).interfaceName;
+ Type type= TypeContextChecker.parseSuperInterface(intfname);
+ if (type == null) {
+ status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperInterfaceName, intfname));
+ return status;
+ }
+ if (type instanceof ParameterizedType && ! JavaModelUtil.is50OrHigher(root.getJavaProject())) {
+ status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_SuperInterfaceNotParameterized, intfname));
+ return status;
+ }
+ }
+ }
+ return status;
+ }
+
+ /**
+ * Sets the super interfaces.
+ *
+ * @param interfacesNames a list of super interface. The method requires that
+ * the list's elements are of type <code>String</code>
+ * @param canBeModified if <code>true</code> the super interface field is
+ * editable; otherwise it is read-only.
+ */
+ @SuppressWarnings("unchecked") // we are called with a raw List
+ public void setSuperInterfaces(List interfacesNames, boolean canBeModified) {
+ ArrayList interfaces= new ArrayList(interfacesNames.size());
+ for (Iterator iter= interfacesNames.iterator(); iter.hasNext();) {
+ interfaces.add(new InterfaceWrapper((String) iter.next()));
+ }
+ _superInterfacesDialogField.setElements(interfaces);
+ _superInterfacesDialogField.setEnabled(canBeModified);
+ }
+
+ /**
+ * Adds a super interface to the end of the list and selects it if it is not in the list yet.
+ *
+ * @param superInterface the fully qualified type name of the interface.
+ * @return returns <code>true</code>if the interfaces has been added, <code>false</code>
+ * if the interface already is in the list.
+ * @since 3.2
+ */
+ public boolean addSuperInterface(String superInterface) {
+ return _superInterfacesDialogField.addElement(new InterfaceWrapper(superInterface));
+ }
+
+
+ /**
+ * Returns the selected modifiers.
+ *
+ * @return the selected modifiers
+ * @see org.eclipse.jdt.core.Flags
+ */
+ public int getModifiers()
+ {
+ int mdf= 0;
+ if (getAccessModifierButtons().isSelected(PUBLIC_INDEX))
+ {
+ mdf+= Flags.AccPublic;
+ } else if (getAccessModifierButtons().isSelected(PRIVATE_INDEX))
+ {
+ mdf+= Flags.AccPrivate;
+ } else if (getAccessModifierButtons().isSelected(PROTECTED_INDEX))
+ {
+ mdf+= Flags.AccProtected;
+ }
+ if (getOtherModifierButtons().isSelected(ABSTRACT_INDEX) && (STATIC_INDEX != 0))
+ {
+ mdf+= Flags.AccAbstract;
+ }
+ if (getOtherModifierButtons().isSelected(FINAL_INDEX))
+ {
+ mdf+= Flags.AccFinal;
+ }
+ if (getOtherModifierButtons().isSelected(STATIC_INDEX))
+ {
+ mdf+= Flags.AccStatic;
+ }
+ return mdf;
+ }
+
+ public IStatus getContainerStatus()
+ {
+ //inherited from NewContainerWizardPage
+ return fContainerStatus;
+ }
+
+ /**
+ * extended visibility in order to enable calls from external listeners
+ * @see NewContainerWizardPage.updateStatus
+ */
+ public void updateStatus(IStatus[] status)
+ {
+ super.updateStatus(status);
+ }
+
+ /**
+ * workaround
+ * the containerDialogField is defined in a superclass and declared private
+ *
+ * informs the listener that the container dialogfield has changed
+ */
+ protected void handleFieldChanged(String fieldName)
+ {
+ super.handleFieldChanged(fieldName);
+ if (fieldName == CONTAINER)
+ {
+ getListener().handleContainerChanged();
+ }
+ }
+
+ /** A bridge to the protected method typeNameChanged() */
+ public IStatus publicTypeNameChanged() {
+ return typeNameChanged();
+ }
+
+ /**
+ * Returns the selection state of the enclosing type checkbox.
+ *
+ * @return the selection state of the enclosing type checkbox
+ */
+ public boolean isEnclosingTypeSelected() {
+ if(_enclosingTypeSelection == null)
+ return super.isEnclosingTypeSelected();
+ else
+ return _enclosingTypeSelection.isSelected();
+ }
+
+ /**
+ * Sets the enclosing type checkbox's selection state.
+ *
+ * @param isSelected the checkbox's selection state
+ * @param canBeModified if <code>true</code> the enclosing type checkbox is
+ * modifiable; otherwise it is read-only.
+ */
+ public void setEnclosingTypeSelection(boolean isSelected, boolean canBeModified) {
+ super.setEnclosingTypeSelection(isSelected, canBeModified);
+ _enclosingTypeSelection.setSelection(isSelected);
+ _enclosingTypeSelection.setEnabled(canBeModified);
+ updateEnableState();
+ }
+
+ /*
+ * Updates the enable state of buttons related to the enclosing type selection checkbox.
+ */
+ public void updateEnableState() {
+ boolean enclosing= isEnclosingTypeSelected();
+ if(_packageDialogField != null)
+ _packageDialogField.setEnabled(_canModifyPackage && !enclosing);
+ _enclosingTypeDialogField.setEnabled(_canModifyEnclosingType && enclosing);
+ }
+
+ /*
+ * @see org.eclipse.jdt.ui.wizards.NewContainerWizardPage#containerChanged()
+ */
+ protected IStatus containerChanged() {
+ IStatus status= super.containerChanged();
+
+ _currPackageCompletionProcessor.setPackageFragmentRoot(getPackageFragmentRoot());
+ if (getPackageFragmentRoot() != null) {
+ _enclosingTypeCompletionProcessor.setPackageFragment(getPackageFragmentRoot().getPackageFragment("")); //$NON-NLS-1$
+ }
+ return status;
+ }
+
+ /**
+ * Returns the label that is used for the enclosing type input field.
+ *
+ * @return the label that is used for the enclosing type input field.
+ * @since 3.2
+ */
+ protected String getEnclosingTypeLabel() {
+ return NewWizardMessages.NewTypeWizardPage_enclosing_selection_label;
+ }
+
+ IType getCurrentType() {
+ return _currentType;
+ }
+
+ @Override
+ public IType chooseEnclosingType() {
+ return super.chooseEnclosingType();
+ }
+
+ public static IStatus validateJavaTypeName(String typeName, IJavaProject javaProject) {
+ String sourceLevel = CompilerOptions.VERSION_1_5;
+ String complianceLevel = CompilerOptions.VERSION_1_5;
+ if (javaProject != null) {
+ sourceLevel = javaProject.getOption(CompilerOptions.OPTION_Source, true);
+ complianceLevel = javaProject.getOption(CompilerOptions.OPTION_Compliance, true);
+ }
+ return JavaConventions.validateJavaTypeName(typeName, sourceLevel, complianceLevel);
+ }
+ public static IStatus validatePackageName(String packageName, IJavaProject javaProject) {
+ String sourceLevel = CompilerOptions.VERSION_1_5;
+ String complianceLevel = CompilerOptions.VERSION_1_5;
+ if (javaProject != null) {
+ sourceLevel = javaProject.getOption(CompilerOptions.OPTION_Source, true);
+ complianceLevel = javaProject.getOption(CompilerOptions.OPTION_Compliance, true);
+ }
+ return JavaConventions.validatePackageName(packageName, sourceLevel, complianceLevel);
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OTNewProjectWizard.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OTNewProjectWizard.java
new file mode 100644
index 0000000..3648cc6
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OTNewProjectWizard.java
@@ -0,0 +1,188 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: OTNewProjectWizard.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jdt.ui.wizards.JavaCapabilityConfigurationPage;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.objectteams.otdt.core.ext.OTDTPlugin;
+import org.eclipse.objectteams.otdt.core.ext.OTREContainer;
+import org.eclipse.objectteams.otdt.ui.ImageConstants;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
+import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
+import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
+
+/**
+ * @author brcan
+ * @version $Id: OTNewProjectWizard.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+
+public class OTNewProjectWizard
+ extends BasicNewProjectResourceWizard
+ implements IExecutableExtension
+{
+ private IConfigurationElement _configElement;
+ private JavaCapabilityConfigurationPage _javaPage;
+ private WizardNewProjectCreationPage _mainPage;
+// private IJavaProject _javaProject;
+ private IWorkbench _workbench;
+
+ public OTNewProjectWizard()
+ {
+ super();
+ setDefaultPageImageDescriptor(OTDTUIPlugin.getDefault().getImageRegistry().getDescriptor(ImageConstants.NEW_OT_PROJECT));
+ setDialogSettings(OTDTUIPlugin.getDefault().getDialogSettings());
+ setWindowTitle(OTDTUIPlugin.getResourceString("NewOTProjectCreationWizard.title")); //$NON-NLS-1$
+ }
+
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ _workbench= workbench;
+ }
+
+ public void addPages()
+ {
+ _mainPage = new WizardNewProjectCreationPage("NewOTProjectCreationWizard"); //$NON-NLS-1$
+ _mainPage.setTitle(OTDTUIPlugin.getResourceString("NewOTProjectCreationWizard.MainPage.title")); //$NON-NLS-1$
+ _mainPage.setDescription(OTDTUIPlugin.getResourceString("NewOTProjectCreationWizard.MainPage.description")); //$NON-NLS-1$
+ addPage(_mainPage);
+
+ _javaPage = new JavaCapabilityConfigurationPage() {
+
+ @Override
+ public void setVisible(boolean visible)
+ {
+ updateJavaPage();
+ super.setVisible(visible);
+ }
+ };
+
+ // We can't add otre.jar to the classpath here, as that would overwrite the default classpath, i.e. the source folder (carp)
+// _javaPage.setDefaultClassPath(new IClasspathEntry[] { JavaCore.newContainerEntry(OTREContainer.OTRE_CONTAINER_PATH) }, true);
+ addPage(_javaPage);
+ }
+
+ private void updateJavaPage()
+ {
+ IJavaProject jproject= JavaCore.create(_mainPage.getProjectHandle());
+ if (!jproject.equals(_javaPage.getJavaProject()))
+ {
+ IClasspathEntry[] buildPath= {
+ JavaCore.newSourceEntry(jproject.getPath().append("src")), //$NON-NLS-1$
+ JavaRuntime.getDefaultJREContainerEntry()
+ };
+ IPath outputLocation= jproject.getPath().append("bin"); //$NON-NLS-1$
+ _javaPage.init(jproject, outputLocation, buildPath, false);
+ }
+ }
+
+ private void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
+ if (monitor == null) {
+ monitor= new NullProgressMonitor();
+ }
+ try {
+ monitor.beginTask(OTNewWizardMessages.NewProjectWizard_task_title, 4); // 4 steps
+
+ IProject project= _mainPage.getProjectHandle();
+ IPath locationPath= _mainPage.getLocationPath();
+
+ // create the project
+ IProjectDescription desc= project.getWorkspace().newProjectDescription(project.getName());
+ if (!_mainPage.useDefaults()) {
+ desc.setLocation(locationPath);
+ }
+ desc.setNatureIds(OTDTPlugin.createProjectNatures(desc));
+ desc.setBuildSpec(OTDTPlugin.createProjectBuildCommands(desc));
+
+ project.create(desc, new SubProgressMonitor(monitor, 1));
+ project.open(new SubProgressMonitor(monitor, 1));
+
+ updateJavaPage();
+ _javaPage.configureJavaProject(new SubProgressMonitor(monitor, 1));
+
+ OTREContainer.initializeOTJProject(project);
+
+ // change to the perspective specified in the plugin.xml
+ BasicNewProjectResourceWizard.updatePerspective(_configElement);
+ BasicNewResourceWizard.selectAndReveal(project, _workbench.getActiveWorkbenchWindow());
+
+ } finally {
+ monitor.done();
+ }
+ }
+
+ public boolean performFinish() {
+ WorkspaceModifyOperation op= new WorkspaceModifyOperation() {
+ protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
+ finishPage(monitor);
+ }
+ };
+ try {
+ getContainer().run(false, true, op);
+ } catch (InvocationTargetException ex) {
+ if (ex.getTargetException() instanceof CoreException)
+ {
+ CoreException core = (CoreException) ex.getTargetException();
+ ErrorDialog.openError(getShell(), OTNewWizardMessages.NewProjectWizard_error_title, core.getMessage(), core.getStatus());
+ }
+
+ String title = OTNewWizardMessages.NewProjectWizard_wizard_creation_failure_title;
+ String message = OTNewWizardMessages.NewProjectWizard_wizard_creation_failure_message;
+ OTDTUIPlugin.getExceptionHandler().logException("Wizard title" + title + ": "+ message, ex); //$NON-NLS-1$ //$NON-NLS-2$
+ return false;
+ } catch (InterruptedException e) {
+ return false; // canceled
+ }
+ return true;
+ }
+
+
+
+ /**
+ * Stores the configuration element for the wizard.
+ * The config element will be used in performFinish()
+ * to set the result perspective.
+ */
+ public void setInitializationData(
+ IConfigurationElement cfig,
+ String propertyName,
+ Object data)
+ {
+ _configElement = cfig;
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OTNewWizardMessages.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OTNewWizardMessages.java
new file mode 100644
index 0000000..7dd0a03
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OTNewWizardMessages.java
@@ -0,0 +1,102 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2006 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: OTNewWizardMessages.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards;
+
+import org.eclipse.osgi.util.NLS;
+
+public class OTNewWizardMessages extends NLS {
+
+ private static final String BUNDLE_NAME= "org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages";//$NON-NLS-1$
+
+
+ private OTNewWizardMessages() {
+ // Do not instantiate
+ }
+
+ public static String NewProjectWizard_task_title;
+ public static String NewProjectWizard_wizard_creation_failure_title;
+ public static String NewProjectWizard_wizard_creation_failure_message;
+ public static String NewProjectWizard_error_title;
+
+ // common errors:
+ public static String NewTypeWizardPage_same_enclosing_and_super_error;
+ public static String NewTypeWizardPage_super_of_regular_is_role_error;
+
+ // NewRole:
+ public static String NewRoleCreationWizard_title;
+
+ public static String NewRoleWizardPage_title;
+ public static String NewRoleWizardPage_description;
+
+ public static String NewRoleWizardPage_enclosingtype_label;
+ public static String NewRoleWizardPage_ChooseEnclosingTypeDialog_title;
+ public static String NewRoleWizardPage_ChooseEnclosingTypeDialog_description;
+
+ public static String NewRoleWizardPage_inlined_checkbox_label;
+
+ public static String NewRoleWizardPage_SuperclassDialog_title;
+ public static String NewRoleWizardPage_SuperclassDialog_message;
+ public static String NewRoleWizardPage_superclass_explicit_label;
+
+ public static String NewRoleWizardPage_superclass_implicit_label;
+
+ public static String NewRoleWizardPage_BaseclassDialog_title;
+ public static String NewRoleWizardPage_BaseclassDialog_message;
+ public static String NewRoleWizardPage_baseclass_label;
+ public static String NewRoleWizardPage_baseclass_selection_button;
+
+ // errors:
+ public static String NewRoleWizardPage_already_has_this_super;
+ public static String NewRoleWizardPage_explicit_and_implicit_subclassing_error;
+ public static String NewRoleWizardPage_incompatible_supers_error;
+ public static String NewRoleWizardPage_super_is_overridden_error;
+ public static String NewRoleWizardPage_super_is_role_of_different_team_error;
+
+ public static String NewRole_base_class_equals_enclosing;
+ public static String NewRole_base_class_equals_member;
+ public static String NewRole_role_hides_team;
+
+ // NewTeam:
+ public static String NewTeamCreationWizard_title;
+ public static String NewTeamWizardPage_title;
+ public static String NewTeamWizardPage_description;
+
+ public static String NewTeamWizardPage_ChooseSuperTypeDialog_title;
+ public static String NewTeamWizardPage_ChooseSuperTypeDialog_description;
+ public static String NewTeamWizardPage_superclass_label;
+
+ public static String NewTeamWizardPage_methods_constructors;
+
+ public static String NewTeamWizardPage_BindingEditor_selection;
+ public static String NewTeamWizardPage_BindingEditor_description;
+
+ public static String TeamSelectionDialog_upperLabel;
+ public static String TeamSelectionDialog_lowerLabel;
+ public static String TeamSelectionDialog_notypes_title;
+ public static String TeamSelectionDialog_notypes_message;
+
+
+
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, OTNewWizardMessages.class);
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OTNewWizardMessages.properties b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OTNewWizardMessages.properties
new file mode 100644
index 0000000..c60292c
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OTNewWizardMessages.properties
@@ -0,0 +1,68 @@
+# new project wizard:
+NewProjectWizard_task_title=Creating Object Teams project...
+NewProjectWizard_wizard_creation_failure_title=Wizard Creation Failure
+NewProjectWizard_wizard_creation_failure_message=An error occurred while creating the wizard
+NewProjectWizard_error_title=Error creating Object Teams Java project
+
+
+# common errors:
+NewTypeWizardPage_same_enclosing_and_super_error=Enclosing and superclass must be different
+NewTypeWizardPage_super_of_regular_is_role_error=Superclass is a role class. Therefore the type to be created must be a role class too and needs an enclosing team class.
+
+#NewTeamCreationWizard
+NewTeamCreationWizard_title = New Team
+
+#NewTeamWizardPage
+NewTeamWizardPage_title = Team Class
+NewTeamWizardPage_description = Create a new team class.
+
+NewTeamWizardPage_ChooseSuperTypeDialog_title= Superteam Selection
+NewTeamWizardPage_ChooseSuperTypeDialog_description= Choose a team as superclass of the new team class:
+NewTeamWizardPage_superclass_label = Superte&am:
+
+NewTeamWizardPage_methods_constructors=&Constructors from superteam
+
+NewTeamWizardPage_BindingEditor_selection= Edit using the Binding Editor
+NewTeamWizardPage_BindingEditor_description= Should this team be used as a connector?
+
+# NewRoleCreationWizard
+NewRoleCreationWizard_title = New Role
+
+#NewRoleWizardPage
+NewRoleWizardPage_title = Role class
+NewRoleWizardPage_description = Create a new role class.
+
+NewRoleWizardPage_enclosingtype_label=Enclosing Team
+NewRoleWizardPage_ChooseEnclosingTypeDialog_description=&Choose a team to which the new class will be added as a role:
+NewRoleWizardPage_ChooseEnclosingTypeDialog_title=Enclosing Team Selection
+
+NewRoleWizardPage_inlined_checkbox_label=&inlined
+
+NewRoleWizardPage_SuperclassDialog_title= Explicit Superclass Selection
+NewRoleWizardPage_SuperclassDialog_message= Choose a type as explicit superclass of the new role class:
+NewRoleWizardPage_superclass_explicit_label = E&xplicit superclass:
+
+NewRoleWizardPage_superclass_implicit_label = Implicit superclass:
+
+NewRoleWizardPage_BaseclassDialog_title= Baseclass Selection
+NewRoleWizardPage_BaseclassDialog_message= Choose a type that plays the new role:
+NewRoleWizardPage_baseclass_label = Bound &base class:
+NewRoleWizardPage_baseclass_selection_button=&Browse...
+
+# errors:
+NewRoleWizardPage_already_has_this_super=Role to be created already inherits from {0} because an implicit superclass inherits from it.
+NewRoleWizardPage_explicit_and_implicit_subclassing_error=It is not allowed to subclass a type implicitly and explicitly at the same time.
+NewRoleWizardPage_incompatible_supers_error=Super class must be sub class of {0} because implicit super role already declares it as its super class.
+NewRoleWizardPage_super_is_overridden_error=The superclass is not visible in the scope of the role that is to be created because it has an overriding implicit subclass.
+NewRoleWizardPage_super_is_role_of_different_team_error=Superclass is a role class. Its enclosing team must be contained in the supertype hierarchy of the enclosing team of the type to be created.
+
+NewRole_base_class_equals_enclosing="Cannot use the enclosing class {0} as the base class."
+NewRole_base_class_equals_member="A member class {0} exists in scope, cannot use as base class."
+NewRole_role_hides_team = Role must not hide or shadow its enclosing team.
+
+# === DIALOGS: ===
+#TeamSelectionDialog
+TeamSelectionDialog_upperLabel= Matching teams:
+TeamSelectionDialog_lowerLabel= Qualifier:
+TeamSelectionDialog_notypes_title=Team Selection
+TeamSelectionDialog_notypes_message=No teams available.
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OpenOTProjectWizardAction.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OpenOTProjectWizardAction.java
new file mode 100644
index 0000000..fbfc592
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OpenOTProjectWizardAction.java
@@ -0,0 +1,48 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: OpenOTProjectWizardAction.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards;
+
+import org.eclipse.jdt.ui.actions.AbstractOpenWizardAction;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.INewWizard;
+
+/**
+ * Action for the OT new project wizard. This action is only used in cheatsheets.
+ *
+ * @author brcan
+ * @version $Id: OpenOTProjectWizardAction.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class OpenOTProjectWizardAction extends AbstractOpenWizardAction {
+
+ public OpenOTProjectWizardAction() {
+// WorkbenchHelp.setHelp(this, IJavaHelpContextIds.OPEN_PROJECT_WIZARD_ACTION);
+ }
+
+ @Override
+ protected INewWizard createWizard() {
+ return new OTNewProjectWizard();
+ }
+
+ @Override
+ protected boolean doCreateProjectFirstOnEmptyWorkspace(Shell shell) {
+ return true; // can work on an empty workspace
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OpenRoleWizardAction.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OpenRoleWizardAction.java
new file mode 100644
index 0000000..4cbeb05
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OpenRoleWizardAction.java
@@ -0,0 +1,52 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: OpenRoleWizardAction.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards;
+
+import org.eclipse.jdt.ui.actions.AbstractOpenWizardAction;
+import org.eclipse.ui.INewWizard;
+
+/**
+ * Action for the role wizard. This action is only used in cheatsheets.
+ *
+ * @author brcan
+ * @version $Id: OpenRoleWizardAction.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class OpenRoleWizardAction extends AbstractOpenWizardAction
+{
+ public OpenRoleWizardAction() {
+// WorkbenchHelp.setHelp(this, IJavaHelpContextIds.OPEN_CLASS_WIZARD_ACTION);
+ }
+/* km: not needed anymore?
+ public OpenRoleWizardAction(String label, Class[] acceptedTypes) {
+ super(label, acceptedTypes, false);
+// WorkbenchHelp.setHelp(this, IJavaHelpContextIds.OPEN_CLASS_WIZARD_ACTION);
+ }
+*/
+ protected INewWizard createWizard() {
+ return new NewRoleCreationWizard();
+ }
+
+// FIXME(KM): method isnt override anymore - what to use instead? outcommented to get compiled
+/* protected boolean shouldAcceptElement(Object obj) {
+ return isOnBuildPath(obj) && !isInArchive(obj);
+ }
+*/
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OpenTeamWizardAction.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OpenTeamWizardAction.java
new file mode 100644
index 0000000..a8cfad1
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/OpenTeamWizardAction.java
@@ -0,0 +1,52 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: OpenTeamWizardAction.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards;
+
+import org.eclipse.jdt.ui.actions.AbstractOpenWizardAction;
+import org.eclipse.ui.INewWizard;
+
+/**
+ * Action for the team wizard. This action is only used in cheatsheets.
+ *
+ * @author brcan
+ * @version $Id: OpenTeamWizardAction.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class OpenTeamWizardAction extends AbstractOpenWizardAction
+{
+ public OpenTeamWizardAction() {
+// WorkbenchHelp.setHelp(this, IJavaHelpContextIds.OPEN_CLASS_WIZARD_ACTION);
+ }
+/* km: not needed anymore?
+ public OpenTeamWizardAction(String label, Class[] acceptedTypes) {
+ super(label, acceptedTypes, false);
+// WorkbenchHelp.setHelp(this, IJavaHelpContextIds.OPEN_CLASS_WIZARD_ACTION);
+ }
+*/
+ protected INewWizard createWizard() {
+ return new NewTeamCreationWizard();
+ }
+
+// FIXME(KM): method isnt override anymore - what to use instead? outcommented to get compiled
+/* protected boolean shouldAcceptElement(Object obj) {
+ return isOnBuildPath(obj) && !isInArchive(obj);
+ }
+*/
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/listeners/NewRoleWizardPageListener.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/listeners/NewRoleWizardPageListener.java
new file mode 100644
index 0000000..c62a412
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/listeners/NewRoleWizardPageListener.java
@@ -0,0 +1,379 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2008 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: NewRoleWizardPageListener.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards.listeners;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
+import org.eclipse.jdt.core.JavaConventions;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.Signature;
+import org.eclipse.jdt.core.search.IJavaSearchConstants;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.core.search.SearchEngine;
+import org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog;
+import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jdt.internal.corext.util.Messages;
+import org.eclipse.objectteams.otdt.core.IOTType;
+import org.eclipse.objectteams.otdt.core.IRoleType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.internal.core.OTJavaElement;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.NewRoleWizardPage;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.NewTypeWizardPage;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.ui.dialogs.ISelectionStatusValidator;
+
+/**
+ * The main listener class for org.eclipse.objectteams.otdt.internal.ui.wizards.NewRoleWizardPage.
+ * It listens to changes of the entry fields and clicks on the browse buttons
+ * of the observed NewRoleWizardPage.
+ *
+ * @author kaschja
+ * @version $Id: NewRoleWizardPageListener.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class NewRoleWizardPageListener extends NewTypeWizardPageListener
+{
+ protected static final int BASE = 20;
+
+ private IStatus _baseStatus = new StatusInfo();
+ // cache this info (hierarchy operation is expensive)
+ private IType[] fSuperTeams = null;
+
+ public NewRoleWizardPageListener(NewTypeWizardPage observedPage)
+ {
+ super(observedPage);
+ }
+
+ protected int getChangedElement(DialogField field)
+ {
+ if (getObservedPage() instanceof NewRoleWizardPage)
+ {
+ NewRoleWizardPage page = (NewRoleWizardPage) getObservedPage();
+
+ if (field == page.getBaseClassDialogField())
+ {
+ return BASE;
+ }
+ }
+
+ return super.getChangedElement(field);
+ }
+
+ protected void performReviews(int change)
+ {
+ super.performReviews(change);
+
+ if ((change == CONTAINER)
+ || (change == PACKAGE)
+ || (change == ENCLOSINGTYPE)
+ || (change == BASE)
+ || (change == NAME) )
+ {
+ _baseStatus = validateBaseClass();
+ handleImplicitSuperclassDialogField();
+ }
+ }
+
+ protected void handleChangeControlPressed(DialogField field)
+ {
+ if (!(getObservedPage() instanceof NewRoleWizardPage) )
+ {
+ return;
+ }
+ NewRoleWizardPage page = (NewRoleWizardPage) getObservedPage();
+
+ if (field == page.getBaseClassDialogField())
+ {
+ IType type = chooseBaseType();
+ if (type != null)
+ {
+ String str = type.getFullyQualifiedName('.');
+ page.setBaseClassName(str);
+ }
+ }
+ else
+ {
+ super.handleChangeControlPressed(field);
+ }
+ }
+
+ protected IStatus validateTypeName()
+ {
+ // FIXME(SH): admit parameterized name!
+ IStatus superStatus = super.validateTypeName();
+ if (superStatus.getSeverity() == IStatus.ERROR)
+ {
+ return superStatus;
+ }
+
+ NewRoleWizardPage page = (NewRoleWizardPage) getObservedPage();
+
+ String enclosingTypeName = page.getEnclosingTypeName();
+ // strip package name off of enclosing type
+ enclosingTypeName = enclosingTypeName.substring(enclosingTypeName.lastIndexOf('.') + 1);
+
+ String simpleRoleName = page.getTypeName();
+ if (simpleRoleName.equals(enclosingTypeName))
+ {
+ StatusInfo status = new StatusInfo();
+ status.setError(OTNewWizardMessages.NewRole_role_hides_team);
+ return status;
+ }
+
+ return superStatus;
+ }
+
+ protected IType chooseEnclosingType()
+ {
+ IPackageFragmentRoot root= getObservedPage().getPackageFragmentRoot();
+ if (root == null)
+ return null;
+
+ return chooseTeam( root,
+ getObservedPage().getShell(),
+ getObservedPage().getWizard().getContainer(),
+ org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages.NewRoleWizardPage_ChooseEnclosingTypeDialog_title,
+ org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages.NewRoleWizardPage_ChooseEnclosingTypeDialog_description,
+ Signature.getSimpleName(getObservedPage().getEnclosingTypeName()));
+ }
+
+ protected IType chooseSuperType()
+ {
+ IPackageFragmentRoot root = getObservedPage().getPackageFragmentRoot();
+ if (root == null)
+ {
+ return null;
+ }
+
+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { root.getJavaProject() });
+
+ FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(
+ getObservedPage().getShell(),
+ false,
+ getObservedPage().getWizard().getContainer(),
+ scope,
+ IJavaSearchConstants.CLASS);
+ dialog.setTitle(OTNewWizardMessages.NewRoleWizardPage_SuperclassDialog_title);
+ dialog.setMessage(OTNewWizardMessages.NewRoleWizardPage_SuperclassDialog_message);
+ dialog.setInitialPattern(getObservedPage().getSuperTypeName());
+
+ if (dialog.open() == Window.OK)
+ {
+ return (IType) dialog.getFirstResult();
+ }
+ return null;
+ }
+
+ private IType chooseBaseType()
+ {
+ IPackageFragmentRoot root = getObservedPage().getPackageFragmentRoot();
+ if (root == null)
+ {
+ return null;
+ }
+
+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { root.getJavaProject() });
+
+ FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(getObservedPage().getShell(),
+ false,
+ getObservedPage().getWizard().getContainer(),
+ scope,
+ IJavaSearchConstants.TYPE);
+ dialog.setTitle(OTNewWizardMessages.NewRoleWizardPage_BaseclassDialog_title);
+ dialog.setMessage(OTNewWizardMessages.NewRoleWizardPage_BaseclassDialog_message);
+ dialog.setInitialPattern( ((NewRoleWizardPage)getObservedPage()).getBaseClassName());
+ dialog.setValidator(new ISelectionStatusValidator()
+ {
+ public IStatus validate(Object[] selection) {
+ if ( selection != null && selection.length > 0
+ && selection[0] instanceof IType)
+ return validateBaseClassName(
+ getObservedPage().getEnclosingType(),
+ ((IType)selection[0]).getElementName());
+ return StatusInfo.OK_STATUS;
+ };
+ });
+
+ if (dialog.open() == FilteredTypesSelectionDialog.OK)
+ {
+ return (IType) dialog.getFirstResult();
+ }
+ return null;
+ }
+
+ protected void handleEnclosingTypeDialogFieldIsEmpty(StatusInfo status)
+ {
+ status.setError(org.eclipse.jdt.internal.ui.wizards.NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeEnterName);
+ }
+
+ @Override
+ protected IStatus validateEnclosingType() {
+ IStatus status = super.validateEnclosingType();
+ if (status.isOK())
+ cacheSuperTeams();
+ return status;
+ }
+
+ private void cacheSuperTeams() {
+ try {
+ IType enclosingType = this.getObservedPage().getEnclosingType();
+ ITypeHierarchy hierarchy = enclosingType.newSupertypeHierarchy(null);
+ fSuperTeams = hierarchy.getAllSuperclasses(enclosingType);
+ }
+ catch (JavaModelException ex) {
+ OTDTUIPlugin.getExceptionHandler().logException("Problems creating supertype hierarchy", ex); //$NON-NLS-1$
+ }
+ }
+
+ // ------ validation --------
+ public IStatus[] getRelevantStates(boolean ignoreFirstField)
+ {
+ if (ignoreFirstField)
+ return new IStatus[]
+ {
+ getObservedPage().getContainerStatus(),
+ _packageStatus,
+ _enclosingTeamStatus,
+ // not this one: _typeNameStatus,
+ _baseStatus,
+ _modifierStatus,
+ _superTypeStatus,
+ _superInterfacesStatus,
+ };
+ else
+ // status of all used components
+ return new IStatus[]
+ {
+ getObservedPage().getContainerStatus(),
+ _packageStatus,
+ _enclosingTeamStatus,
+ _typeNameStatus,
+ _baseStatus,
+ _modifierStatus,
+ _superTypeStatus,
+ _superInterfacesStatus,
+ };
+ }
+
+ private void handleImplicitSuperclassDialogField()
+ {
+ if (!(getObservedPage() instanceof NewRoleWizardPage))
+ return;
+
+ NewRoleWizardPage page = (NewRoleWizardPage) getObservedPage();
+ page.setImplicitSuperclassName(""); //$NON-NLS-1$
+
+ if (hasTypeNameError()) // don't proceed if there is an error already
+ return;
+
+ IType enclosingTeam = page.getEnclosingType();
+
+ if (enclosingTeam != null)
+ {
+ if (fSuperTeams == null)
+ cacheSuperTeams();
+
+ for (int idx = 0; idx < fSuperTeams.length; idx++)
+ {
+ IType memberType = fSuperTeams[idx].getType(page.getTypeName());
+ IOTType otType = OTModelManager.getOTElement(memberType);
+
+ if (otType != null && otType instanceof IRoleType)
+ {
+ String fullQualName = memberType.getFullyQualifiedName('.');
+ page.setImplicitSuperclassName(fullQualName);
+ return;
+ }
+ }
+ }
+ }
+
+ private boolean hasTypeNameError()
+ {
+ IStatus[] stati = new IStatus[] {
+ getObservedPage().getContainerStatus(),
+ _packageStatus,
+ _enclosingTeamStatus,
+ _typeNameStatus
+ };
+
+ return hasErrorStatus(stati);
+ }
+
+ private IStatus validateBaseClass()
+ {
+ NewRoleWizardPage page = (NewRoleWizardPage) getObservedPage();
+ String baseclassName = page.getBaseClassName();
+
+ if (baseclassName.length() == 0)
+ return StatusInfo.OK_STATUS; // a Role without a playedBy relation is just fine
+
+ // ERRORS:
+ IStatus validJava = JavaConventions.validateJavaTypeName(baseclassName);
+ if (validJava.getSeverity() == IStatus.ERROR)
+ return new StatusInfo(IStatus.ERROR,
+ Messages.format(org.eclipse.jdt.internal.ui.wizards.NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName,
+ validJava.getMessage()));
+
+ // check shadowing (ERROR):
+ IType enclosingType = getObservedPage().getEnclosingType();
+ IStatus status = validateBaseClassName(enclosingType, baseclassName);
+ if (!status.isOK())
+ return status;
+
+ // WARNINGS:
+ if (validJava.getSeverity() == IStatus.WARNING)
+ return new StatusInfo(IStatus.WARNING,
+ Messages.format(org.eclipse.jdt.internal.ui.wizards.NewWizardMessages.NewTypeWizardPage_warning_TypeNameDiscouraged,
+ validJava.getMessage()));
+
+ return StatusInfo.OK_STATUS;
+ }
+
+ IStatus validateBaseClassName(IType enclosingType, String name) {
+ while (enclosingType != null) {
+ if (name.equals(enclosingType.getElementName())) {
+ return new StatusInfo(StatusInfo.ERROR,
+ Messages.format(
+ OTNewWizardMessages.NewRole_base_class_equals_enclosing,
+ name));
+ }
+ try {
+ for (IJavaElement member : enclosingType.getChildren()) {
+ if ( member.getElementType() == OTJavaElement.ROLE
+ && member.getElementName().equals(name))
+ return new StatusInfo(StatusInfo.ERROR,
+ Messages.format(
+ OTNewWizardMessages.NewRole_base_class_equals_member,
+ name));
+ }
+ } catch (JavaModelException e) { /* nop */ }
+ enclosingType = enclosingType.getDeclaringType();
+ }
+ return StatusInfo.OK_STATUS;
+ }
+
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/listeners/NewTeamWizardPageListener.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/listeners/NewTeamWizardPageListener.java
new file mode 100644
index 0000000..289203f
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/listeners/NewTeamWizardPageListener.java
@@ -0,0 +1,256 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2008 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: NewTeamWizardPageListener.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards.listeners;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.corext.util.Messages;
+import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFieldGroup;
+import org.eclipse.objectteams.otdt.core.IOTType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.core.compiler.IOTConstants;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.NewTeamWizardPage;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.NewTypeWizardPage;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+
+
+/**
+ * The main listener class for org.eclipse.objectteams.otdt.internal.ui.wizards.NewTeamWizardPage.
+ * It listens to changes of the entry fields and clicks on the browse buttons
+ * of the observed NewTeamWizardPage
+ *
+ *
+ * @author kaschja
+ * @version $Id: NewTeamWizardPageListener.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class NewTeamWizardPageListener extends NewTypeWizardPageListener
+{
+
+ public NewTeamWizardPageListener(NewTeamWizardPage observedPage)
+ {
+ super(observedPage);
+ }
+
+
+ protected IType chooseSuperType()
+ {
+ IPackageFragmentRoot root= getObservedPage().getPackageFragmentRoot();
+ if (root == null)
+ {
+ return null;
+ }
+
+ return chooseTeam(root.getJavaProject(),
+ getObservedPage().getShell(),
+ getObservedPage().getWizard().getContainer(),
+ OTNewWizardMessages.NewTeamWizardPage_ChooseSuperTypeDialog_title,
+ OTNewWizardMessages.NewTeamWizardPage_ChooseSuperTypeDialog_description,
+ getObservedPage().getSuperTypeName());
+ }
+
+ // ------ validation --------
+ public IStatus[] getRelevantStates(boolean ignoreFirstField)
+ {
+ if (ignoreFirstField)
+ return new IStatus[] {
+ getObservedPage().getContainerStatus(),
+
+ _packageStatus,
+ _enclosingTeamStatus,
+
+ // not this one: _typeNameStatus,
+ _modifierStatus,
+ _superTypeStatus,
+ _superInterfacesStatus
+
+ };
+ else
+ // status of all used components
+ return new IStatus[]
+ {
+ getObservedPage().getContainerStatus(),
+
+ _packageStatus,
+ _enclosingTeamStatus,
+
+ _typeNameStatus,
+ _modifierStatus,
+ _superTypeStatus,
+ _superInterfacesStatus
+ };
+ }
+
+
+ protected IStatus validateEnclosingType()
+ {
+ IStatus status = super.validateEnclosingType();
+ if ( status.getSeverity() == IStatus.ERROR )
+ {
+ //deselect and disable Inlined-Checkbox
+ getObservedPage().getInlineSelectionDialogField().setSelection(false);
+ getObservedPage().getInlineSelectionDialogField().setEnabled(false);
+ }
+ handleAccessModifierButtons();
+ getObservedPage().updateEnableState();
+ return status;
+ }
+
+ @Override
+ void validateSuperClass(StatusInfo status) {
+ super.validateSuperClass(status);
+
+ // deselect Bindingeditor when supertype == o.o.Team
+ IType superType = getObservedPage().getSuperType();
+ if (superType == null)
+ return;
+ IOTType superTeam = OTModelManager.getOTElement(superType);
+ if (! superType.getFullyQualifiedName().equals(String.valueOf(IOTConstants.STR_ORG_OBJECTTEAMS_TEAM)) && superTeam != null)
+ {
+ SelectionButtonDialogFieldGroup bindingEditorGroup = ((NewTeamWizardPage)getObservedPage()).getBindingEditorButtons();
+ bindingEditorGroup.setEnabled(true);
+ }
+ }
+
+ protected void handleEnclosingTypeDialogFieldIsEmpty(StatusInfo status)
+ {
+ getObservedPage().getPackageDialogField().setEnabled(true);
+
+ //disable Inlined-Checkbox
+ getObservedPage().getInlineSelectionDialogField().setSelection(false);
+ getObservedPage().getInlineSelectionDialogField().setEnabled(false);
+
+ super.handleEnclosingTypeDialogFieldIsEmpty(status);
+ }
+
+ protected void handleAccessModifierButtons()
+ {
+ SelectionButtonDialogFieldGroup modifierButtons = getObservedPage().getAccessModifierButtons();
+
+ if (getObservedPage().getEnclosingTypeName().equals("")) //$NON-NLS-1$
+ {
+ int modifiers = getObservedPage().getModifiers();
+ if (Flags.isPrivate(modifiers) || Flags.isProtected(modifiers))
+ {
+ modifierButtons.setSelection(NewTypeWizardPage.PRIVATE_INDEX, false);
+ modifierButtons.setSelection(NewTypeWizardPage.PROTECTED_INDEX, false);
+ modifierButtons.setSelection(NewTypeWizardPage.PUBLIC_INDEX, true);
+ }
+ modifierButtons.enableSelectionButton(NewTypeWizardPage.PRIVATE_INDEX, false);
+ modifierButtons.enableSelectionButton(NewTypeWizardPage.PROTECTED_INDEX, false);
+ }
+ else
+ {
+ modifierButtons.enableSelectionButton(NewTypeWizardPage.PRIVATE_INDEX, true);
+ modifierButtons.enableSelectionButton(NewTypeWizardPage.PROTECTED_INDEX, true);
+ }
+ }
+
+
+ /**
+ * Gets called when the package field has changed. The method
+ * validates the package name and returns the status of the validation.
+ * The validation also updates the package fragment model.
+ *
+ * @return the status of the validation
+ */
+ protected IStatus validatePackage() {
+ StatusInfo status = new StatusInfo();
+
+ updatePackageStatusLabel();
+ getObservedPage().getPackageDialogField().enableButton(getObservedPage().getPackageFragmentRoot() != null);
+
+ String packName = getObservedPage().getPackageName();
+ if (packName.trim().length() > 0)
+ {
+ IStatus val = NewTypeWizardPage.validatePackageName(packName, getObservedPage().getJavaProject());
+ if (val.getSeverity() == IStatus.ERROR)
+ {
+ status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName, val.getMessage()));
+ return status;
+ }
+ else if (val.getSeverity() == IStatus.WARNING)
+ {
+ status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage()));
+ // continue
+ }
+ }
+
+ IPackageFragmentRoot root = getObservedPage().getPackageFragmentRoot();
+ if (root != null)
+ {
+ if (root.getJavaProject().exists() && packName.trim().length() > 0)
+ {
+ try
+ {
+ IPath rootPath = root.getPath();
+ IPath outputPath = root.getJavaProject().getOutputLocation();
+
+ if (rootPath.isPrefixOf(outputPath)
+ && !rootPath.equals(outputPath))
+ {
+ // if the bin folder is inside of our root, dont allow to name a package
+ // like the bin folder
+ IPath packagePath = rootPath.append(packName.replace('.', '/'));
+
+ if (outputPath.isPrefixOf(packagePath))
+ {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation);
+ return status;
+ }
+ }
+ }
+ catch (JavaModelException ex)
+ {
+ OTDTUIPlugin.getExceptionHandler().logCoreException("", ex); //$NON-NLS-1$
+ // let pass
+ }
+ }
+ getObservedPage().setPackageFragment(root.getPackageFragment(packName), true);
+ }
+ else
+ {
+ status.setError(""); //$NON-NLS-1$
+ }
+ return status;
+ }
+
+
+ protected void updatePackageStatusLabel() {
+ String packName = getObservedPage().getPackageName();
+
+ if (packName.length() == 0)
+ {
+ getObservedPage().getPackageDialogField().setStatus(NewWizardMessages.NewTypeWizardPage_default);
+ }
+ else
+ {
+ getObservedPage().getPackageDialogField().setStatus(""); //$NON-NLS-1$
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/listeners/NewTypeWizardPageListener.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/listeners/NewTypeWizardPageListener.java
new file mode 100644
index 0000000..059b1ec
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/listeners/NewTypeWizardPageListener.java
@@ -0,0 +1,908 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: NewTypeWizardPageListener.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards.listeners;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.Type;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.internal.corext.refactoring.TypeContextChecker;
+import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
+import org.eclipse.jdt.internal.corext.util.Messages;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
+import org.eclipse.jdt.internal.ui.wizards.SuperInterfaceSelectionDialog;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
+import org.eclipse.jdt.ui.JavaElementLabelProvider;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.IWizardContainer;
+import org.eclipse.objectteams.otdt.core.IOTType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.core.search.OTSearchEngine;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.NewTeamWizardPage;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.NewTypeWizardPage;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.objectteams.otdt.ui.dialogs.TeamSelectionDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+
+
+/**
+ * The main listener class for org.eclipse.objectteams.otdt.internal.ui.wizards.NewTypeWizardPage.
+ * It listens to changes of the entry fields and clicks on the browse buttons
+ * of the observed NewTypeWizardPage.
+ *
+ * @author kaschja
+ * @version $Id: NewTypeWizardPageListener.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public abstract class NewTypeWizardPageListener implements IStringButtonAdapter,
+ IDialogFieldListener,
+ IListAdapter
+{
+ protected static final int CONTAINER = 1;
+ protected static final int PACKAGE = 2;
+ protected static final int ENCLOSINGTYPE = 3;
+ protected static final int NAME = 4;
+ protected static final int SUPERTYPE = 5;
+ protected static final int SUPERINTERFACES = 6;
+ protected static final int ENCLOSINGTYPESELECTION = 7;
+
+ protected IStatus _packageStatus = new StatusInfo();
+ protected IStatus _enclosingTeamStatus = new StatusInfo();
+ protected IStatus _typeNameStatus = new StatusInfo();
+ protected IStatus _modifierStatus = new StatusInfo();
+ protected IStatus _superTypeStatus = new StatusInfo();
+ protected IStatus _superInterfacesStatus = new StatusInfo();
+
+ private NewTypeWizardPage _observedPage;
+
+
+ public NewTypeWizardPageListener(NewTypeWizardPage observedPage)
+ {
+ _observedPage = observedPage;
+ }
+
+//------------------------------------------------------------------------------
+
+ // -------- IStringButtonAdapter
+ /**
+ * gets called when a browse button of the observed wizard page is clicked
+ */
+ public void changeControlPressed(DialogField field)
+ {
+ handleChangeControlPressed(field);
+ }
+
+ // -------- IDialogFieldListener
+ /**
+ * gets called when the content of a dialog field of the observed wizard page
+ * has changed
+ */
+ public void dialogFieldChanged(DialogField field)
+ {
+ if (field == _observedPage.getTypeNameDialogField())
+ _observedPage.publicTypeNameChanged(); // will eventually set _observedPage._currentType
+ int changedElement = getChangedElement(field);
+ performReviews(changedElement);
+ updateStatus();
+ }
+
+ public void doubleClicked(ListDialogField field)
+ {
+ }
+
+ //-------- IListAdapter
+ /**
+ * gets called when the add interface button of the observed page is clicked
+ */
+ public void customButtonPressed(ListDialogField field, int index)
+ {
+ chooseSuperInterfaces(field);
+ }
+ public void selectionChanged(ListDialogField field) {}
+
+//------------------------------------------------------------------------------
+
+ protected NewTypeWizardPage getObservedPage()
+ {
+ return _observedPage;
+ }
+
+ protected int getChangedElement(DialogField field)
+ {
+ int change = 0;
+
+ if (field == getObservedPage().getPackageDialogField())
+ {
+ change = PACKAGE;
+ }
+ else if (field == getObservedPage().getEnclosingTypeDialogField())
+ {
+ change = ENCLOSINGTYPE;
+ }
+ else if (field == getObservedPage().getInlineSelectionDialogField())
+ {
+ }
+ else if (field == getObservedPage().getTypeNameDialogField())
+ {
+ change = NAME;
+ }
+ else if (field == getObservedPage().getSuperTypeDialogField())
+ {
+ change = SUPERTYPE;
+ }
+ else if (field == getObservedPage().getSuperInterfacesDialogField())
+ {
+ change = SUPERINTERFACES;
+ }
+ else if (field == getObservedPage().getEnclosingTypeSelectionField())
+ {
+ change = ENCLOSINGTYPESELECTION;
+ }
+
+ return change;
+ }
+
+ /**
+ * After calling this method, call updateStatus() to reflect the review-status in the UI.
+ * @param change The dialog field, that was changed, one of CONTAINER, PACKAGE, ENCLOSINGTYPE...
+ */
+ protected void performReviews(int change)
+ {
+ switch (change)
+ {
+ case CONTAINER :
+ _packageStatus = validatePackage();
+ _enclosingTeamStatus = validateEnclosingType();
+ _typeNameStatus = validateTypeName();
+ _superTypeStatus = validateSuperType();
+ _superInterfacesStatus = validateSuperInterfaces();
+ break;
+
+ case PACKAGE:
+ _packageStatus = validatePackage();
+ _enclosingTeamStatus = validateEnclosingType();
+ _typeNameStatus = validateTypeName();
+ break;
+
+ case ENCLOSINGTYPE:
+ _enclosingTeamStatus = validateEnclosingType();
+ _typeNameStatus = validateTypeName();
+ break;
+ case ENCLOSINGTYPESELECTION:
+ _packageStatus = validatePackage();
+ _enclosingTeamStatus = validateEnclosingType();
+ _typeNameStatus = validateTypeName();
+ break;
+ case NAME:
+ _typeNameStatus = validateTypeName();
+ break;
+
+ case SUPERTYPE:
+ _superTypeStatus = validateSuperType();
+
+ case SUPERINTERFACES:
+ validateSuperInterfaces();
+
+ default :
+ break;
+ }
+ }
+
+ protected void handleChangeControlPressed(DialogField field)
+ {
+ if (field == getObservedPage().getPackageDialogField())
+ {
+ IPackageFragment pack= choosePackage();
+ if (pack != null)
+ {
+ getObservedPage().setPackageFragmentName(pack.getElementName());
+ }
+ }
+ else if (field == getObservedPage().getEnclosingTypeDialogField())
+ {
+ IType type= chooseEnclosingType();
+
+ if (type != null)
+ {
+ String packageName = type.getPackageFragment().getElementName();
+ getObservedPage().setPackageFragmentName(packageName);
+ String qualifiedTeam = type.getFullyQualifiedName('.');
+ getObservedPage().setEnclosingTypeName(qualifiedTeam);
+ }
+ }
+ else if (field == getObservedPage().getSuperTypeDialogField())
+ {
+ IType supertype = chooseSuperType();
+
+ if (supertype != null)
+ {
+ getObservedPage().setSuperTypeName(supertype.getFullyQualifiedName('.'));
+ }
+ }
+ }
+
+ private IPackageFragment choosePackage()
+ {
+ IPackageFragmentRoot froot = getObservedPage().getPackageFragmentRoot();
+ IJavaElement[] packages = null;
+ try
+ {
+ if (froot != null && froot.exists())
+ {
+ packages= froot.getChildren();
+ }
+ }
+ catch (JavaModelException ex)
+ {
+ OTDTUIPlugin.getExceptionHandler().logCoreException(null, ex);
+ }
+
+ if (packages == null)
+ {
+ packages= new IJavaElement[0];
+ }
+
+ ElementListSelectionDialog dialog = new ElementListSelectionDialog(getObservedPage().getShell(),
+ new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT));
+ dialog.setIgnoreCase(false);
+ dialog.setTitle(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_title);
+ dialog.setMessage(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_description);
+ dialog.setEmptyListMessage(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_empty);
+ dialog.setElements(packages);
+ IPackageFragment pack = getObservedPage().getPackageFragment();
+
+ if (pack != null)
+ {
+ dialog.setInitialSelections(new Object[] { pack });
+ }
+
+ if (dialog.open() == ElementListSelectionDialog.OK)
+ {
+ return (IPackageFragment) dialog.getFirstResult();
+ }
+ return null;
+ }
+
+ // TODO(SH): this method could easily be reused by clients, look for better location then.
+ public static IType chooseTeam(IJavaElement searchScope, Shell shell, IWizardContainer container, String dialogTitle, String dialogMessage, String filter)
+ {
+ IJavaSearchScope scope= OTSearchEngine.createOTSearchScope(new IJavaElement[] { searchScope }, true);
+ TeamSelectionDialog dialog = new TeamSelectionDialog(shell, container, scope);
+ dialog.setTitle(dialogTitle);
+ dialog.setMessage(dialogMessage);
+ dialog.setFilter(filter);
+
+
+ if (dialog.open() == Window.OK)
+ return (IType) dialog.getFirstResult();
+
+ return null;
+ }
+
+ protected abstract IType chooseSuperType();
+
+ private void chooseSuperInterfaces(ListDialogField field)
+ {
+ IPackageFragmentRoot root= getObservedPage().getPackageFragmentRoot();
+ if (root == null)
+ {
+ return;
+ }
+
+ SuperInterfaceSelectionDialog dialog;
+
+
+ Shell parent = getObservedPage().getShell();
+ IRunnableContext context = getObservedPage().getWizard().getContainer();
+ NewTypeWizardPage page = getObservedPage();
+ IJavaProject root2 = root.getJavaProject();
+
+ dialog = new SuperInterfaceSelectionDialog(parent, context, page, root2);
+/* dialog = new SuperInterfaceSelectionDialog(getObservedPage().getShell(),
+ getObservedPage().getWizard().getContainer(),
+ getObservedPage(),
+ root.getJavaProject());
+*/ dialog.setTitle( NewWizardMessages.NewTypeWizardPage_InterfacesDialog_class_title);
+ dialog.setMessage(NewWizardMessages.NewTypeWizardPage_InterfacesDialog_message);
+ dialog.open();
+ return;
+ }
+
+ protected IType chooseEnclosingType()
+ {
+ return getObservedPage().chooseEnclosingType();
+ }
+
+ protected boolean hasErrorStatus(IStatus[] stati)
+ {
+ for (int i = 0; i < stati.length; i++)
+ {
+ if (stati[i] != null && stati[i].getSeverity() == IStatus.ERROR)
+ return true;
+ }
+
+ return false;
+ }
+
+ public abstract IStatus[] getRelevantStates(boolean ignoreFirstField);
+
+ protected void updateStatus()
+ {
+ // the most severe status will be displayed and the ok button enabled/disabled.
+ getObservedPage().updateStatus(getRelevantStates(false));
+ }
+
+ /**
+ * Gets called when the type name has changed. The method validates the
+ * type name and returns the status of the validation.
+ *
+ * @return the status of the validation
+ */
+ protected IStatus validateTypeName()
+ {
+ StatusInfo status = new StatusInfo();
+ String typeName = getObservedPage().getTypeName();
+
+ // must not be empty
+ if (typeName.length() == 0)
+ {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_EnterTypeName);
+ return status;
+ }
+ if (typeName.indexOf('.') != -1)
+ {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_QualifiedName);
+ return status;
+ }
+ IStatus val = NewTypeWizardPage.validateJavaTypeName(typeName, getObservedPage().getJavaProject());
+ if (val.getSeverity() == IStatus.ERROR)
+ {
+ status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, val.getMessage()));
+ return status;
+ }
+ else if (val.getSeverity() == IStatus.WARNING)
+ {
+ status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_TypeNameDiscouraged, val.getMessage()));
+ // continue checking
+ }
+
+ // role file must not exist
+ IType enclosingTeam = getObservedPage().getEnclosingType();
+ IPackageFragment pack = getObservedPage().getPackageFragment();
+ if ((pack == null) && (enclosingTeam != null)) // manually create package via team
+ {
+ pack = getTeamPackage(enclosingTeam);
+ }
+
+ if (pack != null)
+ {
+ ICompilationUnit cu = pack.getCompilationUnit(typeName + ".java"); //$NON-NLS-1$
+ if (cu.getResource().exists())
+ {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
+ return status;
+ }
+ }
+ // inlined role must not exist
+ if (enclosingTeam != null)
+ {
+ IType member = enclosingTeam.getType(typeName);
+ {
+ if (member.exists())
+ {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
+ return status;
+ }
+ }
+ }
+
+ validateSuperClass(status);
+
+ return status;
+ }
+
+ /**
+ * @param teamType the team (maybe nested) to look up the team package for
+ * @return the team package, which may not physically exist or null if an exception occurred.
+ */
+ private IPackageFragment getTeamPackage(IType teamType)
+ {
+ String enclosingTeamName = teamType.getTypeQualifiedName('/'); // e.g. "Outer/Inner/MostInner"
+ try {
+ IPath teamPackagePath = teamType.getPackageFragment().getPath();
+ teamPackagePath = teamPackagePath.append(enclosingTeamName);
+ return teamType.getJavaProject().findPackageFragment(teamPackagePath);
+ }
+ catch (JavaModelException ex)
+ {
+ // package does not exist
+ }
+ return null;
+ }
+
+ /**
+ * Gets called when the enclosing type name has changed. The method
+ * validates the enclosing type and returns the status of the validation.
+ * It also updates the enclosing type model.
+ *
+ * @return the status of the validation
+ */
+ protected IStatus validateEnclosingType()
+ {
+ StatusInfo status = new StatusInfo();
+ getObservedPage().setEnclosingType(null, true);
+
+ IPackageFragmentRoot root = getObservedPage().getPackageFragmentRoot();
+ if (root == null)
+ {
+ status.setError(""); //$NON-NLS-1$
+ return status;
+ }
+
+ String enclName = getObservedPage().getEnclosingTypeName();
+ if (enclName.trim().length() == 0)
+ {
+ handleEnclosingTypeDialogFieldIsEmpty(status);
+ return status;
+ }
+ else
+ {
+ if (_observedPage instanceof NewTeamWizardPage)
+ {
+ _observedPage.getPackageDialogField().setEnabled(false);
+ }
+ }
+
+ try
+ {
+ IType type = root.getJavaProject().findType(enclName);
+
+ if (type == null)
+ {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeNotExists);
+ }
+ else if (type.getCompilationUnit() == null)
+ {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingNotInCU);
+ }
+ else if (!JavaModelUtil.isEditable(type.getCompilationUnit()))
+ {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingNotEditable);
+ }
+ else if (type.equals(getObservedPage().getSuperType()))
+ {
+ status.setError(org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages.NewTypeWizardPage_same_enclosing_and_super_error);
+ }
+
+ if (status.isError())
+ {
+ return status;
+ }
+
+ getObservedPage().setEnclosingType(type, true);
+
+ IPackageFragmentRoot enclosingRoot = JavaModelUtil.getPackageFragmentRoot(type);
+ if (!enclosingRoot.equals(root))
+ {
+ status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_EnclosingNotInSourceFolder);
+ }
+
+ validateSuperClass(status);
+
+ //enable Inlined-Checkbox
+ getObservedPage().getInlineSelectionDialogField().setEnabled(true);
+ return status;
+ }
+ catch (JavaModelException ex)
+ {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeNotExists);
+ OTDTUIPlugin.getExceptionHandler().logCoreException("", ex); //$NON-NLS-1$
+ return status;
+ }
+ }
+
+ protected void handleEnclosingTypeDialogFieldIsEmpty(StatusInfo status)
+ {
+ validateSuperClass(status);
+ }
+
+ /**
+ * Gets called when the package field has changed. The method
+ * validates the package name and returns the status of the validation.
+ * The validation also updates the package fragment model.
+ *
+ * @return the status of the validation
+ */
+ protected IStatus validatePackage() {
+ return new StatusInfo(); // default: nothing to check
+ }
+
+ /**
+ * Gets called when the list of super interface has changed. The method
+ * validates the superinterfaces and returns the status of the validation.
+ *
+ * @return the status of the validation
+ */
+ protected IStatus validateSuperInterfaces()
+ {
+ StatusInfo status = new StatusInfo();
+
+ IPackageFragmentRoot root = getObservedPage().getPackageFragmentRoot();
+ getObservedPage().getSuperInterfacesDialogField().enableButton(
+ 0,
+ root != null);
+
+ if (root != null)
+ {
+ List elements = getObservedPage().getSuperInterfaces();
+ int nElements = elements.size();
+ for (int i = 0; i < nElements; i++)
+ {
+ String intfname = (String) elements.get(i);
+ Type type= TypeContextChecker.parseSuperInterface(intfname);
+ if (type == null) {
+ status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperInterfaceName, intfname));
+ return status;
+ }
+ }
+ }
+ return status;
+ }
+
+ /**
+ * Gets called when the superclass name has changed. The method
+ * validates the superclass name and returns the status of the validation.
+ *
+ * @return the status of the validation
+ */
+ protected IStatus validateSuperType()
+ {
+ StatusInfo status = new StatusInfo();
+ IPackageFragmentRoot root = getObservedPage().getPackageFragmentRoot();
+ getObservedPage().getSuperTypeDialogField().enableButton(root != null);
+
+ getObservedPage().setSuperType(null);
+
+ String superTypeName = getObservedPage().getSuperTypeName();
+ if (superTypeName.trim().length() == 0)
+ {
+ // accept the empty field (stands for java.lang.Object)
+ return status;
+ }
+ IStatus val = NewTypeWizardPage.validateJavaTypeName(superTypeName, getObservedPage().getJavaProject());
+ if (val.getSeverity() == IStatus.ERROR)
+ {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperClassName);
+ return status;
+ }
+ if (root != null)
+ {
+ try
+ {
+ Type type= TypeContextChecker.parseSuperClass(superTypeName);
+ if (type == null) {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperClassName);
+ return status;
+ }
+ IType iType = resolveSuperTypeName(root.getJavaProject(), superTypeName);
+ if (iType == null) {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperClassName);
+ return status;
+ }
+ if (iType.equals(getObservedPage().getEnclosingType()))
+ {
+ status.setError(org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages.NewTypeWizardPage_same_enclosing_and_super_error);
+ }
+ getObservedPage().setSuperType(iType);
+ validateSuperClass(status);
+ }
+ catch (JavaModelException e)
+ {
+ status.setError(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperClassName);
+ JavaPlugin.log(e);
+ }
+ }
+ else
+ {
+ status.setError(""); //$NON-NLS-1$
+ }
+ return status;
+ }
+
+ private IType resolveSuperTypeName(IJavaProject jproject, String supertypeName)
+ throws JavaModelException
+ {
+ if (!jproject.exists())
+ {
+ return null;
+ }
+ IType supertype = null;
+
+ //TODO (kaschja): handle case of external defined role class
+ //innerclass (internal defined role class)
+ if ( (getObservedPage().getEnclosingType() != null)
+ && (getObservedPage().isInlineTypeSelected()) )
+ {
+ // search in the context of the enclosing type
+ IType enclosingType = getObservedPage().getEnclosingType();
+
+ String[][] res = enclosingType.resolveType(supertypeName);
+ if (res != null && res.length > 0)
+ {
+ supertype = jproject.findType(res[0][0], res[0][1]);
+ }
+ }
+ else
+ {
+ IPackageFragment currPack = getObservedPage().getPackageFragment();
+ if (currPack != null)
+ {
+ String packName = currPack.getElementName();
+ // search in own package
+ if (!currPack.isDefaultPackage())
+ {
+ supertype = jproject.findType(packName, supertypeName);
+ }
+ // search in java.lang
+ if (supertype == null && !"java.lang".equals(packName)) //$NON-NLS-1$
+ {
+ supertype = jproject.findType("java.lang", supertypeName); //$NON-NLS-1$
+ }
+ }
+ // search fully qualified
+ if (supertype == null)
+ {
+ supertype = jproject.findType(supertypeName);
+ }
+ }
+ return supertype;
+ }
+
+ /**
+ * workaround
+ *
+ * The containerDialogField of the observed NewTypeWizardPage
+ * is defined in a superclass and declared private. That's why this listener
+ * cannot be registered to this dialog field. So its dialogFieldChanged method
+ * does not get called when the container dialog field has changed.
+ * Fortunately the observed NewTypeWizardPage gets informed about changes of
+ * this dialog field via its superclass hook method handleFieldChanged.
+ * So it can inform its listener by calling this method.
+ *
+ * simulates call of handleDialogFieldChanged
+ */
+ public void handleContainerChanged()
+ {
+ //TODO (kaschja): check if the container is inside a or itself an OTProject
+ // getObservedPage().getPackageFragmentRoot().getJavaProject().getProject().getNature(natureId);
+
+ performReviews(CONTAINER);
+ updateStatus();
+ }
+
+
+ void validateSuperClass(StatusInfo status)
+ {
+
+ IType superType = getObservedPage().getSuperType();
+ IType enclosingType = getObservedPage().getEnclosingType();
+ String newRoleName = getObservedPage().getTypeName().trim();
+
+ IOTType superTypeOTElem = null;
+
+ if (superType == null)
+ return;
+
+ superTypeOTElem = OTModelManager.getOTElement(superType);
+
+ try {
+ if ( (superTypeOTElem != null) && superTypeOTElem.isRole() )
+ {
+ checkSuperRoleType(status, enclosingType, superType, newRoleName);
+
+ if (status.isError())
+ return;
+ }
+
+ // TODO (carp): check if this works
+// old TODO (kaschja) comment the following section in by the time IType.newSuperTypeHierarchy works properly for role classes
+// if ( isTypeToBeCreatedARole() && ! newRoleName.equals("") )
+// {
+// checkImplicitRoleHierarchyForExplicitSuperClass(status, enclosingType, superType, newRoleName);
+// }
+
+ }
+ catch (JavaModelException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+
+ private void checkSuperRoleType(StatusInfo status, IType enclosingType, IType superType, String newRoleName) throws JavaModelException
+ {
+ if ( ! isTypeToBeCreatedARole() )
+ {
+ status.setError(org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages.NewTypeWizardPage_super_of_regular_is_role_error);
+ return;
+ }
+
+ if ( ! isSuperRolesTeamContainedInEnclosingTypesHierarchy(enclosingType, superType) )
+ {
+ status.setError(org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages.NewRoleWizardPage_super_is_role_of_different_team_error);
+ return;
+ }
+
+ if ( newRoleName.equals( superType.getElementName() ) )
+ {
+ status.setError(org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages.NewRoleWizardPage_explicit_and_implicit_subclassing_error);
+ return;
+ }
+
+ if ( hasSuperroleOverridingImplicitSubrole(enclosingType, superType) )
+ {
+ status.setError(org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages.NewRoleWizardPage_super_is_overridden_error);
+ return;
+ }
+ }
+
+ /**
+ * checks if the role that is to be created
+ * has already an explicit superclass
+ * (that is the role that is to be created has an implicit superrole which has an explicit superclass)
+ * and if so
+ * the class that is intended to be the explicit superclass of the role that is to be created
+ * must be a subclass of the existing explicit superclass
+ * otherwise the status is set to ERROR
+ *
+ * FIXME(SH): add a call to this method!
+ */
+ private void checkImplicitRoleHierarchyForExplicitSuperClass(StatusInfo status, IType enclosingType, IType superType, String newRoleName)
+ throws JavaModelException
+ {
+ IType explicitSuperclassOfImplicitSuperrole = getExplicitSuperclassOfImplicitSuperrole(enclosingType, newRoleName);
+
+ if (explicitSuperclassOfImplicitSuperrole != null)
+ {
+ if (explicitSuperclassOfImplicitSuperrole.getFullyQualifiedName().equals(superType.getFullyQualifiedName()))
+ {
+ status.setInfo(Messages.format(
+ org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages.NewRoleWizardPage_already_has_this_super,
+ superType.getFullyQualifiedName()));
+ return;
+ }
+
+ ITypeHierarchy superTypeHierarchy = superType.newSupertypeHierarchy(new NullProgressMonitor());
+
+ if ( !superTypeHierarchy.contains(explicitSuperclassOfImplicitSuperrole))
+ {
+ status.setError(Messages.format(
+ org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages.NewRoleWizardPage_incompatible_supers_error,
+ explicitSuperclassOfImplicitSuperrole.getFullyQualifiedName()));
+ return;
+ }
+ }
+ }
+
+ private IType getExplicitSuperclassOfImplicitSuperrole(IType teamType, String roleSimpleName) throws JavaModelException
+ {
+ IOTType teamOTElem = OTModelManager.getOTElement(teamType);
+
+ if ( (teamOTElem == null) || (!teamOTElem.isTeam()) )
+ {
+ return null;
+ }
+
+ ITypeHierarchy teamSuperHierarchy = teamType.newSupertypeHierarchy(null);
+ IType[] superTeams = teamSuperHierarchy.getAllSuperclasses(teamType);
+ IType curRole = null;
+ ITypeHierarchy explicitRoleSuperHierarchy = null;
+
+ for (int idx = 0; idx < superTeams.length; idx++)
+ {
+ curRole = superTeams[idx].getType(roleSimpleName);
+ if (curRole.exists())
+ {
+ explicitRoleSuperHierarchy = curRole.newSupertypeHierarchy(null);
+ if (explicitRoleSuperHierarchy.getSuperclass(curRole) != null)
+ {
+ return explicitRoleSuperHierarchy.getSuperclass(curRole);
+ }
+ }
+ }
+ return null;
+ }
+
+ private boolean isTypeToBeCreatedARole()
+ {
+ IType enclosingType = getObservedPage().getEnclosingType();
+
+ if (enclosingType == null)
+ {
+ return false;
+ }
+ IOTType enclosingTypeOTElem = OTModelManager.getOTElement(enclosingType);
+
+ if ( (enclosingTypeOTElem == null) || ( ! enclosingTypeOTElem.isTeam()) )
+ {
+ return false;
+ }
+ return true;
+ }
+
+ private boolean isSuperRolesTeamContainedInEnclosingTypesHierarchy(IType enclosingTeam, IType superRole)
+ throws JavaModelException
+ {
+ ITypeHierarchy teamHierarchy = enclosingTeam.newSupertypeHierarchy(null);
+ IType teamOfSuperType = superRole.getDeclaringType();
+
+ if ( ! teamHierarchy.contains(teamOfSuperType) )
+ {
+ return false;
+ }
+ return true;
+ }
+
+ private boolean hasSuperroleOverridingImplicitSubrole(IType enclosingTeam, IType superRole) throws JavaModelException
+ {
+ IType teamOfSuperrole = superRole.getDeclaringType();
+
+ if (enclosingTeam.getFullyQualifiedName().equals(teamOfSuperrole.getFullyQualifiedName()))
+ {
+ return false;
+ }
+
+ ITypeHierarchy enclosingTeamHierarchy = enclosingTeam.newSupertypeHierarchy(null);
+ IType[] superTeams = enclosingTeamHierarchy.getAllSuperclasses(enclosingTeam);
+ IType implicitSubrole = null;
+ int idx = 0;
+ IType curTeam = superTeams[idx];
+
+ while ( ! curTeam.getFullyQualifiedName().equals(teamOfSuperrole.getFullyQualifiedName()))
+ {
+ implicitSubrole = curTeam.getType(superRole.getElementName());
+ if (implicitSubrole.exists())
+ {
+ return true;
+ }
+ idx++;
+ curTeam = superTeams[idx];
+ }
+ return false;
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/listeners/SuperInterfacesListener.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/listeners/SuperInterfacesListener.java
new file mode 100644
index 0000000..696bec8
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/listeners/SuperInterfacesListener.java
@@ -0,0 +1,84 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2003, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: SuperInterfacesListener.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards.listeners;
+
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
+import org.eclipse.jdt.internal.ui.wizards.SuperInterfaceSelectionDialog;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
+import org.eclipse.objectteams.otdt.internal.ui.wizards.NewTypeWizardPage;
+
+
+/**
+ * A listener for org.eclipse.objectteams.otdt.internal.ui.wizards.NewTypeWizardPage.
+ * It listens to changes of the interface list dialog field of its observed page.
+ *
+ * @author kaschja
+ * @version $Id: SuperInterfacesListener.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class SuperInterfacesListener implements IListAdapter
+{
+
+ private NewTypeWizardPage _page;
+
+
+ public SuperInterfacesListener(NewTypeWizardPage page)
+ {
+ _page = page;
+ }
+
+ public void customButtonPressed(ListDialogField field, int index)
+ {
+ chooseSuperInterfaces(field);
+ }
+ public void selectionChanged(ListDialogField field) {}
+ public void doubleClicked(ListDialogField field){}
+
+
+ protected NewTypeWizardPage getPage()
+ {
+ return _page;
+ }
+
+
+ private void chooseSuperInterfaces(ListDialogField field)
+ {
+ IPackageFragmentRoot root= getPage().getPackageFragmentRoot();
+ if (root == null)
+ {
+ return;
+ }
+
+ SuperInterfaceSelectionDialog dialog;
+
+ // Note(km): need to change 3rd param from getPage().getSuperInterfacesDialogField()
+ // to get it compiled.
+ dialog = new SuperInterfaceSelectionDialog(getPage().getShell(),
+ getPage().getWizard().getContainer(),
+ getPage(),
+ root.getJavaProject());
+ dialog.setTitle( NewWizardMessages.NewTypeWizardPage_InterfacesDialog_class_title);
+ dialog.setMessage(NewWizardMessages.NewTypeWizardPage_InterfacesDialog_message);
+ dialog.open();
+ return;
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/RoleCreator.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/RoleCreator.java
new file mode 100644
index 0000000..f982fae
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/RoleCreator.java
@@ -0,0 +1,99 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2005, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: RoleCreator.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.objectteams.otdt.core.IOTType;
+import org.eclipse.objectteams.otdt.core.IRoleType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPluginConstants;
+
+
+/**
+ * A RoleCreator is responsible for creating a new role class.
+ *
+ * @author kaschja
+ * @version $Id: RoleCreator.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class RoleCreator extends TypeCreator
+{
+
+ /**
+ * @return "java.lang.Object"
+ */
+ protected String createDefaultSupertypeName()
+ {
+ return "java.lang.Object"; //$NON-NLS-1$
+ }
+
+
+ protected void writeInheritanceRelations(ImportsManager imports, StringBuffer buf) throws CoreException
+ {
+ super.writeInheritanceRelations(imports, buf);
+ writeBaseClass(buf, imports.fImportsRewrite);
+ }
+
+ private void writeBaseClass(StringBuffer buf, ImportRewrite imports)
+ {
+ if ( !(getTypeInfo() instanceof RoleTypeInfo) )
+ return;
+
+ RoleTypeInfo typeInfo = (RoleTypeInfo) getTypeInfo();
+ String baseName = typeInfo.getBaseTypeName();
+
+ if (baseName != null && baseName.trim().length() > 0 )
+ {
+ buf.append(" playedBy "); //$NON-NLS-1$
+ buf.append(imports.addImportBase(baseName));
+ }
+ }
+
+
+ protected void validateTypeCreation()
+ throws CoreException
+ {
+ if (getTypeInfo().getEnclosingTypeName().trim().length() == 0)
+ {
+ throw new CoreException(new Status(IStatus.ERROR,
+ OTDTUIPluginConstants.UIPLUGIN_ID,
+ IStatus.OK,
+ "The role class " + getTypeInfo().getTypeName() + " must have an enclosing team.", //$NON-NLS-1$ //$NON-NLS-2$
+ null));
+ }
+ }
+
+ protected ITypeHierarchy createSuperTypeHierarchy(IType type,
+ IProgressMonitor monitor) throws JavaModelException
+ {
+ IOTType otType = OTModelManager.getOTElement(type);
+ if (otType instanceof IRoleType)
+ return otType.newSuperOTTypeHierarchy(monitor);
+
+ return super.createSuperTypeHierarchy(type, monitor);
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/RoleTypeInfo.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/RoleTypeInfo.java
new file mode 100644
index 0000000..838286b
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/RoleTypeInfo.java
@@ -0,0 +1,65 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2005, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: RoleTypeInfo.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation;
+
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+
+/**
+ * @author kaschja
+ * @version $Id: RoleTypeInfo.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class RoleTypeInfo extends TypeInfo
+{
+
+ private String _baseTypeName;
+
+
+ public RoleTypeInfo(String typeName, IPackageFragmentRoot pkgFragRoot, IPackageFragment pkgFrag)
+ {
+ super(typeName, pkgFragRoot, pkgFrag);
+ setIsRole(true);
+ }
+
+ public void setBaseTypeName(String baseTypeName)
+ {
+ _baseTypeName = baseTypeName;
+ }
+
+ public String getBaseTypeName()
+ {
+ return _baseTypeName;
+ }
+
+ /**
+ * specifies that the type is a role
+ * parameter will be ignored
+ */
+ public void setIsRole(boolean isRole)
+ {
+ super.setIsRole(true);
+ }
+
+ public boolean isRole()
+ {
+ return true;
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/TeamCreator.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/TeamCreator.java
new file mode 100644
index 0000000..c5f9d22
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/TeamCreator.java
@@ -0,0 +1,58 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2008 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: TeamCreator.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.objectteams.otdt.core.IOTType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.core.compiler.IOTConstants;
+
+
+/**
+ * A TeamCreator is responsible for creating a new team class.
+ *
+ * @author kaschja
+ * @version $Id: TeamCreator.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class TeamCreator extends TypeCreator
+{
+
+ /**
+ * @return "org.objectteams.Team"
+ */
+ protected String createDefaultSupertypeName()
+ {
+ return String.valueOf(IOTConstants.STR_ORG_OBJECTTEAMS_TEAM);
+ }
+
+ protected ITypeHierarchy createSuperTypeHierarchy(IType type,
+ IProgressMonitor monitor) throws JavaModelException
+ {
+ IOTType otType = OTModelManager.getOTElement(type);
+ if (otType != null)
+ return otType.newSuperOTTypeHierarchy(monitor);
+
+ return super.createSuperTypeHierarchy(type, monitor);
+ }
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/TypeCreator.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/TypeCreator.java
new file mode 100644
index 0000000..ecca971
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/TypeCreator.java
@@ -0,0 +1,992 @@
+/*******************************************************************************
+ * 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
+ * $Id: TypeCreator.java 23435 2010-02-04 00:14:38Z stephan $
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Fraunhofer FIRST - extended API and implementation
+ * Technical University Berlin - extended API and implementation
+ *******************************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IBuffer;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.ToolFactory;
+import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.core.compiler.IScanner;
+import org.eclipse.jdt.core.compiler.ITerminalSymbols;
+import org.eclipse.jdt.core.compiler.InvalidInputException;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.core.formatter.CodeFormatter;
+import org.eclipse.jdt.internal.corext.codemanipulation.AddUnimplementedConstructorsOperation;
+import org.eclipse.jdt.internal.corext.codemanipulation.AddUnimplementedMethodsOperation;
+import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
+import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
+import org.eclipse.jdt.internal.corext.dom.ASTNodes;
+import org.eclipse.jdt.internal.corext.dom.TokenScanner;
+import org.eclipse.jdt.internal.corext.refactoring.StubTypeContext;
+import org.eclipse.jdt.internal.corext.refactoring.TypeContextChecker;
+import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContext;
+import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType;
+import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil;
+import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
+import org.eclipse.jdt.internal.corext.util.Strings;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
+import org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaTypeCompletionProcessor;
+import org.eclipse.jdt.internal.ui.viewsupport.ProjectTemplateStore;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
+import org.eclipse.jdt.ui.CodeGeneration;
+import org.eclipse.jdt.ui.PreferenceConstants;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.templates.Template;
+import org.eclipse.jface.text.templates.TemplateBuffer;
+import org.eclipse.jface.text.templates.TemplateException;
+import org.eclipse.jface.text.templates.TemplateVariable;
+import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.MalformedTreeException;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.eclipse.text.edits.TextEdit;
+import org.eclipse.objectteams.otdt.core.compiler.IOTConstants;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPluginConstants;
+
+/**
+ * Individual method copied from {@link org.eclipse.jdt.internal.corext.codemanipulation.StubUtility#getCompilationUnitContent(ICompilationUnit, String, String, String, String)}
+ *
+ * @author kaschja
+ */
+public abstract class TypeCreator
+{
+
+ private TypeInfo _typeInfo;
+
+ private IType _createdType;
+ private String _defaultSupertypeName;
+
+ private StubTypeContext fSuperClassStubTypeContext;
+ private StubTypeContext fSuperInterfaceStubTypeContext; // FIXME(SH): use it!?! (see writeSuperClass / writeSuperInterfaces)
+
+
+ public TypeCreator()
+ {
+ _defaultSupertypeName = createDefaultSupertypeName();
+ }
+
+
+ public void setTypeInfo(TypeInfo typeInfo)
+ {
+ _typeInfo = typeInfo;
+ }
+
+ protected TypeInfo getTypeInfo()
+ {
+ return _typeInfo;
+ }
+
+
+ /**
+ * Hook method. Gets called by Constructor.
+ */
+ protected abstract String createDefaultSupertypeName();
+
+ protected String getDefaultSupertypeName()
+ {
+ return _defaultSupertypeName;
+ }
+
+ private void setCreatedType(IType createdType)
+ {
+ _createdType = createdType;
+ }
+
+ public IType createType(IProgressMonitor monitor) throws CoreException, InterruptedException
+ {
+ if (monitor == null) {
+ monitor= new NullProgressMonitor();
+ }
+
+ monitor.beginTask(NewWizardMessages.NewTypeWizardPage_operationdesc, 10);
+
+ ICompilationUnit createdWorkingCopy= null;
+
+ try
+ {
+ validateTypeCreation();
+
+ IPackageFragment pack = getPackageFragment();
+
+ monitor.worked(1);
+
+ IType createdType;
+ ImportsManager imports;
+ int indent= 0;
+
+ String lineDelimiter= null;
+ boolean needsSave = false;
+
+ Set<String> existingImports;
+
+ if (!_typeInfo.isInlineType())
+ {
+ lineDelimiter= StubUtility.getLineDelimiterUsed(pack.getJavaProject());
+
+ ICompilationUnit parentCU= pack.createCompilationUnit(_typeInfo.getTypeName() + ".java", "", false, new SubProgressMonitor(monitor, 2)); //$NON-NLS-1$ //$NON-NLS-2$
+ // create a working copy with a new owner
+ needsSave= true;
+ parentCU.becomeWorkingCopy(new SubProgressMonitor(monitor, 1)); // cu is now a (primary) working copy
+ createdWorkingCopy= parentCU;
+
+ IBuffer buffer= parentCU.getBuffer();
+
+ String cuContent= constructCUContent(parentCU, constructSimpleTypeStub(), lineDelimiter);
+ buffer.setContents(cuContent);
+
+ CompilationUnit astRoot= createASTForImports(parentCU);
+ existingImports= getExistingImports(astRoot);
+
+ imports= new ImportsManager(astRoot);
+
+ // add an import that will be removed again. Having this import solves 14661
+ imports.addImport(JavaModelUtil.concatenateName(pack.getElementName(), _typeInfo.getTypeName()));
+
+ String typeContent= constructTypeStub(parentCU, imports, lineDelimiter);
+
+ AbstractTypeDeclaration typeNode= (AbstractTypeDeclaration) astRoot.types().get(0);
+ int start= ((ASTNode) typeNode.modifiers().get(0)).getStartPosition();
+ int end= typeNode.getStartPosition() + typeNode.getLength();
+
+ buffer.replace(start, end - start, typeContent);
+
+ createdType= parentCU.getType(_typeInfo.getTypeName());
+//{OTDTUI: help the compiler by saving the unit
+// createdWorkingCopy.commitWorkingCopy(true, monitor);
+// createdWorkingCopy.save(monitor, true);
+//carp}
+ }
+ else
+ {
+ IType enclosingType = getEnclosingType();
+
+ ICompilationUnit parentCU = enclosingType.getCompilationUnit();
+
+ needsSave= !parentCU.isWorkingCopy();
+ parentCU.becomeWorkingCopy(new SubProgressMonitor(monitor, 1)); // cu is now for sure (primary) a working copy
+ createdWorkingCopy= parentCU;
+
+ CompilationUnit astRoot= createASTForImports(parentCU);
+ imports= new ImportsManager(astRoot);
+ existingImports= getExistingImports(astRoot);
+
+ // add imports that will be removed again. Having the imports solves 14661
+ IType[] topLevelTypes= parentCU.getTypes();
+ for (int i= 0; i < topLevelTypes.length; i++) {
+ imports.addImport(topLevelTypes[i].getFullyQualifiedName('.'));
+ }
+
+ lineDelimiter= StubUtility.getLineDelimiterUsed(enclosingType);
+ StringBuffer content= new StringBuffer();
+
+ if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.CODEGEN_ADD_COMMENTS))
+ {
+ String comment= getTypeComment(parentCU, lineDelimiter);
+ if (comment != null)
+ {
+ content.append(comment);
+ content.append(lineDelimiter);
+ }
+ }
+ content.append(constructTypeStub(parentCU, imports, lineDelimiter));
+ IJavaElement[] elems= enclosingType.getChildren();
+ IJavaElement sibling= elems.length > 0 ? elems[0] : null;
+
+// try
+// {
+ createdType = enclosingType.createType(
+ content.toString(),
+ sibling,
+ false,
+ new SubProgressMonitor(monitor, 2));
+// }
+// catch (Exception ex)
+// {
+// OTDTUIPlugin.getExceptionHandler().logException(ex);
+// }
+
+ indent = StubUtility.getIndentUsed(enclosingType) + 1;
+ }
+
+ if (monitor.isCanceled()) {
+ throw new InterruptedException();
+ }
+
+
+ // add imports for superclass/interfaces, so types can be resolved correctly
+
+ ICompilationUnit cu= createdType.getCompilationUnit();
+
+ imports.create(false, new SubProgressMonitor(monitor, 1));
+
+ JavaModelUtil.reconcile(cu);
+
+ if (monitor.isCanceled()) {
+ throw new InterruptedException();
+ }
+
+ // set up again
+ CompilationUnit astRoot= createASTForImports(imports.getCompilationUnit());
+ imports= new ImportsManager(astRoot);
+
+ createTypeMembers(createdType, imports, new SubProgressMonitor(monitor, 1));
+
+ // add imports
+ imports.create(false, new SubProgressMonitor(monitor, 1));
+
+ removeUnusedImports(cu, existingImports, false);
+
+ JavaModelUtil.reconcile(cu);
+
+ ISourceRange range= createdType.getSourceRange();
+
+ IBuffer buf= cu.getBuffer();
+ String originalContent= buf.getText(range.getOffset(), range.getLength());
+
+ String formattedContent= CodeFormatterUtil.format(CodeFormatter.K_CLASS_BODY_DECLARATIONS, originalContent, indent, lineDelimiter, pack.getJavaProject());
+ formattedContent= Strings.trimLeadingTabsAndSpaces(formattedContent);
+ buf.replace(range.getOffset(), range.getLength(), formattedContent);
+
+
+ if (!_typeInfo.isInlineType()) {
+ String fileComment= getFileComment(cu);
+ if (fileComment != null && fileComment.length() > 0) {
+ buf.replace(0, 0, fileComment + lineDelimiter);
+ }
+ }
+
+ if (needsSave) {
+ cu.commitWorkingCopy(true, new SubProgressMonitor(monitor, 1));
+ } else {
+ monitor.worked(1);
+ }
+
+
+ setCreatedType(createdType);
+
+// if (createdWorkingCopy != null) {
+// fCreatedType= (IType) createdType.getPrimaryElement();
+// } else {
+// fCreatedType= createdType;
+// }
+ }
+ finally
+ {
+ if (createdWorkingCopy != null)
+ {
+ createdWorkingCopy.discardWorkingCopy();
+ }
+ monitor.done();
+ }
+
+ return _createdType;
+ }
+
+ private CompilationUnit createASTForImports(ICompilationUnit cu) {
+ ASTParser parser= ASTParser.newParser(AST.JLS3);
+ parser.setSource(cu);
+ parser.setResolveBindings(false);
+ parser.setFocalPosition(0);
+ return (CompilationUnit) parser.createAST(null);
+ }
+
+
+ private Set<String> getExistingImports(CompilationUnit root) {
+ List imports= root.imports();
+ Set<String> res= new HashSet<String>(imports.size());
+ for (int i= 0; i < imports.size(); i++) {
+ res.add(ASTNodes.asString((ImportDeclaration) imports.get(i)));
+ }
+ return res;
+ }
+
+ private boolean isValidComment(String template) {
+ IScanner scanner= ToolFactory.createScanner(true, false, false, false);
+ scanner.setSource(template.toCharArray());
+ try {
+ int next= scanner.getNextToken();
+ while (TokenScanner.isComment(next)) {
+ next= scanner.getNextToken();
+ }
+ return next == ITerminalSymbols.TokenNameEOF;
+ } catch (InvalidInputException e) {
+ }
+ return false;
+ }
+
+ /**
+ * @deprecated Instead of file templates, the new type code template
+ * specifies the stub for a compilation unit.
+ */
+ protected String getFileComment(ICompilationUnit parentCU) {
+ return null;
+ }
+
+ /**
+ * Hook method that gets called from <code>createType</code> to retrieve
+ * a file comment. This default implementation returns the content of the
+ * 'file comment' template or <code>null</code> if no comment should be created.
+ *
+ * @param parentCU the parent compilation unit
+ * @param lineDelimiter the line delimiter to use
+ * @return the file comment or <code>null</code> if a file comment
+ * is not desired
+ * @throws CoreException
+ *
+ * @since 3.1
+ */
+ protected String getFileComment(ICompilationUnit parentCU, String lineDelimiter) throws CoreException {
+ if (true /*isAddComments()*/) {
+ return CodeGeneration.getFileComment(parentCU, lineDelimiter);
+ }
+ return null;
+
+ }
+
+ /**
+ * Hook method that gets called from <code>createType</code> to retrieve
+ * a type comment. This default implementation returns the content of the
+ * 'type comment' template.
+ *
+ * @param parentCU the parent compilation unit
+ * @param lineDelimiter the line delimiter to use
+ * @return the type comment or <code>null</code> if a type comment
+ * is not desired
+ *
+ * @since 3.0
+ */
+ protected String getTypeComment(ICompilationUnit parentCU, String lineDelimiter) {