Author: vrubezhny
Date: 2012-10-18 06:34:04 -0400 (Thu, 18 Oct 2012)
New Revision: 44575
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageSelectionProvider.java
Log:
JBIDE-12783
Missing QuickFix context menu within Source pane of VPE for JSF project
Workaround is committed due to fix the Context Menu.
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java 2012-10-18
10:13:48 UTC (rev 44574)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java 2012-10-18
10:34:04 UTC (rev 44575)
@@ -31,6 +31,8 @@
import org.eclipse.gef.ui.views.palette.PalettePage;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.IPostSelectionProvider;
@@ -42,6 +44,8 @@
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Item;
+import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IEditorActionBarContributor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
@@ -189,6 +193,8 @@
}
}
+
+
private void loadSelectedTab() {
String defaultVpeTab = JspEditorPlugin.getDefault()
.getPreferenceStore().getString(
@@ -496,22 +502,18 @@
case 0: {
// source/visual mode
setActivePage(selectedPageIndex);
-// pageChange(selectedPageIndex);
break;
} case 1: {
// source mode
setActivePage(selectedPageIndex);
-// pageChange(selectedPageIndex);
break;
} case 2: {
// preview mode
setActivePage(selectedPageIndex);
-// pageChange(selectedPageIndex);
break;
} default: {
// by default we sets source/visual mode
setActivePage(0);
-// pageChange(0);
break;
}
}
@@ -531,16 +533,44 @@
*/
vpeIsCreating = false;
}
-
}
+ /*
+ * This Context Menu Listener fixes the 'empty menu items' issue
+ * See JBIDE-12783.
+ */
+ private final class ZContextMenuListener implements IMenuListener
+ {
+ @Override
+ public void menuAboutToShow(IMenuManager manager) {
+ Item[] mi = getMenuItems(manager);
+ for (int i = 0; i < mi.length; i++) {
+ mi[i].dispose();
+ }
+ }
+
+ Item[] getMenuItems(IMenuManager manager) {
+ Menu menu = ((MenuManager)manager).getMenu();
+ return (menu == null) ? new Item[0] : menu.getItems();
+ }
+ }
+
private void createPagesForVPE() throws PartInitException {
/*
* Create Source Editor and BundleMap
*/
- sourceEditor = new JSPTextEditor(this);
+ sourceEditor = new JSPTextEditor(this) {
+ public void createPartControl(Composite parent) {
+ super.createPartControl(parent);
+ Menu m = sourceEditor.getTextViewer().getTextWidget().getMenu();
+ Object data =
m.getData("org.eclipse.jface.action.MenuManager.managerKey");
+ if (data instanceof IMenuManager) {
+ (((IMenuManager)data)).addMenuListener(new ZContextMenuListener());
+ }
+ }
+ };
sourceEditor.setEditorPart(this);
-
+
/*
* Create Bundle Map here but Initialize it in the VpeController
* or here if there is only the source part.
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageSelectionProvider.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageSelectionProvider.java 2012-10-18
10:13:48 UTC (rev 44574)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageSelectionProvider.java 2012-10-18
10:34:04 UTC (rev 44575)
@@ -1,23 +1,22 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 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:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.jst.jsp.jspeditor;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.eclipse.core.runtime.ListenerList;
-import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.jface.text.TextSelection;
-import org.eclipse.jface.util.Assert;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.jface.viewers.*;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.ui.part.MultiPageSelectionProvider;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.filesystems.FileSystemsHelper;
import org.jboss.tools.common.model.filesystems.impl.FileAnyImpl;
@@ -28,60 +27,18 @@
* @author eskimo(dgolovin(a)exadel.com)
*
*/
-public class JSPMultiPageSelectionProvider implements IPostSelectionProvider,
- ISelectionProvider {
-
- private ListenerList listeners = new ListenerList();
-
- private JSPMultiPageEditorPart multiPageEditor;
-
+public class JSPMultiPageSelectionProvider extends MultiPageSelectionProvider {
+ JSPMultiPageEditorPart multiPageEditor;
+
public JSPMultiPageSelectionProvider(JSPMultiPageEditorPart multiPageEditor) {
- Assert.isNotNull(multiPageEditor);
+ super(multiPageEditor);
this.multiPageEditor = multiPageEditor;
}
- Object last = null;
-
- public void addSelectionChangedListener(ISelectionChangedListener listener) {
- listeners.add(listener);
- last = listener;
- }
-
- public void fireSelectionChanged(final SelectionChangedEvent event) {
- Object[] listeners = this.listeners.getListeners();
- for (int i = 0; i < listeners.length; ++i) {
- final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
- SafeRunner.run(new SafeRunnable() {
- public void run() {
- l.selectionChanged(event);
- }
- });
- }
- }
-
public JSPMultiPageEditorPart getMultiPageEditor() {
return multiPageEditor;
}
- public ISelection getSelection() {
- IEditorPart activeEditor = ((JSPMultiPageEditorPart)
multiPageEditor).getActiveEditor();
- if (activeEditor != null) {
- ISelectionProvider selectionProvider = activeEditor.getSite()
- .getSelectionProvider();
- if (selectionProvider != null)
- return selectionProvider.getSelection();
- }
- return null;
- }
-
- /*
- * (non-JavaDoc) Method declaed on <code>ISelectionProvider</code>.
- */
- public void removeSelectionChangedListener(
- ISelectionChangedListener listener) {
- listeners.remove(listener);
- }
-
public void setSelection(ISelection selection) {
selection = convertObjectSelection(selection);
if (!isAppropriateSelected(selection))
@@ -90,13 +47,7 @@
return;
isFiringSelection = true;
try {
- IEditorPart activeEditor = multiPageEditor.getActiveEditor();
- if (activeEditor != null) {
- ISelectionProvider selectionProvider = activeEditor.getSite()
- .getSelectionProvider();
- if (selectionProvider != null)
- selectionProvider.setSelection(selection);
- }
+ super.setSelection(selection);
} finally {
isFiringSelection = false;
}
@@ -131,47 +82,27 @@
return (o instanceof IndexedRegion);
}
- private ListenerList postListeners = new ListenerList();
-
- public void addPostSelectionChangedListener(
- ISelectionChangedListener listener) {
- postListeners.add(listener);
- if (last != null) {
- listeners.remove(last);
- last = null;
- }
- }
-
- public void removePostSelectionChangedListener(
- ISelectionChangedListener listener) {
- postListeners.remove(listener);
- }
-
boolean isFiringSelection = false;
public boolean isFiringSelection() {
return isFiringSelection;
}
- public void firePostSelectionChanged(final SelectionChangedEvent event) {
- fireSelectionChanged(event, postListeners);
- }
-
public void fireSelectionChanged(final SelectionChangedEvent event,
ListenerList listenerList) {
if (isFiringSelection)
return;
- Object[] listeners = listenerList.getListeners();
isFiringSelection = true;
- for (int i = 0; i < listeners.length; ++i) {
- final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
- SafeRunner.run(new SafeRunnable() {
- public void run() {
- l.selectionChanged(event);
- }
- });
- }
+ super.fireSelectionChanged(event);
isFiringSelection = false;
}
+ public void firePostSelectionChanged(final SelectionChangedEvent event,
+ ListenerList listenerList) {
+ if (isFiringSelection)
+ return;
+ isFiringSelection = true;
+ super.firePostSelectionChanged(event);
+ isFiringSelection = false;
+ }
}