Author: scabanovich
Date: 2007-10-18 06:27:18 -0400 (Thu, 18 Oct 2007)
New Revision: 4317
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editor/EditorPartWrapper.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/AbstractMultiPageContributor.java
Log:
JBIDE-800
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editor/EditorPartWrapper.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editor/EditorPartWrapper.java 2007-10-18
05:19:22 UTC (rev 4316)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editor/EditorPartWrapper.java 2007-10-18
10:27:18 UTC (rev 4317)
@@ -12,13 +12,21 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.jboss.tools.common.core.resources.XModelObjectEditorInput;
import org.jboss.tools.common.editor.NullEditorPart;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
@@ -26,12 +34,16 @@
import org.eclipse.ui.IReusableEditor;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.SubActionBars;
import org.eclipse.ui.internal.part.NullEditorInput;
import org.eclipse.ui.part.EditorPart;
+import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.part.Page;
import org.eclipse.ui.part.WorkbenchPart;
+import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.jboss.tools.common.model.XModelObject;
-//import org.jboss.tools.common.text.xml.internal.ui.xmleditor.XmlEditor;
import org.jboss.tools.common.model.ui.ModelUIPlugin;
import org.jboss.tools.common.text.ext.IEditorWrapper;
@@ -75,7 +87,7 @@
editor = new NullEditorPart();
editor.init(site, input);
setSite(site);
- setInput(input);
+ super.setInput(input);
return;
}
entity = computeEntity(input);
@@ -93,11 +105,52 @@
editor.init(site, input);
setSite(site);
editor.addPropertyListener(new PCL());
- setInput(input);
+ super.setInput(input);
}
-
- public void setInput(IEditorInput input) {
+
+ public void setInput(IEditorInput input) {
super.setInput(input);
+ if(editor != null) {
+ editor.dispose();
+ editor = null;
+ }
+ if(parent != null && !parent.isDisposed()) {
+ Control[] cs = parent.getChildren();
+ for (int i = 0; i < cs.length; i++) {
+ if(!cs[i].isDisposed()) cs[i].dispose();
+ }
+ }
+ try {
+ init((IEditorSite)getSite(), input);
+ } catch (PartInitException e) {
+ ModelUIPlugin.getPluginLog().logError(e);
+ return;
+ }
+ if(parent != null && !parent.isDisposed()) {
+ createPartControl(parent);
+ }
+ if(wrapper != null) {
+ IContentOutlinePage outline =
(IContentOutlinePage)editor.getAdapter(IContentOutlinePage.class);
+ wrapper.setOutline(outline);
+ if(outline instanceof Page) {
+ ((SubActionBars)wrapper.getSite().getActionBars()).dispose();
+ ((Page)outline).init(wrapper.getSite());
+ wrapper.getSite().getActionBars().updateActionBars();
+ Control[] cs = wrapper.control.getChildren();
+ for (int i = 0; i < cs.length; i++) {
+ if(!cs[i].isDisposed()) cs[i].dispose();
+ }
+ outline.createControl(wrapper.control);
+ outline.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
+ wrapper.control.update();
+ wrapper.control.layout();
+ wrapper.control.getParent().update();
+ wrapper.control.getParent().layout();
+ wrapper.control.getParent().getParent().update();
+ wrapper.control.getParent().getParent().layout();
+ ((SubActionBars)wrapper.getSite().getActionBars()).getToolBarManager().update(true);
+ }
+ }
}
static String DEFAULT_ENTITY = "xml";
@@ -117,8 +170,11 @@
super.addPropertyListener(l);
if(editor != null) editor.addPropertyListener(l);
}
+
+ Composite parent;
public void createPartControl(Composite parent) {
+ this.parent = parent;
if(editor != null) editor.createPartControl(parent);
parent.layout();
}
@@ -159,9 +215,22 @@
public void setFocus() {
if(editor != null) editor.setFocus();
}
-
+
+ COPWrapper wrapper = null;
+
public Object getAdapter(Class adapter) {
- return (editor == null) ? super.getAdapter(adapter) : editor.getAdapter(adapter);
+ if(editor == null) {
+ return super.getAdapter(adapter);
+ }
+ if(adapter != null && adapter.isAssignableFrom(IContentOutlinePage.class)) {
+ if(wrapper != null) return wrapper;
+ wrapper = new COPWrapper();
+ IContentOutlinePage outline = (IContentOutlinePage)editor.getAdapter(adapter);
+ wrapper.setOutline(outline);
+ return wrapper;
+ }
+
+ return editor.getAdapter(adapter);
}
public void doSave(IProgressMonitor monitor) {
@@ -195,10 +264,87 @@
class PCL implements IPropertyListener {
public void propertyChanged(Object source, int i) {
if(i == IEditorPart.PROP_INPUT && getEditorInput() != editor.getEditorInput())
{
- setInput(editor.getEditorInput());
+ EditorPartWrapper.super.setInput(editor.getEditorInput());
}
firePropertyChange(i);
}
}
}
+
+class COPWrapper extends ContentOutlinePage {
+ IContentOutlinePage outline;
+ Composite control;
+ private ArrayList<ISelectionChangedListener> selectionChangedListeners = new
ArrayList<ISelectionChangedListener>();
+
+ public COPWrapper() {}
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ selectionChangedListeners.add(listener);
+ if(outline != null) outline.addSelectionChangedListener(listener);
+ }
+
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ selectionChangedListeners.remove(listener);
+ if(outline != null) outline.removeSelectionChangedListener(listener);
+ }
+
+ public void setOutline(IContentOutlinePage outline) {
+ this.outline = outline;
+ if(outline != null) for (ISelectionChangedListener l: selectionChangedListeners) {
+ outline.addSelectionChangedListener(l);
+ }
+ }
+
+ public void init(IPageSite pageSite) {
+ super.init(pageSite);
+ if(outline instanceof Page) {
+ ((Page)outline).init(pageSite);
+ }
+ }
+
+ public Control getControl() {
+ return control;
+ }
+
+ public void createControl(Composite parent) {
+ control = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = 0;
+ control.setLayout(layout);
+ control.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ if(outline != null) {
+ outline.createControl(control);
+ outline.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
+ }
+ }
+
+ public ISelection getSelection() {
+ return outline != null ? outline.getSelection() : null;
+ }
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ if(outline instanceof ContentOutlinePage) {
+ ((ContentOutlinePage)outline).selectionChanged(event);
+ }
+ }
+
+ public void setFocus() {
+ if(outline != null) outline.setFocus();
+ }
+
+ public void setSelection(ISelection selection) {
+ if(outline != null) outline.setSelection(selection);
+ }
+
+ public void dispose() {
+ if(outline != null) outline.dispose();
+ if(control != null) {
+ if(!control.isDisposed()) control.dispose();
+ control = null;
+ }
+ super.dispose();
+ }
+
+}
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/AbstractMultiPageContributor.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/AbstractMultiPageContributor.java 2007-10-18
05:19:22 UTC (rev 4316)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/AbstractMultiPageContributor.java 2007-10-18
10:27:18 UTC (rev 4317)
@@ -18,6 +18,7 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
+import org.eclipse.ui.handlers.IHandlerActivation;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.ide.IDEActionFactory;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
@@ -220,19 +221,28 @@
};
Map<IAction, ActionHandler> used = new HashMap<IAction, ActionHandler>();
+ Map<String, IHandlerActivation> registered = new HashMap<String,
IHandlerActivation>();
public void registerKeyBindings(IHandlerService handler, String[] actions, ITextEditor
editor) {
for (int i = 0; i < actions.length; i++) {
IAction action = editor.getAction(actions[i]);
- if(action == null) continue;
- ActionHandler h = used.get(action);
- if(h == null) {
- h = new ActionHandler(action);
- used.put(action, h);
- }
- handler.activateHandler(actions[i], h);
+ registerKeyBinding(handler, actions[i], action);
}
}
+
+ protected void registerKeyBinding(IHandlerService handler, String command, IAction
action) {
+ if(action == null) return;
+ ActionHandler h = used.get(action);
+ if(h == null) {
+ h = new ActionHandler(action);
+ used.put(action, h);
+ }
+ String id = action.getId();
+ IHandlerActivation c = registered.get(id);
+ if(c != null) handler.deactivateHandler(c);
+ IHandlerActivation a = handler.activateHandler(command, h);
+ if(a != null) registered.put(id, a);
+ }
protected class AFakeTextEditor implements ITextEditor, ITextOperationTarget {
protected HashMap<String,IAction> actions = new HashMap<String,IAction>();
Show replies by date