Author: mdryakhlenkov
Date: 2007-10-05 11:16:32 -0400 (Fri, 05 Oct 2007)
New Revision: 4036
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenMappingAction.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenSourceAction.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/popup/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/popup/PopupMenuProvider.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenFileActionUtils.java
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/VisualEditorPlugin.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/META-INF/MANIFEST.MF
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/ViewPlugin.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/ActionOrmTree.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenActionDelegate.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenDiagramActionDelegate.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenMappingActionDelegate.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenSourceActionDelegate.java
Log:
JBIDE-983: Objects on diagram must have context menu
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/VisualEditorPlugin.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/VisualEditorPlugin.java 2007-10-05
15:15:44 UTC (rev 4035)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/VisualEditorPlugin.java 2007-10-05
15:16:32 UTC (rev 4036)
@@ -10,6 +10,10 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.veditor;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.*;
import org.eclipse.jface.resource.ImageDescriptor;
import org.jboss.tools.hibernate.ui.view.BaseUIPlugin;
@@ -42,4 +46,10 @@
public static ImageDescriptor getImageDescriptor(String path) {
return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
}
+
+ public static IWorkbenchPage getPage(){
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ return window.getActivePage();
+ }
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java 2007-10-05
15:15:44 UTC (rev 4035)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java 2007-10-05
15:16:32 UTC (rev 4036)
@@ -10,26 +10,43 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.veditor.editors;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.dnd.TemplateTransferDropTargetListener;
-import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
import org.eclipse.gef.requests.CreationFactory;
import org.eclipse.gef.requests.SimpleFactory;
+import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.WorkbenchPartAction;
import org.eclipse.gef.ui.parts.GraphicalEditor;
import org.eclipse.gef.ui.parts.TreeViewer;
+import org.eclipse.jface.action.IAction;
import org.eclipse.jface.util.TransferDropTargetListener;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.mapping.DependantValue;
+import org.hibernate.mapping.Property;
import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.Table;
+import org.jboss.tools.hibernate.ui.veditor.editors.actions.OpenMappingAction;
+import org.jboss.tools.hibernate.ui.veditor.editors.actions.OpenSourceAction;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.ModelElement;
import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmShape;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.Shape;
import org.jboss.tools.hibernate.ui.veditor.editors.parts.GEFRootEditPart;
+import org.jboss.tools.hibernate.ui.veditor.editors.parts.OrmEditPart;
import org.jboss.tools.hibernate.ui.veditor.editors.parts.OrmEditPartFactory;
+import org.jboss.tools.hibernate.ui.veditor.editors.popup.PopupMenuProvider;
import org.jboss.tools.hibernate.ui.view.views.ObjectEditorInput;
public class VisualEditor extends GraphicalEditor {
@@ -54,6 +71,10 @@
viewer.setRootEditPart(new GEFRootEditPart());
viewer.addDropTargetListener(createTransferDropTargetListener());
viewer.setContents(ormDiagram);
+
+ PopupMenuProvider provider = new PopupMenuProvider(viewer, getActionRegistry());
+ viewer.setContextMenu(provider);
+ getSite().registerContextMenu("FlowDiagramContextmenu", provider, viewer);
}
protected void createActions() {
@@ -71,6 +92,15 @@
super.createActions();
getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.PRINT.getId(),
getActionRegistry().getAction(ActionFactory.PRINT.getId()));
+
+ ActionRegistry registry = getActionRegistry();
+ IAction action;
+
+ action = new OpenMappingAction(this);
+ registry.registerAction(action);
+
+ action = new OpenSourceAction(this);
+ registry.registerAction(action);
}
private TransferDropTargetListener createTransferDropTargetListener() {
@@ -117,4 +147,26 @@
return super.getAdapter(type);
}
+
+ public Set getSelectedElements() {
+ Set ret = new HashSet();
+ List selectedEditParts = getGraphicalViewer().getSelectedEditParts();
+ Iterator iterator = selectedEditParts.iterator();
+ while (iterator.hasNext()) {
+ Object elem = iterator.next();
+ if (elem instanceof OrmEditPart) {
+ Object model = ((OrmEditPart)elem).getModel();
+ ModelElement shape = (Shape)model;
+ while (!(shape instanceof OrmShape)) {
+ shape = shape.getParent();
+ }
+ ret.add(((OrmShape)shape).getOrmElement());
+ }
+ }
+ return ret;
+ }
+
+ public OrmDiagram getViewerContents() {
+ return ormDiagram;
+ }
}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenMappingAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenMappingAction.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenMappingAction.java 2007-10-05
15:16:32 UTC (rev 4036)
@@ -0,0 +1,79 @@
+package org.jboss.tools.hibernate.ui.veditor.editors.actions;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.dom4j.Document;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.gef.ui.actions.SelectionAction;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.Table;
+import org.jboss.tools.hibernate.ui.veditor.VisualEditorPlugin;
+import org.jboss.tools.hibernate.ui.veditor.editors.VisualEditor;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
+import org.jboss.tools.hibernate.ui.view.views.ObjectEditorInput;
+import org.jboss.tools.hibernate.ui.view.views.OpenFileActionUtils;
+
+public class OpenMappingAction extends SelectionAction {
+ public static String ACTION_ID =
"org.jboss.tools.hibernate.ui.veditor.editors.actions.open.mapping";
+
+ public OpenMappingAction(IWorkbenchPart part) {
+ super(part);
+ setId(ACTION_ID);
+ setText("Open Mapping File");
+ }
+
+ public void run() {
+ ObjectEditorInput objectEditorInput =
(ObjectEditorInput)((VisualEditor)getWorkbenchPart()).getEditorInput();
+ ConsoleConfiguration consoleConfiguration = objectEditorInput.getConfiguration();
+ java.io.File configXMLFile = consoleConfiguration.getPreferences().getConfigXMLFile();
+ Document doc = OpenFileActionUtils.getDocument(consoleConfiguration, configXMLFile);
+ IJavaProject proj = objectEditorInput.getJavaProject();
+
+ VisualEditor part = (VisualEditor)getWorkbenchPart();
+ Set selectedElements = part.getSelectedElements();
+
+ Iterator iterator = selectedElements.iterator();
+ while (iterator.hasNext()) {
+ Object selectedElement = iterator.next();
+
+ IResource resource = null;
+ if (selectedElement instanceof RootClass) {
+ RootClass rootClass = (RootClass)selectedElement;
+
+ resource = OpenFileActionUtils.getResource(consoleConfiguration, proj, doc,
configXMLFile, rootClass);
+
+ if (resource == null) {
+ String fullyQualifiedName = rootClass.getClassName();
+ try {
+ resource = proj.findType(fullyQualifiedName).getResource();
+ } catch (JavaModelException e) {
+ VisualEditorPlugin.getDefault().logInfo("Can't find mapping file",
e);
+ }
+ }
+ } else if (selectedElement instanceof Table) {
+ Table table = (Table)selectedElement;
+
+ resource = OpenFileActionUtils.getResource(consoleConfiguration, proj, doc,
configXMLFile, table);
+ }
+
+ if (resource != null) {
+ try {
+ OpenFileActionUtils.openEditor(VisualEditorPlugin.getPage(), resource);
+ } catch (PartInitException e) {
+ VisualEditorPlugin.getDefault().logInfo("Can't open mapping file",
e);
+ }
+ }
+ }
+ }
+
+ protected boolean calculateEnabled() {
+ VisualEditor part = (VisualEditor)getWorkbenchPart();
+ return part.getSelectedElements().size() > 0;
+ }
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenSourceAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenSourceAction.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenSourceAction.java 2007-10-05
15:16:32 UTC (rev 4036)
@@ -0,0 +1,71 @@
+package org.jboss.tools.hibernate.ui.veditor.editors.actions;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.gef.ui.actions.SelectionAction;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.mapping.RootClass;
+import org.jboss.tools.hibernate.ui.veditor.VisualEditorPlugin;
+import org.jboss.tools.hibernate.ui.veditor.editors.VisualEditor;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
+import org.jboss.tools.hibernate.ui.view.ViewPlugin;
+import org.jboss.tools.hibernate.ui.view.views.ObjectEditorInput;
+import org.jboss.tools.hibernate.ui.view.views.OpenFileActionUtils;
+
+public class OpenSourceAction extends SelectionAction {
+ public static String ACTION_ID =
"org.jboss.tools.hibernate.ui.veditor.editors.actions.open.source";
+
+ public OpenSourceAction(IWorkbenchPart part) {
+ super(part);
+ setId(ACTION_ID);
+ setText("Open Source File");
+ }
+
+ public void run() {
+ ObjectEditorInput objectEditorInput =
(ObjectEditorInput)((VisualEditor)getWorkbenchPart()).getEditorInput();
+ ConsoleConfiguration consoleConfiguration = objectEditorInput.getConfiguration();
+ IJavaProject proj = objectEditorInput.getJavaProject();
+
+ VisualEditor part = (VisualEditor)getWorkbenchPart();
+ Set selectedElements = part.getSelectedElements();
+
+ Iterator iterator = selectedElements.iterator();
+ while (iterator.hasNext()) {
+ RootClass rootClass = (RootClass) iterator.next();
+
+ IResource resource = null;
+ String fullyQualifiedName = rootClass.getClassName();
+ try {
+ resource = proj.findType(fullyQualifiedName).getResource();
+ } catch (JavaModelException e) {
+ VisualEditorPlugin.getDefault().logError("Can't find source file.",
e);
+ }
+
+ if (resource instanceof IFile){
+ try {
+ OpenFileActionUtils.openEditor(ViewPlugin.getPage(), (IFile) resource);
+ } catch (PartInitException e) {
+ VisualEditorPlugin.getDefault().logError("Can't open source
file.", e);
+ }
+ }
+ }
+ }
+
+ protected boolean calculateEnabled() {
+ VisualEditor part = (VisualEditor)getWorkbenchPart();
+ Set selectedElements = part.getSelectedElements();
+ Iterator iterator = selectedElements.iterator();
+ while (iterator.hasNext()) {
+ Object elem = iterator.next();
+ if (elem instanceof RootClass) return true;
+ }
+ return false;
+ }
+}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java 2007-10-05
15:15:44 UTC (rev 4035)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java 2007-10-05
15:16:32 UTC (rev 4036)
@@ -124,8 +124,6 @@
childrenLocations[i] = ((RootClass)ormElement).getEntityName() + "@";
} else if (ormElement instanceof Table) {
childrenLocations[i] = HibernateUtils.getTableName((Table)ormElement)+"@";
-// } else if (ormElement instanceof Component) {
-// childrenLocations[i] = ((Component)ormElement).getComponentClassName()+"@";
}
childrenLocations[i] += shape.getLocation().x + ";" +
shape.getLocation().y+";" + shape.isHiden();
}
@@ -707,5 +705,12 @@
public boolean getState(Properties properties, Shape shape){
return getState(properties, getKey(shape)+".state");
}
-
+
+ public IJavaProject getJavaProject() {
+ return javaProject;
+ }
+
+ public ConsoleConfiguration getConsoleConfiguration() {
+ return consoleConfiguration;
+ }
}
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/popup/PopupMenuProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/popup/PopupMenuProvider.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/popup/PopupMenuProvider.java 2007-10-05
15:16:32 UTC (rev 4036)
@@ -0,0 +1,76 @@
+package org.jboss.tools.hibernate.ui.veditor.editors.popup;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.ContextMenuProvider;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.ui.actions.ActionRegistry;
+import org.eclipse.gef.ui.actions.GEFActionConstants;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.actions.ActionFactory;
+import org.jboss.tools.hibernate.ui.veditor.editors.actions.OpenMappingAction;
+import org.jboss.tools.hibernate.ui.veditor.editors.actions.OpenSourceAction;
+
+public class PopupMenuProvider extends ContextMenuProvider {
+ private ActionRegistry actionRegistry;
+
+ public PopupMenuProvider(EditPartViewer viewer, ActionRegistry actionRegistry) {
+ super(viewer);
+ this.actionRegistry = actionRegistry;
+ }
+
+ public void buildContextMenu(IMenuManager menu) {
+ menu.add(new Separator(GEFActionConstants.MB_ADDITIONS));
+
+ IAction action = getActionRegistry().getAction(OpenSourceAction.ACTION_ID);
+ appendToGroup(GEFActionConstants.MB_ADDITIONS, action);
+ createMenuItem(getMenu(), action);
+
+ action = getActionRegistry().getAction(OpenMappingAction.ACTION_ID);
+ appendToGroup(GEFActionConstants.MB_ADDITIONS, action);
+ createMenuItem(getMenu(), action);
+ }
+
+ public void createMenuItem(Menu menu, IAction action) {
+ boolean enabled = action.isEnabled();
+ boolean hidden = false;
+ if (hidden)
+ return;
+ MenuItem item = new MenuItem(menu, SWT.CASCADE);
+ String displayName = action.getText();
+ item.addSelectionListener(new AL(action));
+ item.setText(displayName);
+ item.setEnabled(enabled);
+ }
+
+ class AL implements SelectionListener {
+ IAction action;
+
+ public AL(IAction action) {
+ this.action = action;
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ action.run();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ }
+
+ public ActionRegistry getActionRegistry() {
+ return actionRegistry;
+ }
+}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/META-INF/MANIFEST.MF
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/META-INF/MANIFEST.MF 2007-10-05
15:15:44 UTC (rev 4035)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/META-INF/MANIFEST.MF 2007-10-05
15:16:32 UTC (rev 4036)
@@ -21,6 +21,6 @@
org.eclipse.ui.editors,
org.eclipse.jface.text,
org.hibernate.eclipse,
- org.hibernate.eclipse.console,
- org.eclipse.debug.core
+ org.eclipse.debug.core,
+ org.hibernate.eclipse.console
Eclipse-LazyStart: true
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/ViewPlugin.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/ViewPlugin.java 2007-10-05
15:15:44 UTC (rev 4035)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/ViewPlugin.java 2007-10-05
15:16:32 UTC (rev 4036)
@@ -18,6 +18,8 @@
import java.util.Properties;
import java.util.ResourceBundle;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
@@ -25,21 +27,20 @@
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
import org.osgi.framework.BundleContext;
/**
* The main plugin class to be used in the desktop.
*/
public class ViewPlugin extends BaseUIPlugin {
- //The shared instance.
private static ViewPlugin plugin;
- //Resource bundle.
private ResourceBundle resourceBundle;
public static final ResourceBundle BUNDLE_IMAGE =
ResourceBundle.getBundle(ViewPlugin.class.getPackage().getName() + ".image");
- // add Tau 28.04.2005 for trace
public static boolean TRACE = false;
public static boolean TRACE_VIEW = false;
public static boolean TRACE_WIZARD = false;
@@ -47,9 +48,6 @@
public static final String PLUGIN_ID = "org.jboss.tools.hibernate.view";
public static final String autoMappingSettingPrefPage =
"autoMappingSettingPrefPage";
- /**
- * The constructor.
- */
public ViewPlugin() {
super();
plugin = this;
@@ -72,31 +70,18 @@
}
}
- /**
- * This method is called upon plug-in activation
- */
public void start(BundleContext context) throws Exception {
super.start(context);
}
- /**
- * This method is called when the plug-in is stopped
- */
public void stop(BundleContext context) throws Exception {
super.stop(context);
}
- /**
- * Returns the shared instance.
- */
public static ViewPlugin getDefault() {
return plugin;
}
- /**
- * Returns the string from the plugin's resource bundle,
- * or 'key' if not found.
- */
public static String getResourceString(String key) {
ResourceBundle bundle = ViewPlugin.getDefault().getResourceBundle();
try {
@@ -106,14 +91,10 @@
}
}
- /**
- * Returns the plugin's resource bundle,
- */
public ResourceBundle getResourceBundle() {
return resourceBundle;
}
- // add tau 05.04.2005
public static Shell getActiveWorkbenchShell() {
IWorkbenchWindow window = getActiveWorkbenchWindow();
if (window != null) {
@@ -122,19 +103,16 @@
return null;
}
- // add tau 05.04.2005
public static IWorkbenchWindow getActiveWorkbenchWindow() {
return getDefault().getWorkbench().getActiveWorkbenchWindow();
}
- // add tau 19.04.2005
public static IWorkbenchPage getPage(){
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
return window.getActivePage();
}
- // add Tau 28.04.2005 for trace
static {
String value = Platform.getDebugOption(PLUGIN_ID + "/debug");
@@ -148,7 +126,6 @@
}
- // add tau 22.12.2005
public static void loadPreferenceStoreProperties(Properties properties, String key){
IPreferenceStore preferenceStore = ViewPlugin.getDefault().getPreferenceStore();
String value = preferenceStore.getString(key);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/ActionOrmTree.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/ActionOrmTree.java 2007-10-05
15:15:44 UTC (rev 4035)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/ActionOrmTree.java 2007-10-05
15:16:32 UTC (rev 4036)
@@ -31,15 +31,7 @@
public void run() {
try {
-// if (ViewPlugin.TRACE || ViewPlugin.TRACE_VIEW ) ExceptionHandler.logInfo("!TRY
ActionOrmTree.run() lock(=" + OrmCore.lock + ").acquire(), Depth=" +
OrmCore.lock.getDepth());
-// ((OrmContentProvider)viewer.getContentProvider()).lockMenu = true; // add tau
06.12.2005
-// OrmCore.lock.acquire(); // add tau 05.12.2005
-// if (ViewPlugin.TRACE || ViewPlugin.TRACE_VIEW ) ExceptionHandler.logInfo("!RUN
ActionOrmTree.run() lock(=" + OrmCore.lock + ").acquire(), Depth=" +
OrmCore.lock.getDepth());
-//
-// OrmCore.getDefault().setLockResourceChangeListener(true);
-
this.rush();
-
} finally {
// OrmCore.lock.release();
// ((OrmContentProvider)viewer.getContentProvider()).lockMenu = false; // add tau
06.12.2005
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenActionDelegate.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenActionDelegate.java 2007-10-05
15:15:44 UTC (rev 4035)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenActionDelegate.java 2007-10-05
15:16:32 UTC (rev 4036)
@@ -10,29 +10,10 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.view.views;
-import java.util.HashMap;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.ide.IDE;
-import org.eclipse.ui.internal.ObjectPluginAction;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.eclipse.console.EclipseConsoleConfigurationPreferences;
-import org.hibernate.eclipse.console.EclipseLaunchConsoleConfigurationPreferences;
-import org.hibernate.eclipse.console.utils.ProjectUtils;
-import org.hibernate.eclipse.launch.IConsoleConfigurationLaunchConstants;
-import org.jboss.tools.hibernate.ui.view.ViewPlugin;
public abstract class OpenActionDelegate implements IObjectActionDelegate {
@@ -41,48 +22,4 @@
public void selectionChanged(IAction action, ISelection selection) {
}
-
- protected IJavaProject findJavaProject(ConsoleConfiguration consoleConfiguration) {
- IJavaProject proj = null;
- if (consoleConfiguration != null) {
- ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
- ILaunchConfigurationType launchConfigurationType =
launchManager.getLaunchConfigurationType(
"org.hibernate.eclipse.launch.ConsoleConfigurationLaunchConfigurationType" );
- ILaunchConfiguration[] launchConfigurations;
- try {
- launchConfigurations = launchManager.getLaunchConfigurations( launchConfigurationType
);
- for (int i = 0; i < launchConfigurations.length; i++) { // can't believe there
is no look up by name API
- ILaunchConfiguration launchConfiguration = launchConfigurations[i];
- if(launchConfiguration.getName().equals(consoleConfiguration.getName())) {
- proj =
ProjectUtils.findJavaProject(launchConfiguration.getAttribute(IConsoleConfigurationLaunchConstants.PROJECT_NAME,
""));
- }
- }
- } catch (CoreException e1) {
- ViewPlugin.getDefault().logError("Can't find java project.", e1);
- }
- }
- return proj;
- }
-// protected IJavaProject findJavaProject(ConsoleConfiguration consoleConfiguration) {
-// IJavaProject proj = null;
-// if (consoleConfiguration != null) {
-// ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
-//
-// ILaunchConfigurationType launchConfigurationType =
launchManager.getLaunchConfigurationType(
"org.hibernate.eclipse.launch.ConsoleConfigurationLaunchConfigurationType" );
-// ILaunchConfiguration[] launchConfigurations = null;
-// try {
-// launchConfigurations =
launchManager.getLaunchConfigurations(launchConfigurationType);
-// } catch (Exception e) {
-// }
-// for (int i = 0; i < launchConfigurations.length; i++) {
-//
-// }
-//
-// String projectName =
((EclipseConsoleConfigurationPreferences)consoleConfiguration.getPreferences()).getProjectName();
-// if (projectName != null) {
-// proj = ProjectUtils.findJavaProject(projectName);
-// }
-// }
-// return proj;
-// }
-
}
\ No newline at end of file
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenDiagramActionDelegate.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenDiagramActionDelegate.java 2007-10-05
15:15:44 UTC (rev 4035)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenDiagramActionDelegate.java 2007-10-05
15:16:32 UTC (rev 4036)
@@ -12,36 +12,25 @@
import java.util.HashMap;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.internal.ObjectPluginAction;
-import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.eclipse.console.utils.ProjectUtils;
-import org.hibernate.eclipse.launch.IConsoleConfigurationLaunchConstants;
import org.jboss.tools.hibernate.ui.view.ViewPlugin;
public class OpenDiagramActionDelegate extends OpenActionDelegate {
+ private HashMap hashMap = new HashMap();
public void run(IAction action) {
- HashMap hashMap = new HashMap();
ObjectPluginAction objectPluginAction = (ObjectPluginAction)action;
Object rootClass =
((TreeSelection)objectPluginAction.getSelection()).getFirstElement();
ObjectEditorInput input = (ObjectEditorInput)hashMap.get(rootClass);
ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)(((TreeSelection)objectPluginAction.getSelection()).getPaths()[0]).getSegment(0);
- IJavaProject proj = findJavaProject(consoleConfiguration);
+ IJavaProject proj = OpenFileActionUtils.findJavaProject(consoleConfiguration);
if(input == null) {
input = new ObjectEditorInput(consoleConfiguration, rootClass, proj);
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenFileActionUtils.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenFileActionUtils.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenFileActionUtils.java 2007-10-05
15:16:32 UTC (rev 4036)
@@ -0,0 +1,252 @@
+package org.jboss.tools.hibernate.ui.view.views;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.Node;
+import org.dom4j.Visitor;
+import org.dom4j.VisitorSupport;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IDE;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.eclipse.console.utils.ProjectUtils;
+import org.hibernate.eclipse.launch.IConsoleConfigurationLaunchConstants;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.Table;
+import org.hibernate.util.StringHelper;
+import org.hibernate.util.XMLHelper;
+import org.jboss.tools.hibernate.ui.view.ViewPlugin;
+import org.xml.sax.InputSource;
+
+public class OpenFileActionUtils {
+ private static XMLHelper helper = new XMLHelper();
+
+ public static void openEditor(IWorkbenchPage page, IResource resource) throws
PartInitException {
+ IDE.openEditor(page, (IFile) resource);
+ }
+
+ public static IJavaProject findJavaProject(ConsoleConfiguration consoleConfiguration) {
+ IJavaProject proj = null;
+ if (consoleConfiguration != null) {
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType launchConfigurationType =
launchManager.getLaunchConfigurationType(
"org.hibernate.eclipse.launch.ConsoleConfigurationLaunchConfigurationType" );
+ ILaunchConfiguration[] launchConfigurations;
+ try {
+ launchConfigurations = launchManager.getLaunchConfigurations( launchConfigurationType
);
+ for (int i = 0; i < launchConfigurations.length; i++) { // can't believe there
is no look up by name API
+ ILaunchConfiguration launchConfiguration = launchConfigurations[i];
+ if(launchConfiguration.getName().equals(consoleConfiguration.getName())) {
+ proj =
ProjectUtils.findJavaProject(launchConfiguration.getAttribute(IConsoleConfigurationLaunchConstants.PROJECT_NAME,
""));
+ }
+ }
+ } catch (CoreException e1) {
+ ViewPlugin.getDefault().logError("Can't find java project.", e1);
+ }
+ }
+ return proj;
+ }
+
+ private static boolean elementInResource(ConsoleConfiguration consoleConfiguration,
IResource resource, Object element) {
+ if (element instanceof RootClass) {
+ return classInResource(consoleConfiguration, resource, (RootClass)element);
+ } else if (element instanceof Table) {
+ return tableInResource(consoleConfiguration, resource, (Table)element);
+ } else {
+ return false;
+ }
+ }
+
+ public static boolean classInResource(ConsoleConfiguration consoleConfiguration,
IResource resource, RootClass rootClass) {
+ Document doc = getDocument(consoleConfiguration, resource.getLocation().toFile());
+ Element hmNode = doc.getRootElement();
+
+ Iterator rootChildren = hmNode.elementIterator();
+ while ( rootChildren.hasNext() ) {
+ Element element = (Element) rootChildren.next();
+ String elementName = element.getName();
+
+ if ( "class".equals( elementName ) ) {
+ Attribute classAttr = element.attribute( "name" );
+ if (classAttr != null) {
+ if (classAttr.getValue().equals(rootClass.getClassName())) {
+ return true;
+ } else {
+ Attribute packNode = hmNode.attribute( "package" );
+ String packageName = null;
+ if ( packNode != null ) {
+ packageName = packNode.getValue();
+ String className = packageName + "." + classAttr.getValue();
+ if (className.equals(rootClass.getClassName())) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean tableInResource(ConsoleConfiguration consoleConfiguration,
IResource resource, Table table) {
+ Document doc = getDocument(consoleConfiguration, resource.getLocation().toFile());
+
+ if (getElements(doc, "table", HibernateUtils.getTableName(table)).hasNext())
{
+ return true;
+ }
+
+ Iterator classes = getElements(doc, "class");
+ while (classes.hasNext()) {
+ Element element = (Element) classes.next();
+ Attribute classNameAttr = element.attribute( "name" );
+ String physicalTableName =
consoleConfiguration.getConfiguration().getNamingStrategy().classToTableName(classNameAttr.getValue());
+ if (table.getName().equals(physicalTableName)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private static Iterator getElements(Document doc, String elementName) {
+ return getElements(doc, elementName, null, null);
+ }
+
+ private static Iterator getElements(Document doc, String attrName, String attrValue) {
+ return getElements(doc, null, attrName, attrValue);
+ }
+
+ private static Iterator getElements(Document doc, String elementName, String attrName,
String attrValue) {
+ LVS visitor = new LVS(elementName, attrName, attrValue);
+ doc.accept( visitor );
+ return visitor.iterator();
+ }
+
+ static class LVS extends VisitorSupport {
+ private String nodeName;
+ private String attrName;
+ private String attrValue;
+ private List ret = new ArrayList();
+
+ public LVS(String nodeName, String attrName, String attrValue) {
+ super();
+ this.nodeName = nodeName;
+ this.attrName = attrName;
+ this.attrValue = attrValue;
+ }
+
+ public void visit(Element element) {
+ if (nodeName == null) {
+ if (attrName != null && attrValue != null) {
+ if (attrIsCorrect(element, attrName, attrValue)) {
+ ret.add(element);
+ }
+ }
+ } else {
+ if (nodeName.equals(element.getName())) {
+ if (attrName != null) {
+ if (attrIsCorrect(element, attrName, attrValue)) {
+ ret.add(element);
+ }
+ } else {
+ ret.add(element);
+ }
+ }
+ }
+
+ }
+
+ private boolean attrIsCorrect(Element element, String attrName, String attrValue) {
+ Attribute attr = element.attribute(attrName);
+ if (attr != null && attrValue.equals(attr.getValue())) {
+ return attrValue.equals(attr.getValue());
+ }
+ return false;
+ }
+
+ public Iterator iterator() {
+ return ret.iterator();
+ }
+ }
+
+ public static Document getDocument(ConsoleConfiguration consoleConfiguration,
java.io.File configXMLFile) {
+ Document doc = null;
+ if (consoleConfiguration != null && configXMLFile != null) {
+ InputStream stream = null;
+ try {
+ stream = new FileInputStream( configXMLFile );
+ } catch (FileNotFoundException e) {
+ ViewPlugin.getDefault().logError("Configuration file not found", e);
+ }
+ try {
+ List errors = new ArrayList();
+ doc = helper.createSAXReader( configXMLFile.getPath(), errors,
consoleConfiguration.getConfiguration().getEntityResolver() )
+ .read( new InputSource( stream ) );
+ if ( errors.size() != 0 ) {
+ ViewPlugin.getDefault().logError("invalid configuration");
+ }
+ }
+ catch (DocumentException e) {
+ ViewPlugin.getDefault().logError("Could not parse configuration", e);
+ }
+ finally {
+ try {
+ stream.close();
+ }
+ catch (IOException ioe) {
+ ViewPlugin.getDefault().logError("could not close input stream for",
ioe);
+ }
+ }
+ }
+ return doc;
+ }
+
+ public static IResource getResource(ConsoleConfiguration consoleConfiguration,
IJavaProject proj, Document doc, java.io.File configXMLFile, Object element) {
+ IResource resource = null;
+ if (consoleConfiguration != null && proj != null && doc != null) {
+ Element sfNode = doc.getRootElement().element( "session-factory" );
+ Iterator elements = sfNode.elementIterator();
+ while ( elements.hasNext() ) {
+ Element subelement = (Element) elements.next();
+ String subelementName = subelement.getName();
+ if ( "mapping".equals( subelementName ) ) {
+ Attribute file = subelement.attribute( "resource" );
+ if (file != null) {
+ resource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new
Path(configXMLFile.getParent()).append(file.getValue()));
+ if (elementInResource(consoleConfiguration, resource, element)) return
resource;
+ }
+ }
+ }
+ java.io.File[] files = consoleConfiguration.getPreferences().getMappingFiles();
+ for (int i = 0; i < files.length; i++) {
+ java.io.File file = files[i];
+ if (file != null) {
+ resource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new
Path(file.getPath()));
+ if (OpenFileActionUtils.elementInResource(consoleConfiguration, resource, element))
return resource;
+ }
+ }
+ }
+ return null;
+ }
+}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenMappingActionDelegate.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenMappingActionDelegate.java 2007-10-05
15:15:44 UTC (rev 4035)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenMappingActionDelegate.java 2007-10-05
15:16:32 UTC (rev 4036)
@@ -58,129 +58,31 @@
public class OpenMappingActionDelegate extends OpenActionDelegate {
private static XMLHelper helper = new XMLHelper();
- private HashMap map = new HashMap();
public void run(IAction action) {
ObjectPluginAction objectPluginAction = (ObjectPluginAction)action;
RootClass rootClass =
(RootClass)((TreeSelection)objectPluginAction.getSelection()).getFirstElement();
ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)(((TreeSelection)objectPluginAction.getSelection()).getPaths()[0]).getSegment(0);
- IJavaProject proj = findJavaProject(consoleConfiguration);
+ IJavaProject proj = OpenFileActionUtils.findJavaProject(consoleConfiguration);
java.io.File configXMLFile = consoleConfiguration.getPreferences().getConfigXMLFile();
- Document doc = getDocument(consoleConfiguration, configXMLFile);
- IResource resource = getResource(consoleConfiguration, proj, doc, configXMLFile,
rootClass);
+ Document doc = OpenFileActionUtils.getDocument(consoleConfiguration, configXMLFile);
+ IResource resource = OpenFileActionUtils.getResource(consoleConfiguration, proj,
doc, configXMLFile, rootClass);
if (resource == null) {
String fullyQualifiedName = rootClass.getClassName();
try {
resource = proj.findType(fullyQualifiedName).getResource();
- } catch (JavaModelException e1) {
- e1.printStackTrace();
+ } catch (JavaModelException e) {
+ ViewPlugin.getDefault().logError("Can't find mapping file.", e);
}
}
if (resource != null && resource instanceof IFile){
try {
- IDE.openEditor(ViewPlugin.getPage(), (IFile) resource);
+ OpenFileActionUtils.openEditor(ViewPlugin.getPage(), (IFile) resource);
} catch (PartInitException e) {
ViewPlugin.getDefault().logError("Can't open mapping or source
file.", e);
}
}
}
-
- private boolean classInResource(ConsoleConfiguration consoleConfiguration, IResource
resource, RootClass rootClass) {
- Document doc = getDocument(consoleConfiguration, resource.getLocation().toFile());
- Element hmNode = doc.getRootElement();
-
- Iterator rootChildren = hmNode.elementIterator();
- while ( rootChildren.hasNext() ) {
- Element element = (Element) rootChildren.next();
- String elementName = element.getName();
-
- if ( "class".equals( elementName ) ) {
- Attribute classAttr = element.attribute( "name" );
- if (classAttr != null) {
- if (classAttr.getValue().equals(rootClass.getClassName())) {
- if (map.get(rootClass.getClassName()) == null) map.put(rootClass.getClassName(),
resource);
- return true;
- } else {
- Attribute packNode = hmNode.attribute( "package" );
- String packageName = null;
- if ( packNode != null ) {
- packageName = packNode.getValue();
- String className = packageName + "." + classAttr.getValue();
- if (className.equals(rootClass.getClassName())) {
- if (map.get(rootClass.getClassName()) == null) map.put(rootClass.getClassName(),
resource);
- return true;
- }
- }
- }
- }
- }
- }
- return false;
- }
-
- private IResource getResource(ConsoleConfiguration consoleConfiguration, IJavaProject
proj, Document doc, java.io.File configXMLFile, RootClass rootClass) {
- if (map.get(rootClass.getClassName()) != null) {
- return (IResource)map.get(rootClass.getClassName());
- } else {
- IResource resource = null;
- if (consoleConfiguration != null && proj != null && doc != null) {
- Element sfNode = doc.getRootElement().element( "session-factory" );
- Iterator elements = sfNode.elementIterator();
- while ( elements.hasNext() ) {
- Element subelement = (Element) elements.next();
- String subelementName = subelement.getName();
- if ( "mapping".equals( subelementName ) ) {
- Attribute file = subelement.attribute( "resource" );
- if (file != null) {
- resource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new
Path(configXMLFile.getParent()).append(file.getValue()));
- if (classInResource(consoleConfiguration, resource, rootClass)) return
resource;
- }
- }
- }
- java.io.File[] files = consoleConfiguration.getPreferences().getMappingFiles();
- for (int i = 0; i < files.length; i++) {
- java.io.File file = files[i];
- if (file != null) {
- resource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new
Path(file.getPath()));
- if (classInResource(consoleConfiguration, resource, rootClass)) return resource;
- }
- }
- }
- return null;
- }
- }
-
- private Document getDocument(ConsoleConfiguration consoleConfiguration, java.io.File
configXMLFile) {
- Document doc = null;
- if (consoleConfiguration != null && configXMLFile != null) {
- InputStream stream = null;
- try {
- stream = new FileInputStream( configXMLFile );
- } catch (FileNotFoundException e) {
- ViewPlugin.getDefault().logError("Configuration file not found", e);
- }
- try {
- List errors = new ArrayList();
- doc = helper.createSAXReader( configXMLFile.getPath(), errors,
consoleConfiguration.getConfiguration().getEntityResolver() )
- .read( new InputSource( stream ) );
- if ( errors.size() != 0 ) {
- ViewPlugin.getDefault().logError("invalid configuration");
- }
- }
- catch (DocumentException e) {
- ViewPlugin.getDefault().logError("Could not parse configuration", e);
- }
- finally {
- try {
- stream.close();
- }
- catch (IOException ioe) {
- ViewPlugin.getDefault().logError("could not close input stream for",
ioe);
- }
- }
- }
- return doc;
- }
}
\ No newline at end of file
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenSourceActionDelegate.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenSourceActionDelegate.java 2007-10-05
15:15:44 UTC (rev 4035)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenSourceActionDelegate.java 2007-10-05
15:16:32 UTC (rev 4036)
@@ -10,51 +10,17 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.view.views;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-
-import org.dom4j.Attribute;
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.Element;
-import org.eclipse.core.internal.resources.File;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.internal.ObjectPluginAction;
-import org.hibernate.HibernateException;
-import org.hibernate.MappingException;
-import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.eclipse.console.EclipseConsoleConfigurationPreferences;
-import org.hibernate.eclipse.console.utils.ProjectUtils;
-import org.hibernate.eclipse.launch.IConsoleConfigurationLaunchConstants;
import org.hibernate.mapping.RootClass;
-import org.hibernate.util.XMLHelper;
import org.jboss.tools.hibernate.ui.view.ViewPlugin;
-import org.xml.sax.InputSource;
public class OpenSourceActionDelegate extends OpenActionDelegate {
@@ -62,19 +28,19 @@
ObjectPluginAction objectPluginAction = (ObjectPluginAction)action;
RootClass rootClass =
(RootClass)((TreeSelection)objectPluginAction.getSelection()).getFirstElement();
ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)(((TreeSelection)objectPluginAction.getSelection()).getPaths()[0]).getSegment(0);
- IJavaProject proj = findJavaProject(consoleConfiguration);
+ IJavaProject proj = OpenFileActionUtils.findJavaProject(consoleConfiguration);
IResource resource = null;
String fullyQualifiedName = rootClass.getClassName();
try {
resource = proj.findType(fullyQualifiedName).getResource();
- } catch (JavaModelException e1) {
- e1.printStackTrace();
+ } catch (JavaModelException e) {
+ ViewPlugin.getDefault().logError("Can't find source file.", e);
}
if (resource instanceof IFile){
try {
- IDE.openEditor(ViewPlugin.getPage(), (IFile) resource);
+ OpenFileActionUtils.openEditor(ViewPlugin.getPage(), (IFile) resource);
} catch (PartInitException e) {
ViewPlugin.getDefault().logError("Can't open source file.", e);
}