Author: scabanovich
Date: 2009-10-06 09:41:44 -0400 (Tue, 06 Oct 2009)
New Revision: 17929
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/IPalettePageAdapter.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/PaletteCreator.java
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/IPaletteAdapter.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/PaletteAdapter.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/PaletteViewPart.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4976
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/IPaletteAdapter.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/IPaletteAdapter.java 2009-10-06
13:33:22 UTC (rev 17928)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/IPaletteAdapter.java 2009-10-06
13:41:44 UTC (rev 17929)
@@ -14,8 +14,9 @@
import org.eclipse.swt.widgets.Control;
public interface IPaletteAdapter {
- void setPaletteViewPart(PaletteViewPart viewPart);
- Control createControl(Composite composite);
+ public void setPaletteViewPart(IPalettePageAdapter viewPart);
+ public Control createControl(Composite composite);
+ public void initActionBars();
void setEnabled(boolean enabled);
void dispose();
void setPaletteContents(PaletteContents contents);
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/IPalettePageAdapter.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/IPalettePageAdapter.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/IPalettePageAdapter.java 2009-10-06
13:41:44 UTC (rev 17929)
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.ui.views.palette;
+
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchPage;
+import org.jboss.tools.common.model.XModelObject;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public interface IPalettePageAdapter {
+ public IActionBars getActionBars();
+ public void insertIntoEditor(XModelObject macro);
+ public boolean isEnabled();
+ public void setContentDescription(String description);
+ public IWorkbenchPage getPage();
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/IPalettePageAdapter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/PaletteAdapter.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/PaletteAdapter.java 2009-10-06
13:33:22 UTC (rev 17928)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/PaletteAdapter.java 2009-10-06
13:41:44 UTC (rev 17929)
@@ -58,7 +58,7 @@
public class PaletteAdapter implements IPaletteAdapter {
private static final int TEXT_MARGIN = 4;
- private PaletteViewPart viewPart = null;
+ private IPalettePageAdapter viewPart = null;
private PaletteModel model = null;
private ScrolledComposite pane = null;
private PaletteModelListener modelListener = null;
@@ -69,10 +69,31 @@
private String selectedTab = null;
private boolean fWindowsFlag;
- public void setPaletteViewPart(PaletteViewPart viewPart) {
+ public void setPaletteViewPart(IPalettePageAdapter viewPart) {
this.viewPart = viewPart;
}
+ public void initActionBars() {
+ IActionBars bars = viewPart.getActionBars();
+ if(bars != null) {
+ IMenuManager menuManager = bars.getMenuManager();
+
+ bars.getToolBarManager().add(new PaletteEditAction());
+ bars.getToolBarManager().add(new ShowHideTabsAction());
+ if (selectedTab != null) {
+ ActionContributionItem item = (ActionContributionItem)menuManager.find(selectedTab);
+ if (item != null) {
+ item.getAction().run();
+ }
+ } else {
+ IContributionItem[] actions = menuManager.getItems();
+ if (actions.length > 0 && (actions[0] instanceof ActionContributionItem))
{
+ ((ActionContributionItem)actions[0]).getAction().run();
+ }
+ }
+ }
+ }
+
public Control createControl(Composite composite) {
String osName = System.getProperty("os.name"); //$NON-NLS-1$
fWindowsFlag = osName != null &&
osName.toUpperCase().indexOf("WINDOWS") != -1; //$NON-NLS-1$
@@ -94,31 +115,16 @@
model = PaletteModel.getInstance();
createPaletteTabs();
- IActionBars bars = viewPart.getViewSite().getActionBars();
- IMenuManager menuManager = bars.getMenuManager();
+// initActionBars();
- bars.getToolBarManager().add(new PaletteEditAction());
- bars.getToolBarManager().add(new ShowHideTabsAction());
-
modelListener = new PaletteModelListener();
model.addModelTreeListener(modelListener);
- if (selectedTab != null) {
- ActionContributionItem item = (ActionContributionItem)menuManager.find(selectedTab);
- if (item != null) {
- item.getAction().run();
- }
- } else {
- IContributionItem[] actions = menuManager.getItems();
- if (actions.length > 0 && (actions[0] instanceof ActionContributionItem))
{
- ((ActionContributionItem)actions[0]).getAction().run();
- }
- }
return pane;
}
private void createPaletteTabs() {
- IActionBars bars = viewPart.getViewSite().getActionBars();
+ IActionBars bars = viewPart.getActionBars();
IMenuManager menuManager = bars.getMenuManager();
IPaletteNode root = model.getRoot();
IPaletteNode[] nodes = root.getChildren();
@@ -193,7 +199,7 @@
private void reload(XModelObject xtab) {
model.reload();
- IActionBars bars = viewPart.getViewSite().getActionBars();
+ IActionBars bars = viewPart.getActionBars();
IMenuManager menuManager = bars.getMenuManager();
String oldTitle = null;
@@ -252,14 +258,14 @@
oldTabs[i].dispose();
}
- setEnabled(viewPart.idEnabled());
+ setEnabled(viewPart.isEnabled());
}
public void dispose() {
dropManager.dispose();
descriptionManager.dispose();
model.removeModelTreeListener(modelListener);
- viewPart.getViewSite().getActionBars().getToolBarManager().removeAll();
+ viewPart.getActionBars().getToolBarManager().removeAll();
try {
if (selectedTab != null) {
ModelUIPlugin.getWorkspace().getRoot().setPersistentProperty(persistentTabQualifiedName,
selectedTab);
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/PaletteCreator.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/PaletteCreator.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/PaletteCreator.java 2009-10-06
13:41:44 UTC (rev 17929)
@@ -0,0 +1,249 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.ui.views.palette;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Properties;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.MultiPageEditorPart;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.osgi.framework.Bundle;
+
+import org.jboss.tools.common.meta.action.SpecialWizard;
+import org.jboss.tools.common.meta.action.SpecialWizardFactory;
+import org.jboss.tools.common.meta.action.XActionInvoker;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
+import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
+import org.jboss.tools.common.model.ui.editor.EditorPartWrapper;
+
+public class PaletteCreator {
+
+ public static final String PALETTE_GEF_ID = "org.jboss.tools.vpe.ui.palette";
//$NON-NLS-1$
+
+ IPalettePageAdapter palettePage;
+
+ private IPaletteAdapter paletteAdapter = null;
+ private Composite root = null;
+ private Control palette = null;
+ private IWorkbenchPart lastPart = null;
+ private boolean lastPaletteEnabled = false;
+
+ public PaletteCreator(IPalettePageAdapter palettePage) {
+ this.palettePage = palettePage;
+ }
+
+ public void createPartControlImpl(Composite parent) {
+ paletteAdapter = createPaletteAdapter();
+ paletteAdapter.setPaletteContents(null);
+ paletteAdapter.setPaletteViewPart(palettePage);
+ root = new Composite(parent, SWT.NONE);
+ root.setLayout(new FillLayout());
+ palette = paletteAdapter.createControl(root);
+ }
+
+ public void initActionBars() {
+ paletteAdapter.initActionBars();
+ }
+
+ public Control getControl() {
+ return root;
+ }
+
+ private IPaletteAdapter createPaletteAdapter() {
+ try {
+ Bundle b = Platform.getBundle(PALETTE_GEF_ID);
+ Class cls = b == null ? null :
b.loadClass("org.jboss.tools.vpe.ui.palette.PaletteAdapter"); //$NON-NLS-1$
+ if(cls != null) return (IPaletteAdapter)cls.newInstance();
+ } catch (ClassNotFoundException t) {
+ //ignore
+ } catch (InstantiationException e) {
+ //ignore
+ } catch (IllegalAccessException e) {
+ //ignore
+ }
+ return new PaletteAdapter();
+ }
+
+ public void dispose() {
+ if (palette != null) {
+ if (!palette.isDisposed())
+ palette.dispose();
+ palette = null;
+ }
+ if (root != null) {
+ if (!root.isDisposed())
+ root.dispose();
+ root = null;
+ }
+ //TODO
+// getSite().getPage().removePartListener(this);
+ if (paletteAdapter != null)
+ paletteAdapter.dispose();
+ paletteAdapter = null;
+ }
+
+ public void setFocus() {
+ if(palette != null && !palette.isDisposed()) palette.setFocus();
+ }
+
+ public void partActivated(IWorkbenchPart part) {
+ IEditorPart part1 =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ if (part1 instanceof IEditorPart) {
+ paletteAdapter.setPaletteContents(new PaletteContents((IEditorPart)part1));
+ lastPaletteEnabled = true;
+ paletteAdapter.setEnabled(lastPaletteEnabled);
+ lastPart = part1;
+ } else {
+ paletteAdapter.setEnabled(false);
+ }
+
+ }
+
+ public void partClosed(IWorkbenchPart part) {
+ if (lastPart != null && palettePage.getPage().getActiveEditor() != lastPart) {
+ lastPart = null;
+ paletteAdapter.setPaletteContents(new PaletteContents(null));
+ paletteAdapter.setEnabled(lastPaletteEnabled = false);
+ }
+ }
+
+ public void insertIntoEditor(XModelObject macro) {
+ IWorkbenchPage page = palettePage.getPage();
+ IEditorPart part = page.getActiveEditor();
+ if (part == null) return;
+ ITextEditor editor = getActiveTextEditor(part);
+
+ /// It is not a text editor
+ if(editor == null) return;
+ /// Do we need a warning here?
+ if(!editor.isEditable()) return;
+
+ if(dropIntoEditor(editor, macro)) return;
+ if(dropIntoEditor2(editor, macro)) return;
+
+ //TODO implement a service
+/**
+ String tagname = macro.getAttributeValue("name"); //$NON-NLS-1$
+ String startText = "" + macro.getAttributeValue("start text");
//$NON-NLS-1$ //$NON-NLS-2$
+ String endText = "" + macro.getAttributeValue("end text");
//$NON-NLS-1$ //$NON-NLS-2$
+ String newline = "" + macro.getAttributeValue("new line");
//$NON-NLS-1$ //$NON-NLS-2$
+ String reformat = "" + macro.getAttributeValue("automatically reformat
tag body"); //$NON-NLS-1$ //$NON-NLS-2$
+ XModelObject parent = macro.getParent();
+ String uri = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
+ String libraryVersion = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_VERSION); //$NON-NLS-1$
+ String defaultPrefix = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
+ String addTaglib = (parent == null) ? "" : parent.getAttributeValue("add
taglib"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (editor != null) {
+ Properties properties = new Properties();
+ properties.setProperty(PaletteInsertHelper.PROPOPERTY_TAG_NAME, tagname);
+ properties.setProperty(PaletteInsertHelper.PROPOPERTY_TAGLIBRARY_URI, uri);
+ properties.setProperty(PaletteInsertHelper.PROPOPERTY_TAGLIBRARY_VERSION,
libraryVersion);
+ properties.setProperty(PaletteInsertHelper.PROPOPERTY_DEFAULT_PREFIX, defaultPrefix);
+
+ if(startText != null)
properties.setProperty(PaletteInsertHelper.PROPOPERTY_START_TEXT, startText);
+ if(endText != null) properties.setProperty(PaletteInsertHelper.PROPOPERTY_END_TEXT,
endText);
+ properties.setProperty(PaletteInsertHelper.PROPOPERTY_REFORMAT_BODY, reformat);
+ properties.setProperty(PaletteInsertHelper.PROPOPERTY_NEW_LINE, newline);
+ properties.setProperty(PaletteInsertHelper.PROPOPERTY_ADD_TAGLIB, addTaglib);
+
+ //TODO WARNING we cannot have here correct insert helper instance!
+ PaletteInsertHelper.getInstance().insertIntoEditor(
+ editor,
+ properties
+ );
+ page.activate(part);
+ }
+*/
+ }
+
+ private boolean dropIntoEditor(ITextEditor editor, XModelObject macro) {
+ try {
+ Method m = editor.getClass().getMethod("runDropCommand", new
Class[]{String.class, String.class}); //$NON-NLS-1$
+ if(m == null) return false;
+ m.setAccessible(true);
+ Properties p = new Properties();
+ p.setProperty("isDrag", "true"); //$NON-NLS-1$ //$NON-NLS-2$
+ XActionInvoker.invoke("CopyActions.Copy", macro, p); //$NON-NLS-1$
+ m.invoke(editor, new Object[]{ModelTransfer.MODEL, null});
+ return true;
+ } catch (NoSuchMethodException ne) {
+ return false;
+ } catch (IllegalAccessException e) {
+ ModelUIPlugin.getPluginLog().logError(e);
+ return false;
+ } catch (IllegalArgumentException e) {
+ ModelUIPlugin.getPluginLog().logError(e);
+ return false;
+ } catch (InvocationTargetException e) {
+ ModelUIPlugin.getPluginLog().logError(e);
+ return false;
+ }
+ }
+ private boolean dropIntoEditor2(ITextEditor editor, XModelObject macro) {
+ SpecialWizard w =
SpecialWizardFactory.createSpecialWizard("org.jboss.tools.jst.jsp.outline.DefaultDropCommandRunner");
//$NON-NLS-1$
+ if(w == null) return false;
+ Properties p = new Properties();
+ p.setProperty("isDrag", "true"); //$NON-NLS-1$ //$NON-NLS-2$
+ XActionInvoker.invoke("CopyActions.Copy", macro, p); //$NON-NLS-1$
+ p.setProperty("flavor", ModelTransfer.MODEL); //$NON-NLS-1$
+ p.put("textEditor", editor); //$NON-NLS-1$
+ w.setObject(p);
+ int r = w.execute();
+ return r == 0;
+ }
+
+ public boolean isEnabled() {
+ return lastPart != null; //lastTextEditor != null;
+ }
+
+ // TODO: NLS support
+ private static final String ERROR_GETTING_ACTIVE_EDITOR = "Error while getting
active text editor";
+
+ // FIXME: Rewrite without reflection
+ private ITextEditor getActiveTextEditor(IWorkbenchPart part) {
+ ITextEditor editor = null;
+ if (part instanceof EditorPartWrapper) {
+ part = ((EditorPartWrapper)part).getEditor();
+ }
+ if (part instanceof ITextEditor) {
+ editor = (ITextEditor)part;
+ } else if (part instanceof MultiPageEditorPart) {
+ try {
+ Method m = MultiPageEditorPart.class.getDeclaredMethod("getActiveEditor",
new Class[0]); //$NON-NLS-1$
+ m.setAccessible(true);
+ Object o = m.invoke(part, new Object[0]);
+ if (o instanceof ITextEditor) {
+ editor = (ITextEditor)o;
+ }
+ } catch (NoSuchMethodException t) {
+ ModelUIPlugin.getPluginLog().logError(ERROR_GETTING_ACTIVE_EDITOR, t);
+ } catch (IllegalArgumentException t) {
+ ModelUIPlugin.getPluginLog().logError(ERROR_GETTING_ACTIVE_EDITOR, t);
+ } catch (IllegalAccessException t) {
+ ModelUIPlugin.getPluginLog().logError(ERROR_GETTING_ACTIVE_EDITOR, t);
+ } catch (InvocationTargetException t) {
+ ModelUIPlugin.getPluginLog().logError(ERROR_GETTING_ACTIVE_EDITOR, t);
+ }
+ }
+ return editor;
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/PaletteCreator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/PaletteViewPart.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/PaletteViewPart.java 2009-10-06
13:33:22 UTC (rev 17928)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/palette/PaletteViewPart.java 2009-10-06
13:41:44 UTC (rev 17929)
@@ -10,119 +10,55 @@
******************************************************************************/
package org.jboss.tools.common.model.ui.views.palette;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Properties;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.part.ViewPart;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.osgi.framework.Bundle;
-import org.jboss.tools.common.meta.action.SpecialWizard;
-import org.jboss.tools.common.meta.action.SpecialWizardFactory;
-import org.jboss.tools.common.meta.action.XActionInvoker;
import org.jboss.tools.common.model.XModelObject;
-import org.jboss.tools.common.model.ui.ModelUIPlugin;
-import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
-import org.jboss.tools.common.model.ui.editor.EditorPartWrapper;
-public class PaletteViewPart extends ViewPart implements IPartListener {
+public class PaletteViewPart extends ViewPart implements IPartListener,
IPalettePageAdapter {
public static final String VIEW_ID =
"org.jboss.tools.common.model.ui.views.palette.PaletteView"; //$NON-NLS-1$
- public static final String PALETTE_GEF_ID = "org.jboss.tools.vpe.ui.palette";
//$NON-NLS-1$
- private IPaletteAdapter paletteAdapter = null;
- private Composite root = null;
- private Control palette = null;
- private IWorkbenchPart lastPart = null;
- private boolean lastPaletteEnabled = false;
+ PaletteCreator paletteCreator = new PaletteCreator(this);
+ public PaletteViewPart() {}
+
+ public IWorkbenchPage getPage() {
+ return getSite().getPage();
+ }
+
public void createPartControl(Composite parent) {
- createPartControlImpl(parent);
+ paletteCreator.createPartControlImpl(parent);
+ paletteCreator.initActionBars();
}
- protected void setContentDescription(String description) {
+ public void setContentDescription(String description) {
super.setContentDescription(description);
}
- private void createPartControlImpl(Composite parent) {
- paletteAdapter = createPaletteAdapter();
- paletteAdapter.setPaletteContents(null);
- paletteAdapter.setPaletteViewPart(this);
- root = new Composite(parent, SWT.NONE);
- root.setLayout(new FillLayout());
- palette = paletteAdapter.createControl(root);
- }
-
- private IPaletteAdapter createPaletteAdapter() {
- try {
- Bundle b = Platform.getBundle(PALETTE_GEF_ID);
- Class cls = b == null ? null :
b.loadClass("org.jboss.tools.vpe.ui.palette.PaletteAdapter"); //$NON-NLS-1$
- if(cls != null) return (IPaletteAdapter)cls.newInstance();
- } catch (ClassNotFoundException t) {
- //ignore
- } catch (InstantiationException e) {
- //ignore
- } catch (IllegalAccessException e) {
- //ignore
- }
- return new PaletteAdapter();
- }
-
public void dispose() {
super.dispose();
- if (palette != null) {
- if (!palette.isDisposed())
- palette.dispose();
- palette = null;
- }
- if (root != null) {
- if (!root.isDisposed())
- root.dispose();
- root = null;
- }
+ paletteCreator.dispose();
getSite().getPage().removePartListener(this);
- if (paletteAdapter != null)
- paletteAdapter.dispose();
- paletteAdapter = null;
}
public void setFocus() {
- if(palette != null && !palette.isDisposed()) palette.setFocus();
+ paletteCreator.setFocus();
}
public void partActivated(IWorkbenchPart part) {
- IEditorPart part1 =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- if (part1 instanceof IEditorPart) {
- paletteAdapter.setPaletteContents(new PaletteContents((IEditorPart)part1));
- lastPaletteEnabled = true;
- paletteAdapter.setEnabled(lastPaletteEnabled);
- lastPart = part1;
- } else {
- paletteAdapter.setEnabled(false);
- }
-
+ paletteCreator.partActivated(part);
}
public void partBroughtToTop(IWorkbenchPart part) {
}
public void partClosed(IWorkbenchPart part) {
- if (lastPart != null && getSite().getPage().getActiveEditor() != lastPart) {
- lastPart = null;
- paletteAdapter.setPaletteContents(new PaletteContents(null));
- paletteAdapter.setEnabled(lastPaletteEnabled = false);
- }
+ paletteCreator.partClosed(part);
}
public void partDeactivated(IWorkbenchPart part) {}
@@ -130,124 +66,15 @@
public void partOpened(IWorkbenchPart part) {}
public void insertIntoEditor(XModelObject macro) {
- IWorkbenchPage page = getSite().getPage();
- IEditorPart part = page.getActiveEditor();
- if (part == null) return;
- ITextEditor editor = getActiveTextEditor(part);
-
- /// It is not a text editor
- if(editor == null) return;
- /// Do we need a warning here?
- if(!editor.isEditable()) return;
-
- if(dropIntoEditor(editor, macro)) return;
- if(dropIntoEditor2(editor, macro)) return;
-
- //TODO implement a service
-/**
- String tagname = macro.getAttributeValue("name"); //$NON-NLS-1$
- String startText = "" + macro.getAttributeValue("start text");
//$NON-NLS-1$ //$NON-NLS-2$
- String endText = "" + macro.getAttributeValue("end text");
//$NON-NLS-1$ //$NON-NLS-2$
- String newline = "" + macro.getAttributeValue("new line");
//$NON-NLS-1$ //$NON-NLS-2$
- String reformat = "" + macro.getAttributeValue("automatically reformat
tag body"); //$NON-NLS-1$ //$NON-NLS-2$
- XModelObject parent = macro.getParent();
- String uri = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
- String libraryVersion = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_VERSION); //$NON-NLS-1$
- String defaultPrefix = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
- String addTaglib = (parent == null) ? "" : parent.getAttributeValue("add
taglib"); //$NON-NLS-1$ //$NON-NLS-2$
- if (editor != null) {
- Properties properties = new Properties();
- properties.setProperty(PaletteInsertHelper.PROPOPERTY_TAG_NAME, tagname);
- properties.setProperty(PaletteInsertHelper.PROPOPERTY_TAGLIBRARY_URI, uri);
- properties.setProperty(PaletteInsertHelper.PROPOPERTY_TAGLIBRARY_VERSION,
libraryVersion);
- properties.setProperty(PaletteInsertHelper.PROPOPERTY_DEFAULT_PREFIX, defaultPrefix);
-
- if(startText != null)
properties.setProperty(PaletteInsertHelper.PROPOPERTY_START_TEXT, startText);
- if(endText != null) properties.setProperty(PaletteInsertHelper.PROPOPERTY_END_TEXT,
endText);
- properties.setProperty(PaletteInsertHelper.PROPOPERTY_REFORMAT_BODY, reformat);
- properties.setProperty(PaletteInsertHelper.PROPOPERTY_NEW_LINE, newline);
- properties.setProperty(PaletteInsertHelper.PROPOPERTY_ADD_TAGLIB, addTaglib);
-
- //TODO WARNING we cannot have here correct insert helper instance!
- PaletteInsertHelper.getInstance().insertIntoEditor(
- editor,
- properties
- );
- page.activate(part);
- }
-*/
+ paletteCreator.insertIntoEditor(macro);
}
- private boolean dropIntoEditor(ITextEditor editor, XModelObject macro) {
- try {
- Method m = editor.getClass().getMethod("runDropCommand", new
Class[]{String.class, String.class}); //$NON-NLS-1$
- if(m == null) return false;
- m.setAccessible(true);
- Properties p = new Properties();
- p.setProperty("isDrag", "true"); //$NON-NLS-1$ //$NON-NLS-2$
- XActionInvoker.invoke("CopyActions.Copy", macro, p); //$NON-NLS-1$
- m.invoke(editor, new Object[]{ModelTransfer.MODEL, null});
- return true;
- } catch (NoSuchMethodException ne) {
- return false;
- } catch (IllegalAccessException e) {
- ModelUIPlugin.getPluginLog().logError(e);
- return false;
- } catch (IllegalArgumentException e) {
- ModelUIPlugin.getPluginLog().logError(e);
- return false;
- } catch (InvocationTargetException e) {
- ModelUIPlugin.getPluginLog().logError(e);
- return false;
- }
+ public boolean isEnabled() {
+ return paletteCreator.isEnabled();
}
- private boolean dropIntoEditor2(ITextEditor editor, XModelObject macro) {
- SpecialWizard w =
SpecialWizardFactory.createSpecialWizard("org.jboss.tools.jst.jsp.outline.DefaultDropCommandRunner");
//$NON-NLS-1$
- if(w == null) return false;
- Properties p = new Properties();
- p.setProperty("isDrag", "true"); //$NON-NLS-1$ //$NON-NLS-2$
- XActionInvoker.invoke("CopyActions.Copy", macro, p); //$NON-NLS-1$
- p.setProperty("flavor", ModelTransfer.MODEL); //$NON-NLS-1$
- p.put("textEditor", editor); //$NON-NLS-1$
- w.setObject(p);
- int r = w.execute();
- return r == 0;
- }
- public boolean idEnabled() {
- return lastPart != null; //lastTextEditor != null;
+ public IActionBars getActionBars() {
+ return getViewSite() == null ? null : getViewSite().getActionBars();
}
- // TODO: NLS support
- private static final String ERROR_GETTING_ACTIVE_EDITOR = "Error while getting
active text editor";
-
- // FIXME: Rewrite without reflection
- private ITextEditor getActiveTextEditor(IWorkbenchPart part) {
- ITextEditor editor = null;
- if (part instanceof EditorPartWrapper) {
- part = ((EditorPartWrapper)part).getEditor();
- }
- if (part instanceof ITextEditor) {
- editor = (ITextEditor)part;
- } else if (part instanceof MultiPageEditorPart) {
- try {
- Method m = MultiPageEditorPart.class.getDeclaredMethod("getActiveEditor",
new Class[0]); //$NON-NLS-1$
- m.setAccessible(true);
- Object o = m.invoke(part, new Object[0]);
- if (o instanceof ITextEditor) {
- editor = (ITextEditor)o;
- }
- } catch (NoSuchMethodException t) {
- ModelUIPlugin.getPluginLog().logError(ERROR_GETTING_ACTIVE_EDITOR, t);
- } catch (IllegalArgumentException t) {
- ModelUIPlugin.getPluginLog().logError(ERROR_GETTING_ACTIVE_EDITOR, t);
- } catch (IllegalAccessException t) {
- ModelUIPlugin.getPluginLog().logError(ERROR_GETTING_ACTIVE_EDITOR, t);
- } catch (InvocationTargetException t) {
- ModelUIPlugin.getPluginLog().logError(ERROR_GETTING_ACTIVE_EDITOR, t);
- }
- }
- return editor;
- }
-
}