Author: yradtsevich
Date: 2009-03-27 14:49:54 -0400 (Fri, 27 Mar 2009)
New Revision: 14360
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/VisibilityEvent.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/VisibilityListener.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeDropDownMenu.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/SelectionBar.java
Log:
RESOLVED - issue JBIDE-3895: Add Show selection bar button in VPE
https://jira.jboss.org/jira/browse/JBIDE-3895
- 'Show/Hide Selection Bar' option has been added to the VPE drop-down menu.
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java 2009-03-27
18:11:40 UTC (rev 14359)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java 2009-03-27
18:49:54 UTC (rev 14360)
@@ -31,6 +31,8 @@
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Point;
@@ -40,6 +42,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
@@ -80,10 +83,14 @@
import org.jboss.tools.vpe.editor.mozilla.EditorLoadWindowListener;
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
import org.jboss.tools.vpe.editor.mozilla.MozillaPreview;
+import org.jboss.tools.vpe.editor.util.Constants;
import org.jboss.tools.vpe.editor.xpl.CustomSashForm;
import org.jboss.tools.vpe.editor.xpl.EditorSettings;
import org.jboss.tools.vpe.editor.xpl.SashSetting;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
import org.jboss.tools.vpe.selbar.SelectionBar;
+import org.jboss.tools.vpe.selbar.VisibilityEvent;
+import org.jboss.tools.vpe.selbar.VisibilityListener;
public class VpeEditorPart extends EditorPart implements ITextEditor,
ITextEditorExtension, IReusableEditor, IVisualEditor {
@@ -358,11 +365,9 @@
Composite visualContent = null;
public void setVisualMode(int type) {
- String showSelectionBar = VpePreference.SHOW_SELECTION_TAG_BAR
- .getValue();
switch (type) {
case VISUALSOURCE_MODE:
- selectionBar.showBar(showSelectionBar);
+ selectionBar.setVisible(selectionBar.getAlwaysVisibleOption());
/*
* Fixes
https://jira.jboss.org/jira/browse/JBIDE-3140
* author Denis Maliarevich.
@@ -389,7 +394,7 @@
// break;
case SOURCE_MODE:
- selectionBar.showBar(showSelectionBar);
+ selectionBar.setVisible(selectionBar.getAlwaysVisibleOption());
if (sourceContent != null) {
sourceContent.setVisible(true);
/*
@@ -419,7 +424,7 @@
case PREVIEW_MODE:
if (selectionBar != null) {
- selectionBar.showBar("no");
+ selectionBar.setVisible(false);
}
/*
* Fixes
https://jira.jboss.org/jira/browse/JBIDE-3140
@@ -576,8 +581,7 @@
visualContent.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
- visualContent
- .removeControlListener(visualContentControlListener);
+ visualContent.removeControlListener(visualContentControlListener);
visualContent.removeDisposeListener(this);
}
@@ -671,9 +675,7 @@
listener = new XModelTreeListener() {
public void nodeChanged(XModelTreeEvent event) {
- String showSelectionBar = VpePreference.SHOW_SELECTION_TAG_BAR
- .getValue();
- selectionBar.showBar(showSelectionBar);
+ selectionBar.setVisible(selectionBar.getAlwaysVisibleOption());
}
public void structureChanged(XModelTreeEvent event) {
@@ -755,21 +757,52 @@
VpePlugin.reportProblem(e);
}
if (visualEditor != null) {
- visualEditor
- .setEditorLoadWindowListener(new EditorLoadWindowListener() {
+ visualEditor.setEditorLoadWindowListener(new EditorLoadWindowListener() {
public void load() {
visualEditor.setEditorLoadWindowListener(null);
visualEditor.setController(new VpeController(
VpeEditorPart.this));
selectionBar.setVpeController(visualEditor.getController());
visualEditor.getController().setSelectionBarController(selectionBar);
+ createShowSelectionBarMenuItem();
visualEditor.getController().init(sourceEditor, visualEditor);
}
+
});
visualEditor.createPartControl(visualContent);
}
}
+ /**
+ * Creates new MenuItem in VPE drop-down menu. This menu item provides
+ * option to show/hide selection bar.
+ */
+ private void createShowSelectionBarMenuItem() {
+ final MenuItem selectionBarVisibilityMenuItem =
+ new MenuItem(visualEditor.getDropDownMenu().getDropDownMenu(), SWT.PUSH);
+
+ selectionBarVisibilityMenuItem.setText(selectionBar.isVisible()
+ ? VpeUIMessages.HIDE_SELECTION_BAR
+ : VpeUIMessages.SHOW_SELECTION_BAR);
+
+ // add menu item listener
+ selectionBarVisibilityMenuItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ boolean selectionBarVisible = !selectionBar.isVisible();
+ selectionBar.setAlwaysVisibleOption(selectionBarVisible);
+ selectionBar.setVisible(selectionBarVisible);
+ }
+ });
+ // add selection bar listener
+ selectionBar.addVisibilityListener(new VisibilityListener() {
+ public void visibilityChanged(VisibilityEvent event) {
+ selectionBarVisibilityMenuItem.setText(event.getSource().isVisible()
+ ? VpeUIMessages.HIDE_SELECTION_BAR
+ : VpeUIMessages.SHOW_SELECTION_BAR);
+ }
+ });
+ }
+
public void createPreviewBrowser() {
previewWebBrowser = new MozillaPreview(this, sourceEditor);
try {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2009-03-27
18:11:40 UTC (rev 14359)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2009-03-27
18:49:54 UTC (rev 14360)
@@ -105,6 +105,7 @@
* for example enable or disable readOnlyMode
*/
private nsIEditor editor;
+ private VpeDropDownMenu dropDownMenu = null;
public void doSave(IProgressMonitor monitor) {
}
@@ -174,8 +175,7 @@
ToolBar verBar = new ToolBar(cmpVerticalToolbar, SWT.VERTICAL|SWT.FLAT);
verBar.setLayoutData(new GridData(GridData.FILL_VERTICAL));
- VpeDropDownMenu dropDownMenu = new VpeDropDownMenu(verBar,
- VpeUIMessages.MENU);
+ dropDownMenu = new VpeDropDownMenu(verBar, VpeUIMessages.MENU);
// Use vpeToolBarManager to create a horizontal toolbar.
vpeToolBarManager = new VpeToolBarManager(dropDownMenu
@@ -394,11 +394,9 @@
// add dispose listener
item.addDisposeListener(new DisposeListener() {
-
public void widgetDisposed(DisposeEvent e) {
// dispose tollitem's image
((ToolItem) e.widget).getImage().dispose();
-
}
});
return item;
@@ -418,6 +416,11 @@
vpeToolBarManager = null;
}
+ if (dropDownMenu != null) {
+ dropDownMenu.dispose();
+ dropDownMenu = null;
+ }
+
// removeDomEventListeners();
if(getController()!=null) {
controller.dispose();
@@ -786,4 +789,8 @@
}
return editor;
}
+
+ public VpeDropDownMenu getDropDownMenu() {
+ return dropDownMenu;
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeDropDownMenu.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeDropDownMenu.java 2009-03-27
18:11:40 UTC (rev 14359)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeDropDownMenu.java 2009-03-27
18:49:54 UTC (rev 14360)
@@ -64,5 +64,10 @@
return dropDownMenu;
}
-
+ public void dispose() {
+ if (dropDownMenu != null) {
+ dropDownMenu.dispose();
+ dropDownMenu = null;
+ }
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java 2009-03-27
18:11:40 UTC (rev 14359)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java 2009-03-27
18:49:54 UTC (rev 14360)
@@ -1,232 +1,227 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and 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
- ******************************************************************************/
-package org.jboss.tools.vpe.editor.toolbar;
-
-import org.eclipse.compare.Splitter;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Point;
-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.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-import org.jboss.tools.vpe.VpePlugin;
-import org.jboss.tools.vpe.editor.util.Constants;
-import org.jboss.tools.vpe.messages.VpeUIMessages;
-
-/**
- * @author Erick Created on 14.07.2005
- * @see IVpeToolBarManager
- */
-public class VpeToolBarManager implements IVpeToolBarManager {
-
- private Splitter splitter;
-
- private Menu dropDownMenu;
-
- public static final String SHOW = "show"; //$NON-NLS-1$
- public static final String HIDE = "hide"; //$NON-NLS-1$
-
- public VpeToolBarManager(Menu dropDownMenu) {
-
- this.dropDownMenu = dropDownMenu;
- }
-
- public Composite createToolBarComposite(Composite parent) {
- splitter = new Splitter(parent, SWT.NONE) {
-
- // if there is not visual children then return Point(0,0)
- public Point computeSize(int hint, int hint2, boolean changed) {
-
- int countVisibleChild = 0;
- for (Control child : getChildren()) {
- if (child.getVisible())
- countVisibleChild++;
- }
-
- if (countVisibleChild == 0)
- return new Point(0, 0);
- else
- return super.computeSize(hint, hint2, changed);
- }
- };
- return splitter;
-
- }
-
- public void addToolBar(IVpeToolBar bar) {
-
- Composite cmpToolBar = new Composite(splitter, SWT.NONE);
- GridLayout layoutTl = new GridLayout(2, false);
- layoutTl.marginBottom = 0;
- layoutTl.marginHeight = 2;
- layoutTl.marginWidth = 0;
- layoutTl.verticalSpacing = 0;
- layoutTl.horizontalSpacing = 0;
- cmpToolBar.setLayout(layoutTl);
- cmpToolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- // create toolbar control
- bar.createToolBarControl(cmpToolBar);
-
- // create tolbar container
- ToolbarContainer toolbarContainer = new ToolbarContainer(cmpToolBar,
- bar);
-
- // show or hide toolbar
- setStateToolbar(cmpToolBar, isShowedToolbar(bar));
-
- // create item to manage show/hide toolbar
- attachToMenu(dropDownMenu, toolbarContainer);
- }
-
- /**
- * create item to manage show/hide toolbar
- *
- * @param menu
- * @param toolbarContainer
- */
- public void attachToMenu(Menu menu, ToolbarContainer toolbarContainer) {
- MenuItem menuItem = new MenuItem(dropDownMenu, SWT.PUSH);
-
- boolean showToolbar = isShowedToolbar(toolbarContainer.getToolbar());
-
- // set text to menu item
- menuItem
- .setText((showToolbar ? VpeUIMessages.HIDE : VpeUIMessages.SHOW)
- + Constants.WHITE_SPACE
- + toolbarContainer.getToolbar().getName());
-
- // add listener
- menuItem.addSelectionListener(new ToolbarManagerSelectionListener(
- toolbarContainer, showToolbar));
-
- }
-
- /**
- *
- * @param bar
- * @return
- */
- protected boolean isShowedToolbar(IVpeToolBar bar) {
-
- return !HIDE.equalsIgnoreCase(getPreference(bar.getId()));
- }
-
- /**
- * show/hide toolbar
- *
- * @param toolBar
- * @param show
- */
- protected void setStateToolbar(Control toolBar, boolean show) {
- splitter.setVisible(toolBar, show);
- splitter.getParent().layout(true, true);
- }
-
- public void dispose() {
- if (splitter != null) {
- splitter.dispose();
- splitter = null;
- }
-
- for (MenuItem menuItem : dropDownMenu.getItems()) {
- menuItem.dispose();
- }
-
- }
-
- /**
- * get preference by key
- *
- * @param key
- * @return
- */
- private String getPreference(String key) {
-
- return VpePlugin.getDefault().getPreferenceStore().getString(key);
- }
-
- /**
- * set preference
- *
- * @param key
- * @param value
- */
- private void setPreference(String key, String value) {
-
- VpePlugin.getDefault().getPreferenceStore().setValue(key, value);
- }
-
- /**
- * selection listener to manage toolbars
- *
- * @author Sergey Dzmitrovich
- *
- */
- private class ToolbarManagerSelectionListener extends SelectionAdapter {
-
- private ToolbarContainer toolbarContainer;
- private boolean showBar;
-
- public ToolbarManagerSelectionListener(
- ToolbarContainer toolbarContainer, boolean showBar) {
- this.toolbarContainer = toolbarContainer;
- this.showBar = showBar;
- }
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- MenuItem selectedItem = (MenuItem) e.widget;
-
- // change flag
- showBar = !showBar;
-
- // set new value of preference
- setPreference(toolbarContainer.getToolbar().getId(), showBar ? SHOW
- : HIDE);
- // change text
- selectedItem.setText((showBar ? VpeUIMessages.HIDE
- : VpeUIMessages.SHOW)
- + Constants.WHITE_SPACE
- + toolbarContainer.getToolbar().getName());
- // show or hide toolbar
- setStateToolbar(toolbarContainer.getParent(), showBar);
- }
- }
-
- /*
- * This class describe the container for toolbars
- */
- private static class ToolbarContainer {
-
- private Composite parent;
- private IVpeToolBar toolbar;
-
- public ToolbarContainer(Composite parent, IVpeToolBar toolbar) {
- this.parent = parent;
- this.toolbar = toolbar;
- }
-
- public Composite getParent() {
- return parent;
- }
-
- public IVpeToolBar getToolbar() {
- return toolbar;
- }
-
- }
-
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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
+ ******************************************************************************/
+package org.jboss.tools.vpe.editor.toolbar;
+
+import org.eclipse.compare.Splitter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
+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.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.editor.util.Constants;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
+
+/**
+ * @author Erick Created on 14.07.2005
+ * @see IVpeToolBarManager
+ */
+public class VpeToolBarManager implements IVpeToolBarManager {
+
+ private Splitter splitter;
+
+ private Menu dropDownMenu;
+
+ public static final String SHOW = "show"; //$NON-NLS-1$
+ public static final String HIDE = "hide"; //$NON-NLS-1$
+
+ public VpeToolBarManager(Menu dropDownMenu) {
+
+ this.dropDownMenu = dropDownMenu;
+ }
+
+ public Composite createToolBarComposite(Composite parent) {
+ splitter = new Splitter(parent, SWT.NONE) {
+
+ // if there is not visual children then return Point(0,0)
+ public Point computeSize(int hint, int hint2, boolean changed) {
+
+ int countVisibleChild = 0;
+ for (Control child : getChildren()) {
+ if (child.getVisible())
+ countVisibleChild++;
+ }
+
+ if (countVisibleChild == 0)
+ return new Point(0, 0);
+ else
+ return super.computeSize(hint, hint2, changed);
+ }
+ };
+
+ return splitter;
+ }
+
+ public void addToolBar(IVpeToolBar bar) {
+
+ Composite cmpToolBar = new Composite(splitter, SWT.NONE);
+ GridLayout layoutTl = new GridLayout(2, false);
+ layoutTl.marginBottom = 0;
+ layoutTl.marginHeight = 2;
+ layoutTl.marginWidth = 0;
+ layoutTl.verticalSpacing = 0;
+ layoutTl.horizontalSpacing = 0;
+ cmpToolBar.setLayout(layoutTl);
+ cmpToolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ // create toolbar control
+ bar.createToolBarControl(cmpToolBar);
+
+ // create tolbar container
+ ToolbarContainer toolbarContainer = new ToolbarContainer(cmpToolBar, bar);
+
+ // show or hide toolbar
+ setStateToolbar(cmpToolBar, isShowedToolbar(bar));
+
+ // create item to manage show/hide toolbar
+ attachToMenu(dropDownMenu, toolbarContainer);
+ }
+
+ /**
+ * create item to manage show/hide toolbar
+ *
+ * @param menu
+ * @param toolbarContainer
+ */
+ public void attachToMenu(Menu menu, ToolbarContainer toolbarContainer) {
+ MenuItem menuItem = new MenuItem(dropDownMenu, SWT.PUSH);
+
+ boolean showToolbar = isShowedToolbar(toolbarContainer.getToolbar());
+
+ // set text to menu item
+ menuItem.setText( (showToolbar ? VpeUIMessages.HIDE : VpeUIMessages.SHOW)
+ + Constants.WHITE_SPACE
+ + toolbarContainer.getToolbar().getName() );
+
+ // add listener
+ menuItem.addSelectionListener(
+ new ToolbarManagerSelectionListener(toolbarContainer, showToolbar));
+ }
+
+ /**
+ *
+ * @param bar
+ * @return
+ */
+ protected boolean isShowedToolbar(IVpeToolBar bar) {
+ return !HIDE.equalsIgnoreCase(getPreference(bar.getId()));
+ }
+
+ /**
+ * show/hide toolbar
+ *
+ * @param toolBar
+ * @param show
+ */
+ protected void setStateToolbar(Control toolBar, boolean show) {
+ splitter.setVisible(toolBar, show);
+ splitter.getParent().layout(true, true);
+ }
+
+ public void dispose() {
+ if (splitter != null) {
+ splitter.dispose();
+ splitter = null;
+ }
+
+ for (MenuItem menuItem : dropDownMenu.getItems()) {
+ menuItem.dispose();
+ }
+
+ }
+
+ /**
+ * get preference by key
+ *
+ * @param key
+ * @return
+ */
+ private String getPreference(String key) {
+
+ return VpePlugin.getDefault().getPreferenceStore().getString(key);
+ }
+
+ /**
+ * set preference
+ *
+ * @param key
+ * @param value
+ */
+ private void setPreference(String key, String value) {
+
+ VpePlugin.getDefault().getPreferenceStore().setValue(key, value);
+ }
+
+ /**
+ * selection listener to manage toolbars
+ *
+ * @author Sergey Dzmitrovich
+ *
+ */
+ private class ToolbarManagerSelectionListener extends SelectionAdapter {
+
+ private ToolbarContainer toolbarContainer;
+ private boolean showBar;
+
+ public ToolbarManagerSelectionListener(
+ ToolbarContainer toolbarContainer, boolean showBar) {
+ this.toolbarContainer = toolbarContainer;
+ this.showBar = showBar;
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ MenuItem selectedItem = (MenuItem) e.widget;
+
+ // change flag
+ showBar = !showBar;
+
+ // set new value of preference
+ setPreference(toolbarContainer.getToolbar().getId(),
+ showBar ? SHOW : HIDE);
+ // change text
+ selectedItem.setText((showBar ? VpeUIMessages.HIDE
+ : VpeUIMessages.SHOW)
+ + Constants.WHITE_SPACE
+ + toolbarContainer.getToolbar().getName());
+ // show or hide toolbar
+ setStateToolbar(toolbarContainer.getParent(), showBar);
+ }
+ }
+
+ /*
+ * This class describe the container for toolbars
+ */
+ private static class ToolbarContainer {
+
+ private Composite parent;
+ private IVpeToolBar toolbar;
+
+ public ToolbarContainer(Composite parent, IVpeToolBar toolbar) {
+ this.parent = parent;
+ this.toolbar = toolbar;
+ }
+
+ public Composite getParent() {
+ return parent;
+ }
+
+ public IVpeToolBar getToolbar() {
+ return toolbar;
+ }
+
+ }
}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2009-03-27
18:11:40 UTC (rev 14359)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2009-03-27
18:49:54 UTC (rev 14360)
@@ -24,7 +24,8 @@
public static String PREFERENCES;
public static String REFRESH;
public static String PAGE_DESIGN_OPTIONS;
- public static String HIDE_SELECTIONBAR;
+ public static String HIDE_SELECTION_BAR;
+ public static String SHOW_SELECTION_BAR;
public static String MOZILLA_LOADING_ERROR;
public static String MOZILLA_LOADING_ERROR_LINK_TEXT;
public static String MOZILLA_LOADING_ERROR_LINK;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2009-03-27
18:11:40 UTC (rev 14359)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2009-03-27
18:49:54 UTC (rev 14360)
@@ -2,7 +2,8 @@
PREFERENCES=Preferences
REFRESH=Refresh
PAGE_DESIGN_OPTIONS=Page Design Options
-HIDE_SELECTIONBAR=Hide Selection Bar
+HIDE_SELECTION_BAR=Hide Selection Bar
+SHOW_SELECTION_BAR=Show Selection Bar
SHOW_BORDER_FOR_ALL_TAGS=show border for all tags
MOZILLA_LOADING_ERROR=The VPE editor can't be run because your system environment
needs to be changed slightly.
MOZILLA_LOADING_ERROR_LINK_TEXT=Find out more.
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/SelectionBar.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/SelectionBar.java 2009-03-27
18:11:40 UTC (rev 14359)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/SelectionBar.java 2009-03-27
18:49:54 UTC (rev 14360)
@@ -1,16 +1,17 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2009 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
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.vpe.selbar;
import java.util.ArrayList;
+import java.util.List;
import org.eclipse.compare.Splitter;
import org.eclipse.jface.dialogs.IDialogConstants;
@@ -46,9 +47,11 @@
import org.w3c.dom.Node;
/**
- * @author erick This class create and manage the Selection Bar under the VPE.
- * Entry point from the class MozilaEditor This bar can be hiden and
- * shown it uses splitter for this
+ * This class create and manage the Selection Bar under the VPE.
+ * Entry point from the class MozilaEditor This bar can be hiden and
+ * shown it uses splitter for this.
+ *
+ * @author erick
*/
public class SelectionBar extends Layout implements SelectionListener {
@@ -66,12 +69,19 @@
private Composite cmpBar = null;
private Composite closeBar = null;
+ private List<VisibilityListener> visibilityListeners = new
ArrayList<VisibilityListener>(1);
+
+ /**
+ * Visibility state of the {@code SelectionBar}.
+ */
+ private boolean visible;
+
//Listener selbarListener = null;
- final static String PREFERENCE_STATUS_BAR_ENABLE = "yes"; //$NON-NLS-1$
- final static String PREFERENCE_STATUS_BAR_DISABLE = "no"; //$NON-NLS-1$
+ final static String PREFERENCE_YES = "yes"; //$NON-NLS-1$
+ final static String PREFERENCE_NO = "no"; //$NON-NLS-1$
- public Composite createToolBarComposite(Composite parent, boolean show) {
+ public Composite createToolBarComposite(Composite parent, boolean visible) {
splitter = new Splitter(parent, SWT.NONE);
splitter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
/*
@@ -102,7 +112,6 @@
cmpBar = new Composite(cmpToolBar, SWT.NONE);
cmpBar.setLayout(layoutTl);
cmpBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
closeBar = new Composite(cmpToolBar, SWT.NONE);
closeBar.setLayout(layoutTl);
closeBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
@@ -111,16 +120,10 @@
ToolItem closeItem = new ToolItem(closeSelectionBar, SWT.FLAT);
closeItem.setImage(PlatformUI.getWorkbench().getSharedImages()
.getImage(ISharedImages.IMG_TOOL_DELETE));
- closeItem.setToolTipText(VpeUIMessages.HIDE_SELECTIONBAR);
+ closeItem.setToolTipText(VpeUIMessages.HIDE_SELECTION_BAR);
closeItem.addListener(SWT.Selection, new Listener() {
-
public void handleEvent(Event event) {
- boolean toggleState = VpePreference.ALWAYS_HIDE_SELECTION_BAR_WITHOUT_PROMT
- .getValue().equals(PREFERENCE_STATUS_BAR_ENABLE);
- XModelObject optionsObject = ModelUtilities
- .getPreferenceModel().getByPath(
- VpePreference.VPE_EDITOR_PATH);
- if (!toggleState) {
+ if (!getHideWithoutPromptOption()) {
MessageDialogWithToggle dialog = MessageDialogWithToggle
.openOkCancelConfirm(
PlatformUI.getWorkbench()
@@ -134,53 +137,138 @@
return;
}
if (dialog.getToggleState()) {
- optionsObject
- .setAttributeValue(
- VpePreference.ATT_ALWAYS_HIDE_SELECTION_BAR_WITHOUT_PROMT,
- PREFERENCE_STATUS_BAR_ENABLE);
+ setHideWithoutPromptOption(true);
}
}
- optionsObject.setAttributeValue(
- VpePreference.ATT_SHOW_SELECTION_TAG_BAR,
- PREFERENCE_STATUS_BAR_DISABLE);
-
- /*
- * Fixes
http://jira.jboss.com/jira/browse/JBIDE-2298
- * To get stored in xml XModelObject
- * should be marked as modified.
- */
- optionsObject.setModified(true);
- performStore(optionsObject);
-
- showBar(PREFERENCE_STATUS_BAR_DISABLE);
+
+ setAlwaysVisibleOption(false);
+ setVisible(false);
}
+
});
// Create selection bar
selBar = new ToolBar(cmpBar, SWT.HORIZONTAL | SWT.FLAT);
- if (show == true) {
- splitter.setVisible(cmpTlEmpty, false);
- splitter.setVisible(cmpToolBar, true);
+ setVisible(visible);
+
+ return splitter;
+ }
+
+ private void setPersistentOption(String name, String value) {
+ XModelObject optionsObject = getOptionsObject();
+ optionsObject.setAttributeValue(name, value);
+
+ /*
+ * Fixes
http://jira.jboss.com/jira/browse/JBIDE-2298
+ * To get stored in xml XModelObject
+ * should be marked as modified.
+ */
+ optionsObject.setModified(true);
+ performStore(optionsObject);
+ }
+
+ private XModelObject getOptionsObject() {
+ XModelObject optionsObject = ModelUtilities.getPreferenceModel()
+ .getByPath(VpePreference.VPE_EDITOR_PATH);
+ return optionsObject;
+ }
+
+ public void setAlwaysVisibleOption(boolean visible) {
+ final String optionValue;
+ if (visible) {
+ optionValue = PREFERENCE_YES;
} else {
- splitter.setVisible(cmpTlEmpty, true);
- splitter.setVisible(cmpToolBar, false);
+ optionValue = PREFERENCE_NO;
}
- return splitter;
+ setPersistentOption(VpePreference.ATT_SHOW_SELECTION_TAG_BAR, optionValue);
}
- public void showBar(String show) {
- if (PREFERENCE_STATUS_BAR_ENABLE.equals(show)) {
+ public boolean getAlwaysVisibleOption() {
+ return VpePreference.SHOW_SELECTION_TAG_BAR.getValue().equals(PREFERENCE_YES);
+ }
+
+ public void setHideWithoutPromptOption(boolean hideWithoutPrompt) {
+ final String optionValue;
+ if (hideWithoutPrompt) {
+ optionValue = PREFERENCE_YES;
+ } else {
+ optionValue = PREFERENCE_NO;
+ }
+
+ setPersistentOption(VpePreference.ATT_ALWAYS_HIDE_SELECTION_BAR_WITHOUT_PROMT,
+ optionValue);
+ }
+
+ public boolean getHideWithoutPromptOption() {
+ return VpePreference.ALWAYS_HIDE_SELECTION_BAR_WITHOUT_PROMT
+ .getValue().equals(PREFERENCE_YES);
+ }
+
+ /**
+ * Sets {@code visible} state to this {@code SelectionBar} and fires
+ * all registered {@code VisibilityListener}s.
+ */
+ public void setVisible(boolean visible) {
+ if (visible) {
splitter.setVisible(cmpToolBar, true);
splitter.setVisible(cmpTlEmpty, false);
- splitter.getParent().layout(true, true);
} else {
splitter.setVisible(cmpToolBar, false);
splitter.setVisible(cmpTlEmpty, true);
- splitter.getParent().layout(true, true);
}
+ splitter.getParent().layout(true, true);
+
+ this.visible = visible;
+ fireVisibilityListeners();
}
- public void setVpeController(VpeController vpeController) {
+ /**
+ * Returns {@code visible} state of this {@code SelectionBar}.
+ */
+ public boolean isVisible() {
+ return visible;
+ }
+
+ /**
+ * Adds the listener to the collection of listeners who will
+ * be notified when the {@code #visible} state is changed.
+ *
+ * @param listener the listener which should be notified
+ *
+ * @see VisibilityListener
+ * @see VisibilityEvent
+ */
+ public void addVisibilityListener(VisibilityListener listener) {
+ visibilityListeners.add(listener);
+ }
+
+ /**
+ * Removes the listener from the collection of listeners who will
+ * be notified when the {@link #visible} state is changed.
+ *
+ * @param listener the listener which should be removed
+ *
+ * @see VisibilityListener
+ */
+ public void removeVisibilityListener(VisibilityListener listener) {
+ visibilityListeners.remove(listener);
+ }
+
+ /**
+ * Fires all registered instances of {@code VisibilityListener} by
+ * sending them {@link VisibilityEvent}.
+ *
+ * @see #addVisibilityListener(VisibilityListener)
+ * @see #removeVisibilityListener(VisibilityListener)
+ */
+ private void fireVisibilityListeners() {
+ VisibilityEvent event = new VisibilityEvent(this);
+ for (VisibilityListener listener : visibilityListeners) {
+ listener.visibilityChanged(event);
+ }
+ }
+
+ public void setVpeController(VpeController vpeController) {
this.vpeController = vpeController;
}
@@ -341,7 +429,6 @@
*/
xmo.getModel().saveOptions();
}
-
public String toString() {
StringBuffer st = new StringBuffer("CountItem: ");
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/VisibilityEvent.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/VisibilityEvent.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/VisibilityEvent.java 2009-03-27
18:49:54 UTC (rev 14360)
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.selbar;
+
+import java.util.EventObject;
+
+/**
+ * Instances of this class are sent as a result of a visibility state
+ * of widgets is changed.
+ *
+ * @see VisibilityListener
+ *
+ * @author yradtsevich
+ */
+public class VisibilityEvent extends EventObject {
+ private static final long serialVersionUID = 1L;
+
+ public VisibilityEvent(SelectionBar source) {
+ super(source);
+ }
+
+ @Override
+ public SelectionBar getSource() {
+ return (SelectionBar) super.getSource();
+ }
+}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/VisibilityListener.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/VisibilityListener.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/VisibilityListener.java 2009-03-27
18:49:54 UTC (rev 14360)
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.selbar;
+
+import java.util.EventListener;
+
+/**
+ * Classes which implement this interface provide method
+ * that deal with the events that are generated when visibility
+ * of a widget is changed.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a control using the
+ * {@code addVisibilityListener} method and removed using
+ * the {@code removeVisibilityListener} method. When
+ * visibility state is changed in a control the appropriate method
+ * will be invoked.
+ * </p>
+ *
+ * @see VisibilityEvent
+ *
+ * @author yradtsevich
+ */
+public interface VisibilityListener extends EventListener {
+ /**
+ * Sent when the visibility state of the widget is changed.
+ *
+ * @param event an event containing information about the operation
+ */
+ public void visibilityChanged(VisibilityEvent event);
+}