Author: yradtsevich
Date: 2011-07-21 05:51:59 -0400 (Thu, 21 Jul 2011)
New Revision: 33096
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/SelectionBarHandler.java
Removed:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/handlers/SelectionBarHandler.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
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/JSPMultiPageEditorPart.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/SelectionBar.java
Log:
https://issues.jboss.org/browse/JBIDE-8439 Selection Bar dissapears on VPE part when it
lost focus for Find/Replace dialogs of content assist proposal list windoe
- fixed issue
- made refactoring
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2011-07-21 03:00:08 UTC (rev
33095)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2011-07-21 09:51:59 UTC (rev
33096)
@@ -493,7 +493,7 @@
</enabledWhen>
</handler>
<handler
-
class="org.jboss.tools.jst.jsp.selection.bar.handlers.SelectionBarHandler"
+ class="org.jboss.tools.jst.jsp.selection.bar.SelectionBarHandler"
commandId="org.jboss.tools.jst.jsp.commands.showSelectionBar">
</handler>
<handler
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 2011-07-21
03:00:08 UTC (rev 33095)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java 2011-07-21
09:51:59 UTC (rev 33096)
@@ -88,6 +88,7 @@
import org.jboss.tools.jst.jsp.editor.IVisualEditor;
import org.jboss.tools.jst.jsp.editor.IVisualEditorFactory;
import org.jboss.tools.jst.jsp.preferences.IVpePreferencesPage;
+import org.jboss.tools.jst.jsp.selection.bar.SelectionBarHandler;
import org.jboss.tools.jst.web.tld.VpeTaglibManager;
import org.jboss.tools.jst.web.tld.VpeTaglibManagerProvider;
@@ -268,9 +269,9 @@
}
ICommandService commandService = (ICommandService) PlatformUI
- .getWorkbench().getService(ICommandService.class);
- commandService.refreshElements("org.jboss.tools.jst.jsp.commands.showSelectionBar",
null); //$NON-NLS-1$
-
+ .getWorkbench().getService(ICommandService.class);
+ commandService.refreshElements(SelectionBarHandler.COMMAND_ID, null);
+ getSelectionBar().refreshVisibility();
superPageChange(newPageIndex);
JspEditorPlugin.getDefault().getPreferenceStore().
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorPart.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorPart.java 2011-07-21
03:00:08 UTC (rev 33095)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorPart.java 2011-07-21
09:51:59 UTC (rev 33096)
@@ -354,6 +354,10 @@
protected CTabFolder getTabFolder() {
return tabFolderContainer;
}
+
+ public SelectionBar getSelectionBar() {
+ return selectionBar;
+ }
protected void handlePropertyChange(int propertyId) {
firePropertyChange(propertyId);
@@ -377,33 +381,8 @@
return false;
}
- protected void pageChange(int newPageIndex) {
- Control control = getControl(newPageIndex);
- if (control != null) {
- control.setVisible(true);
- }
+ protected abstract void pageChange(int newPageIndex);
- setFocus();
- IEditorPart activeEditor = getEditor(newPageIndex);
- IEditorActionBarContributor contributor = getEditorSite()
- .getActionBarContributor();
- if (contributor != null
- && contributor instanceof MultiPageEditorActionBarContributor) {
- ((MultiPageEditorActionBarContributor) contributor)
- .setActivePage(activeEditor);
- }
- if (activeEditor != null) {
- ISelectionProvider selectionProvider = activeEditor.getSite()
- .getSelectionProvider();
- if (selectionProvider != null) {
- SelectionChangedEvent event = new SelectionChangedEvent(
- selectionProvider, selectionProvider.getSelection());
- ((MultiPageSelectionProvider) getSite().getSelectionProvider())
- .fireSelectionChanged(event);
- }
- }
- }
-
private void disposePart(final IWorkbenchPart part) {
SafeRunner.run(new SafeRunnable() {
public void run() {
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/SelectionBar.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/SelectionBar.java 2011-07-21
03:00:08 UTC (rev 33095)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/SelectionBar.java 2011-07-21
09:51:59 UTC (rev 33096)
@@ -49,14 +49,19 @@
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Widget;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
import org.eclipse.ui.internal.WorkbenchImages;
+import org.eclipse.ui.part.EditorPart;
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditorPart;
import org.jboss.tools.jst.jsp.messages.JstUIMessages;
import org.jboss.tools.jst.jsp.selection.SelectionHelper;
import org.jboss.tools.jst.jsp.selection.SourceSelection;
@@ -73,7 +78,7 @@
* @author yradtsevich
* @author mareshkau
*/
-public class SelectionBar extends Composite implements ISelectionChangedListener,
IStateListener,ICommandListener{
+public class SelectionBar extends Composite {
private static final int SEL_ITEM_RIGHT_MARGIN = 5;
/*
* The main composite that holds all other controls
@@ -104,24 +109,39 @@
*/
private State toggleSelBarState;
private Command toggleSelBarCommand;
+ private ICommandListener toggleSelBarCommandListener;
+ private ISelectionChangedListener selectionChangedListener;
private ImageButton arrowButton;
public SelectionBar(StructuredTextEditor textEditor, Composite parent,
int style) {
super(parent, style);
this.textEditor = textEditor;
- if(this.textEditor.getTextViewer()!= null) {
- this.textEditor.getTextViewer().addSelectionChangedListener(this);
+
+ if (this.textEditor.getTextViewer() != null) {
+ selectionChangedListener = new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ updateNodes(true);
+ }
+ };
+ this.textEditor.getTextViewer().addSelectionChangedListener(selectionChangedListener);
}
-
+
ICommandService commandService = (ICommandService) PlatformUI
.getWorkbench().getService(ICommandService.class);
- this.toggleSelBarCommand = commandService
- .getCommand("org.jboss.tools.jst.jsp.commands.showSelectionBar");
//$NON-NLS-1$
+ this.toggleSelBarCommand = commandService.getCommand(SelectionBarHandler.COMMAND_ID);
toggleSelBarState = toggleSelBarCommand
.getState("org.eclipse.ui.commands.toggleState"); //$NON-NLS-1$
- toggleSelBarState.addListener(this);
- toggleSelBarCommand.addCommandListener(this);
+
+ toggleSelBarCommandListener = new ICommandListener() {
+ @Override
+ public void commandChanged(CommandEvent commandEvent) {
+ refreshVisibility();
+ }
+ };
+ toggleSelBarCommand.addCommandListener(toggleSelBarCommandListener);
+
this.setLayout(new FillLayout());
/*
* Create the Selection Bar Composite in its constructor
@@ -158,6 +178,7 @@
.getImage(ISharedImages.IMG_TOOL_DELETE);
final Listener closeListener = new Listener() {
+ @Override
public void handleEvent(Event event) {
/*
* Hide the selection bar
@@ -194,6 +215,7 @@
* Sets {@code visible} state to this {@code SelectionBar} and fires
* all registered {@code VisibilityListener}s.
*/
+ @Override
public void setVisible(boolean visible) {
if (visible) {
splitter.setVisible(realBar, true);
@@ -214,8 +236,22 @@
this.getParent().layout(true, true);
tempItem.dispose();
}
+
+ public void refreshVisibility() {
+ boolean visible = (Boolean) toggleSelBarState.getValue();
+ IEditorPart editorPart = textEditor.getEditorPart();
+ if(editorPart instanceof JSPMultiPageEditor){
+ JSPMultiPageEditor jspEditor = (JSPMultiPageEditor) editorPart;
+ if(jspEditor.getSelectedPageIndex() == jspEditor.getPreviewIndex()){
+ visible = false;
+ }
+ }
+
+ setVisible(visible);
+ }
+
/**
* Updates buttons in the selection bar and the drop-down menu
* according to the source selection.
@@ -291,9 +327,9 @@
// for now dropDownMenu = null
int elementCounter = 0;
- while ((node != null)
- && ((node.getNodeType() == Node.ELEMENT_NODE)
- || (node.getNodeType() == Node.COMMENT_NODE))) {
+ while (node != null
+ && (node.getNodeType() == Node.ELEMENT_NODE
+ || node.getNodeType() == Node.COMMENT_NODE)) {
addNodeListenerTo(node);
/*
@@ -311,12 +347,14 @@
/*
* for the last tag -- show check button
*/
- if ((elementCounter == 0) && (list.size() == 0)){
+ if (elementCounter == 0 && list.size() == 0){
item = new ToolItem(toolbar, SWT.FLAT | SWT.CHECK, 1);
item.addSelectionListener(new SelectionListener() {
+ @Override
public void widgetSelected(SelectionEvent e) {
handleSelectionEvent(e);
}
+ @Override
public void widgetDefaultSelected(SelectionEvent e) {
handleSelectionEvent(e);
}
@@ -334,6 +372,7 @@
* Thus unnecessary memory will be released.
*/
item.addDisposeListener(new DisposeListener() {
+ @Override
public void widgetDisposed(DisposeEvent e) {
dropdownListener.disposeMenu();
}
@@ -359,9 +398,11 @@
if (dropDownMenu != null) {
MenuItem menuItem = new MenuItem(dropDownMenu, SWT.CHECK, 0);
menuItem.addSelectionListener(new SelectionListener() {
+ @Override
public void widgetSelected(SelectionEvent e) {
handleSelectionEvent(e);
}
+ @Override
public void widgetDefaultSelected(SelectionEvent e) {
handleSelectionEvent(e);
}
@@ -388,6 +429,7 @@
if (!resizeListenerAdded ) {
realBar.addListener(SWT.Resize, new Listener() {
+ @Override
public void handleEvent(Event event) {
updateNodes(true);
}
@@ -438,6 +480,7 @@
arrowButton.setEnabled(false);
arrowButton.addSelectionListener(
new Listener() {
+ @Override
public void handleEvent(Event event) {
Rectangle bounds = arrowButton.getButtonBounds();
Point point = toolbar.toDisplay(bounds.x, bounds.y
@@ -512,12 +555,14 @@
nodeNotifiers.clear();
}
- public void dispose() {
+ @Override
+ public void dispose() {
removeNodeListenerFromAllNodes();
- toggleSelBarCommand.removeCommandListener(this);
- if(textEditor.getTextViewer()!=null)
- textEditor.getTextViewer().removeSelectionChangedListener(this);
- toggleSelBarState.removeListener(this);
+ toggleSelBarCommand.removeCommandListener(toggleSelBarCommandListener);
+ if (textEditor.getTextViewer() != null) {
+ textEditor.getTextViewer().removeSelectionChangedListener(selectionChangedListener);
+ }
+
if (splitter != null) {
splitter.dispose();
splitter = null;
@@ -601,6 +646,7 @@
menuItem.setText(node.getNodeName());
menuItem.setData(node);
menuItem.addSelectionListener(new SelectionAdapter() {
+ @Override
public void widgetSelected(SelectionEvent event) {
handleSelectionEvent(event);
}
@@ -613,6 +659,7 @@
* @param event
* the event that trigged this call
*/
+ @Override
public void widgetSelected(SelectionEvent event) {
/*
* If they clicked the arrow, we show the list or close it
@@ -629,18 +676,20 @@
*/
if (menu == null) {
menu = new Menu(dropdown.getParent());
- if ((children != null) && (children.size() > 0)) {
+ if (children != null && children.size() > 0) {
for (Node node : children) {
add(node);
}
}
}
menu.addMenuListener(new MenuListener() {
+ @Override
public void menuShown(MenuEvent e) {
/*
* Do nothing
*/
}
+ @Override
public void menuHidden(MenuEvent e) {
/*
* Change the 'shown' state
@@ -667,18 +716,6 @@
}
}
}
-
- public void selectionChanged(SelectionChangedEvent event) {
- updateNodes(true);
- }
-
- public void handleStateChange(State state, Object oldValue) {
- setVisible(toggleSelBarCommand.isEnabled()&&(Boolean)state.getValue());
- }
-
- public void commandChanged(CommandEvent commandEvent) {
- setVisible(toggleSelBarCommand.isEnabled()&&(Boolean)commandEvent.getCommand().getState("org.eclipse.ui.commands.toggleState").getValue());
//$NON-NLS-1$
- }
}
/**
@@ -695,6 +732,7 @@
public ImageButton(Composite parent, Image image, String toolTip) {
composite = new Composite(parent, SWT.NONE);
composite.addDisposeListener(new DisposeListener() {
+ @Override
public void widgetDisposed(DisposeEvent e) {
release();
}
@@ -787,7 +825,8 @@
* identity comparison to 'type', but this is not required, that is, the
* decision can be based on complex logic.
*/
- public boolean isAdapterForType(Object type) {
+ @Override
+ public boolean isAdapterForType(Object type) {
return selectionBar == type;
}
@@ -798,8 +837,8 @@
* ISSUE: may be more evolvable if the argument was one big 'notifier
* event' instance.
*/
- public void notifyChanged(INodeNotifier notifier, int eventType, Object
changedFeature, Object oldValue, Object newValue, int pos) {
+ @Override
+ public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature,
Object oldValue, Object newValue, int pos) {
selectionBar.updateNodes(false);
}
- }
-
+}
Copied:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/SelectionBarHandler.java
(from rev 33041,
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/handlers/SelectionBarHandler.java)
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/SelectionBarHandler.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/SelectionBarHandler.java 2011-07-21
09:51:59 UTC (rev 33096)
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.jst.jsp.selection.bar;
+
+import java.util.Map;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.HandlerEvent;
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.commands.IElementUpdater;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.menus.UIElement;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+
+/**
+ * Selection bar handler
+ */
+public class SelectionBarHandler extends AbstractHandler implements IElementUpdater {
+
+ public static final String COMMAND_ID =
"org.jboss.tools.jst.jsp.commands.showSelectionBar"; //$NON-NLS-1$
+
+ /**
+ * The constructor.
+ */
+ public SelectionBarHandler() {
+ }
+
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ boolean enabled = false;
+
+ if (evaluationContext instanceof IEvaluationContext) {
+ IEvaluationContext context = (IEvaluationContext) evaluationContext;
+ Object activeEditor = context.getVariable(ISources.ACTIVE_EDITOR_NAME);
+ if(activeEditor instanceof JSPMultiPageEditor){
+ JSPMultiPageEditor jspEditor = (JSPMultiPageEditor) activeEditor;
+ if(jspEditor.getSelectedPageIndex() != jspEditor.getPreviewIndex()){
+ enabled = true;
+ }
+ }
+ }
+
+ if (enabled != isEnabled()) {
+ setBaseEnabled(enabled);
+ }
+ }
+
+ /**
+ * the command has been executed, so extract extract the needed information
+ * from the application context.
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ HandlerUtil.toggleCommandState(event.getCommand());
+ return null;
+ }
+
+ public void updateElement(UIElement element, Map parameters) {
+ fireHandlerChanged(new HandlerEvent(this, true, false));
+ }
+
+}
Deleted:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/handlers/SelectionBarHandler.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/handlers/SelectionBarHandler.java 2011-07-21
03:00:08 UTC (rev 33095)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/handlers/SelectionBarHandler.java 2011-07-21
09:51:59 UTC (rev 33096)
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 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.jst.jsp.selection.bar.handlers;
-
-import java.util.Map;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.HandlerEvent;
-import org.eclipse.core.expressions.IEvaluationContext;
-import org.eclipse.ui.ISources;
-import org.eclipse.ui.commands.IElementUpdater;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.ui.menus.UIElement;
-import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
-
-/**
- * Selection bar handler
- */
-public class SelectionBarHandler extends AbstractHandler implements IElementUpdater{
-
- /**
- * The constructor.
- */
- public SelectionBarHandler() {
- }
-
- @Override
- public void setEnabled(Object evaluationContext) {
- boolean enabled = false;
-
- if (evaluationContext instanceof IEvaluationContext) {
- IEvaluationContext context = (IEvaluationContext) evaluationContext;
- Object activeEditor = context.getVariable(ISources.ACTIVE_EDITOR_NAME);
- if(activeEditor instanceof JSPMultiPageEditor){
- JSPMultiPageEditor jspEditor = (JSPMultiPageEditor) activeEditor;
- if(jspEditor.getSelectedPageIndex() != jspEditor.getPreviewIndex()){
- enabled = true;
- }
- }
- }
-
- if (enabled != isEnabled()) {
- setBaseEnabled(enabled);
- }
- }
-
- /**
- * the command has been executed, so extract extract the needed information
- * from the application context.
- */
- public Object execute(ExecutionEvent event) throws ExecutionException {
- HandlerUtil.toggleCommandState(event.getCommand());
- return null;
- }
-
- public void updateElement(UIElement element, Map parameters) {
- fireHandlerChanged(new HandlerEvent(this, true, false));
- }
-
-}