Author: dsakovich
Date: 2007-08-14 07:04:01 -0400 (Tue, 14 Aug 2007)
New Revision: 3113
Modified:
trunk/common/plugins/org.jboss.tools.common.model/resources/meta/studio_eclipse_option.meta
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/preferences/VpePreference.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
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/xpl/SashForm.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:
add functionality for
http://jira.jboss.com/jira/browse/JBIDE-600
Modified:
trunk/common/plugins/org.jboss.tools.common.model/resources/meta/studio_eclipse_option.meta
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/resources/meta/studio_eclipse_option.meta 2007-08-14
10:44:57 UTC (rev 3112)
+++
trunk/common/plugins/org.jboss.tools.common.model/resources/meta/studio_eclipse_option.meta 2007-08-14
11:04:01 UTC (rev 3113)
@@ -1490,6 +1490,20 @@
</Constraint>
<Editor name="CheckBox"/>
</XModelAttribute>
+ <XModelAttribute default="yes" name="show selection tag bar"
xmlname="show_selection_tag_bar">
+ <Constraint loader="List">
+ <value name="yes"/>
+ <value name="no"/>
+ </Constraint>
+ <Editor name="CheckBox"/>
+ </XModelAttribute>
+ <XModelAttribute default="no" name="always hide selection bar
without prompt" xmlname="always_hide_selection_bar_without_prompt">
+ <Constraint loader="List">
+ <value name="yes"/>
+ <value name="no"/>
+ </Constraint>
+ <Editor name="CheckBox"/>
+ </XModelAttribute>
<XModelAttribute default="Visual/Source" name="option list"
xmlname="option_list">
<Constraint loader="List">
<value name="Visual/Source"/>
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/preferences/VpePreference.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/preferences/VpePreference.java 2007-08-14
10:44:57 UTC (rev 3112)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/preferences/VpePreference.java 2007-08-14
11:04:01 UTC (rev 3113)
@@ -21,6 +21,8 @@
public static String ATT_USE_ABSOLUTE_POSITION = "";
public static String ATT_ALWAYS_PROMPT_FOR_TAG_ATTRIBUTES_DURING_TAG_INSERT =
"always prompt for tag attributes during tag insert";
public static String ATT_OPTION_LIST = "option list";
+ public static String ATT_SHOW_SELECTION_TAG_BAR = "show selection tag bar";
+ public static String ATT_ALWAYS_HIDE_SELECTION_BAR_WITHOUT_PROMT="always hide
selection bar without prompt";
public static String VPE_EDITOR_PATH = "%Options%/Struts Studio/Editors/Visual Page
Editor"; //$NON-NLS-1$
public static final Preference SHOW_COMMENTS = new VpePreference(VPE_EDITOR_PATH,
ATT_SHOW_COMMENTS);
@@ -31,7 +33,9 @@
public static final Preference USE_ABSOLUTE_POSITION = new
VpePreference(VPE_EDITOR_PATH, ATT_USE_ABSOLUTE_POSITION);
public static final Preference ALWAYS_REQUEST_FOR_ATTRIBUTE = new
VpePreference(VPE_EDITOR_PATH, ATT_ALWAYS_PROMPT_FOR_TAG_ATTRIBUTES_DURING_TAG_INSERT);
public static final Preference EDITOR_VIEW_OPTION = new VpePreference(VPE_EDITOR_PATH,
ATT_OPTION_LIST);
-
+ public static final Preference SHOW_SELECTION_TAG_BAR = new
VpePreference(VPE_EDITOR_PATH,ATT_SHOW_SELECTION_TAG_BAR);
+ public static final Preference ALWAYS_HIDE_SELECTION_BAR_WITHOUT_PROMT = new
VpePreference(VPE_EDITOR_PATH,ATT_ALWAYS_HIDE_SELECTION_BAR_WITHOUT_PROMT);
+
protected VpePreference(String optionPath, String attributeName) {
super(optionPath, attributeName);
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2007-08-14
10:44:57 UTC (rev 3112)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2007-08-14
11:04:01 UTC (rev 3113)
@@ -2407,7 +2407,7 @@
}
public void selectionChanged(SelectionChangedEvent event) {
- if (editPart.getVisualMode() != VpeEditorPart.SOURCE_MODE) {
+ if (editPart.getVisualMode() != VpeEditorPart.PREVIEW_MODE) {
if(toolbarFormatControllerManager != null)
toolbarFormatControllerManager.selectionChanged();
if(selectionBar != null) selectionBar.selectionChanged();
}
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 2007-08-14
10:44:57 UTC (rev 3112)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java 2007-08-14
11:04:01 UTC (rev 3113)
@@ -7,7 +7,7 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.vpe.editor;
import java.beans.PropertyChangeEvent;
@@ -26,6 +26,8 @@
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
@@ -47,517 +49,641 @@
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorExtension;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.event.XModelTreeEvent;
+import org.jboss.tools.common.model.event.XModelTreeListener;
+import org.jboss.tools.common.model.ui.util.ModelUtilities;
+import org.jboss.tools.common.model.util.XModelTreeListenerSWTSync;
import org.jboss.tools.jst.jsp.editor.IVisualEditor;
+import org.jboss.tools.jst.jsp.preferences.VpePreference;
import org.jboss.tools.vpe.VpePlugin;
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.xpl.SashForm;
+import org.jboss.tools.vpe.selbar.SelectionBar;
-public class VpeEditorPart extends EditorPart implements ITextEditor,
ITextEditorExtension, IReusableEditor, IVisualEditor {
- private SashForm container;
- private StructuredTextEditor sourceEditor=null;
- private MozillaEditor visualEditor;
- private IEditorPart activeEditor;
- private VpeController controller;
- private ActivationListener activationListener = new ActivationListener();
- private int visualMode=0;
- private EditorPart multiPageEditor;
- private static final QualifiedName SPLITTER_POSITION_KEY1 = new
QualifiedName("", "splitter_position1");
- private static final QualifiedName SPLITTER_POSITION_KEY2 = new
QualifiedName("", "splitter_position2");
- private static final QualifiedName SPLITTER_POSITION_KEY3 = new
QualifiedName("", "splitter_position3");
- private int controlCount = 0;
-
- /** default web-browser */
- private MozillaPreview previewWebBrowser = null;
-
- /** preview content */
- private Composite previewContent = null;
+public class VpeEditorPart extends EditorPart implements ITextEditor,
+ ITextEditorExtension, IReusableEditor, IVisualEditor {
+ private SashForm container;
+ private StructuredTextEditor sourceEditor = null;
+ private MozillaEditor visualEditor;
+ private IEditorPart activeEditor;
+ private VpeController controller;
+ private XModelTreeListener listener;
+ XModelObject optionsObject;
+ private SelectionBar selectionBar = new SelectionBar();
+ private ActivationListener activationListener = new ActivationListener();
+ private int visualMode = 0;
+ private EditorPart multiPageEditor;
+ private static final QualifiedName SPLITTER_POSITION_KEY1 = new QualifiedName(
+ "", "splitter_position1");
+ private static final QualifiedName SPLITTER_POSITION_KEY2 = new QualifiedName(
+ "", "splitter_position2");
+ private static final QualifiedName SPLITTER_POSITION_KEY3 = new QualifiedName(
+ "", "splitter_position3");
+ private int controlCount = 0;
- public StructuredTextEditor getSourceEditor(){
- return sourceEditor;
+ /** default web-browser */
+ private MozillaPreview previewWebBrowser = null;
+
+ /** preview content */
+ private Composite previewContent = null;
+
+ public StructuredTextEditor getSourceEditor() {
+ return sourceEditor;
+ }
+
+ // returns JSPMultipageEditor for closing by ctrl+F4 and ctrl+shift+F4 keys
+ public EditorPart getParentEditor() {
+ return multiPageEditor;
+ }
+
+ public void close(boolean save) {
+ if (sourceEditor != null)
+ sourceEditor.close(save);
+ }
+
+ public void doRevertToSaved() {
+ if (sourceEditor != null)
+ sourceEditor.doRevertToSaved();
+ }
+
+ public IDocumentProvider getDocumentProvider() {
+ if (sourceEditor != null)
+ return sourceEditor.getDocumentProvider();
+ else {
+ return null;
}
-
- // returns JSPMultipageEditor for closing by ctrl+F4 and ctrl+shift+F4 keys
- public EditorPart getParentEditor(){
- return multiPageEditor;
+ }
+
+ public IRegion getHighlightRange() {
+ if (sourceEditor != null)
+ return sourceEditor.getHighlightRange();
+ else {
+ return null;
}
-
- public void close(boolean save) {
- if(sourceEditor!=null)sourceEditor.close(save);
+ }
+
+ public ISelectionProvider getSelectionProvider() {
+ if (sourceEditor != null)
+ return sourceEditor.getSelectionProvider();
+ else {
+ return null;
}
- public void doRevertToSaved() {
- if(sourceEditor!=null)sourceEditor.doRevertToSaved();
+ }
+
+ public boolean isEditable() {
+ if (sourceEditor != null)
+ return sourceEditor.isEditable();
+ else {
+ return false;
}
- public IDocumentProvider getDocumentProvider() {
- if(sourceEditor!=null)return sourceEditor.getDocumentProvider();
- else{
- return null;
- }
+ }
+
+ public void removeActionActivationCode(String actionId) {
+ if (sourceEditor != null)
+ sourceEditor.removeActionActivationCode(actionId);
+ }
+
+ public void resetHighlightRange() {
+ if (sourceEditor != null)
+ sourceEditor.resetHighlightRange();
+ }
+
+ public void selectAndReveal(int offset, int length) {
+ if (sourceEditor != null)
+ sourceEditor.selectAndReveal(offset, length);
+ }
+
+ public void setAction(String actionID, IAction action) {
+ if (sourceEditor != null)
+ sourceEditor.setAction(actionID, action);
+ }
+
+ public void setActionActivationCode(String actionId,
+ char activationCharacter, int activationKeyCode,
+ int activationStateMask) {
+ if (sourceEditor != null)
+ sourceEditor.setActionActivationCode(actionId, activationCharacter,
+ activationKeyCode, activationStateMask);
+ }
+
+ public void setHighlightRange(int offset, int length, boolean moveCursor) {
+ if (sourceEditor != null)
+ sourceEditor.setHighlightRange(offset, length, moveCursor);
+ }
+
+ public void showHighlightRangeOnly(boolean showHighlightRangeOnly) {
+ if (sourceEditor != null)
+ sourceEditor.showHighlightRangeOnly(showHighlightRangeOnly);
+ }
+
+ public boolean showsHighlightRangeOnly() {
+ if (sourceEditor != null)
+ return sourceEditor.showsHighlightRangeOnly();
+ else {
+ return false;
}
- public IRegion getHighlightRange() {
- if(sourceEditor!=null)return sourceEditor.getHighlightRange();
- else{
- return null;
- }
+ }
+
+ public void addRulerContextMenuListener(IMenuListener listener) {
+ if (sourceEditor != null)
+ sourceEditor.addRulerContextMenuListener(listener);
+ }
+
+ public boolean isEditorInputReadOnly() {
+ if (sourceEditor != null)
+ return sourceEditor.isEditorInputReadOnly();
+ else {
+ return false;
}
- public ISelectionProvider getSelectionProvider() {
- if(sourceEditor!=null)return sourceEditor.getSelectionProvider();
- else{
- return null;
- }
+ }
+
+ public void removeRulerContextMenuListener(IMenuListener listener) {
+ if (sourceEditor != null)
+ sourceEditor.removeRulerContextMenuListener(listener);
+ }
+
+ public void setStatusField(IStatusField field, String category) {
+ if (visualMode == VISUAL_MODE) {
+ if (field != null) {
+ field.setImage(null);
+ field.setText(null);
+ }
+ } else if (sourceEditor != null)
+ sourceEditor.setStatusField(field, category);
+ }
+
+ public VpeEditorPart(EditorPart multiPageEditor,
+ StructuredTextEditor textEditor, boolean visualMode) {
+ sourceEditor = textEditor;
+ // this.visualMode = visualMode;
+ this.multiPageEditor = multiPageEditor;
+ }
+
+ public IAction getAction(String actionID) {
+ return sourceEditor.getAction(actionID);
+ }
+
+ public VpeEditorPart() {
+ }
+
+ public void doSave(IProgressMonitor monitor) {
+ if (sourceEditor != null) {
+ sourceEditor.doSave(monitor);
}
- public boolean isEditable() {
- if(sourceEditor!=null)return sourceEditor.isEditable();
- else{
- return false;
- }
+ }
+
+ public void doSaveAs() {
+ if (sourceEditor != null) {
+ sourceEditor.doSaveAs();
+ setInput(sourceEditor.getEditorInput());
}
- public void removeActionActivationCode(String actionId) {
- if(sourceEditor!=null)sourceEditor.removeActionActivationCode(actionId);
+ }
+
+ public void init(IEditorSite site, IEditorInput input)
+ throws PartInitException {
+ setSite(site);
+ setInput(input);
+ }
+
+ public void setInput(IEditorInput input) {
+ super.setInput(input);
+ if (visualEditor != null && visualEditor.getEditorInput() != null
+ && visualEditor.getEditorInput() != getEditorInput()) {
+ visualEditor.setInput(input);
}
- public void resetHighlightRange() {
- if(sourceEditor!=null)sourceEditor.resetHighlightRange();
+ }
+
+ public boolean isDirty() {
+ if (sourceEditor != null) {
+ return sourceEditor.isDirty();
+ } else {
+ return false;
}
- public void selectAndReveal(int offset, int length) {
- if(sourceEditor!=null)sourceEditor.selectAndReveal(offset, length);
+ }
+
+ public boolean isSaveAsAllowed() {
+ if (sourceEditor != null) {
+ return sourceEditor.isSaveAsAllowed();
+ } else {
+ return false;
}
- public void setAction(String actionID, IAction action) {
- if(sourceEditor!=null)sourceEditor.setAction(actionID, action);
+ }
+
+ protected int[] loadSplitterPosition() {
+ int[] sizes = new int[3];
+ try {
+ IEditorInput input = getEditorInput();
+ if (!(input instanceof IFileEditorInput))
+ return null;
+ IFile file = ((IFileEditorInput) input).getFile();
+ String s = file.getPersistentProperty(SPLITTER_POSITION_KEY1);
+ if (s != null) {
+ sizes[0] = Integer.parseInt(s);
+ } else
+ return null;
+ s = file.getPersistentProperty(SPLITTER_POSITION_KEY2);
+ if (s != null) {
+ sizes[1] = Integer.parseInt(s);
+ } else
+ return null;
+ s = file.getPersistentProperty(SPLITTER_POSITION_KEY3);
+ if (s != null) {
+ sizes[2] = Integer.parseInt(s);
+ } else
+ return null;
+ } catch (Exception e) {
+ VpePlugin.getPluginLog().logError(e);
+ return null;
}
- public void setActionActivationCode(String actionId,
- char activationCharacter, int activationKeyCode,
- int activationStateMask) {
- if(sourceEditor!=null)sourceEditor.setActionActivationCode(actionId,
activationCharacter, activationKeyCode, activationStateMask);
+ return sizes;
+ }
+
+ protected void saveSplitterPosition(int[] weights) {
+ IEditorInput input = getEditorInput();
+ if (!(input instanceof IFileEditorInput))
+ return;
+ IFile file = ((IFileEditorInput) input).getFile();
+ try {
+ String s = String.valueOf(weights[0]);
+ file.setPersistentProperty(SPLITTER_POSITION_KEY1, s);
+ s = String.valueOf(weights[1]);
+ file.setPersistentProperty(SPLITTER_POSITION_KEY2, s);
+ s = String.valueOf(weights[2]);
+ file.setPersistentProperty(SPLITTER_POSITION_KEY3, s);
+ } catch (Exception e) {
+ VpePlugin.getPluginLog().logError(e);
}
- public void setHighlightRange(int offset, int length, boolean moveCursor) {
- if(sourceEditor!=null)sourceEditor.setHighlightRange(offset, length, moveCursor);
- }
- public void showHighlightRangeOnly(boolean showHighlightRangeOnly) {
- if(sourceEditor!=null)sourceEditor.showHighlightRangeOnly(showHighlightRangeOnly);
- }
- public boolean showsHighlightRangeOnly() {
- if(sourceEditor!=null)return sourceEditor.showsHighlightRangeOnly();
- else{
- return false;
- }
- }
+ }
- public void addRulerContextMenuListener(IMenuListener listener) {
- if(sourceEditor!=null)sourceEditor.addRulerContextMenuListener(listener);
+ Composite sourceContent = null;
+ Composite visualContent = null;
+
+ public void setVisualMode(int type) {
+ String showSelectionBar = VpePreference.SHOW_SELECTION_TAG_BAR
+ .getValue();
+ switch (type) {
+ case VISUALSOURCE_MODE:
+ selectionBar.showBar(showSelectionBar);
+ if (sourceContent != null)
+ sourceContent.setVisible(true);
+ if (visualContent != null)
+ visualContent.setVisible(true);
+ if (previewContent != null) {
+ previewContent.setVisible(false);
+ }
+ break;
+
+ case VISUAL_MODE:
+ selectionBar.showBar(showSelectionBar);
+ if (sourceContent != null)
+ sourceContent.setVisible(false);
+ if (visualContent != null)
+ visualContent.setVisible(true);
+ if (previewContent != null) {
+ previewContent.setVisible(false);
+ }
+ break;
+
+ case SOURCE_MODE:
+ selectionBar.showBar(showSelectionBar);
+ if (sourceContent != null)
+ sourceContent.setVisible(true);
+ if (visualContent != null)
+ visualContent.setVisible(false);
+ if (previewContent != null) {
+ previewContent.setVisible(false);
+ }
+ break;
+
+ case PREVIEW_MODE:
+ if (selectionBar != null) {
+ selectionBar.showBar("no");
+ }
+ if (sourceContent != null) {
+ sourceContent.setVisible(false);
+ }
+
+ if (visualContent != null) {
+ visualContent.setVisible(false);
+ }
+
+ if (previewContent != null) {
+ previewWebBrowser.rebuildDom();
+ previewContent.setVisible(true);
+ }
+ break;
}
- public boolean isEditorInputReadOnly() {
- if(sourceEditor!=null)return sourceEditor.isEditorInputReadOnly();
- else{
- return false;
- }
+ container.layout();
+ if (visualMode == SOURCE_MODE && type != SOURCE_MODE) {
+ visualMode = type;
+ if (controller != null) {
+ controller.visualRefresh();
+ controller.sourceSelectionChanged();
+ }
}
- public void removeRulerContextMenuListener(IMenuListener listener) {
- if(sourceEditor!=null)sourceEditor.removeRulerContextMenuListener(listener);
- }
- public void setStatusField(IStatusField field, String category) {
- if(visualMode == VISUAL_MODE) {
- if(field != null) {
- field.setImage(null);
- field.setText(null);
- }
- }else
- if(sourceEditor!=null)sourceEditor.setStatusField(field, category);
- }
-
-
- public VpeEditorPart(EditorPart multiPageEditor, StructuredTextEditor textEditor,
boolean visualMode){
- sourceEditor = textEditor;
- //this.visualMode = visualMode;
- this.multiPageEditor = multiPageEditor;
- }
-
- public IAction getAction(String actionID){
- return sourceEditor.getAction(actionID);
- }
-
- public VpeEditorPart(){
- }
-
- public void doSave(IProgressMonitor monitor) {
- if (sourceEditor != null) {
- sourceEditor.doSave(monitor);
- }
- }
+ visualMode = type;
+ }
- public void doSaveAs() {
- if (sourceEditor != null) {
- sourceEditor.doSaveAs();
- setInput(sourceEditor.getEditorInput());
- }
- }
+ public int getVisualMode() {
+ return visualMode;
+ }
- public void init(IEditorSite site, IEditorInput input) throws PartInitException {
- setSite(site);
- setInput(input);
- }
+ public void createPartControl(Composite parent) {
+ controlCount++;
+ if (controlCount > 1)
+ return;
+ // //////////////////////////////////////////////////////////////
- public void setInput(IEditorInput input) {
- super.setInput(input);
- if(visualEditor != null && visualEditor.getEditorInput() != null &&
visualEditor.getEditorInput() != getEditorInput()) {
- visualEditor.setInput(input);
- }
- }
+ Composite cmpEdTl = new Composite(parent, SWT.NONE);
+ GridLayout layoutEdTl = new GridLayout(1, false);
+ layoutEdTl.verticalSpacing = 0;
+ layoutEdTl.marginHeight = 0;
+ layoutEdTl.marginBottom = 3;
+ layoutEdTl.marginWidth = 0;
+ cmpEdTl.setLayout(layoutEdTl);
+ cmpEdTl.setLayoutData(new GridData(GridData.FILL_BOTH));
- public boolean isDirty() {
- if (sourceEditor != null) {
- return sourceEditor.isDirty();
- } else {
- return false;
- }
- }
+ Composite cmpEd = new Composite(cmpEdTl, SWT.NATIVE);
+ GridLayout layoutEd = new GridLayout(1, false);
+ layoutEd.marginBottom = 0;
+ layoutEd.marginHeight = 1;
+ layoutEd.marginWidth = 0;
+ layoutEd.marginRight = 0;
+ layoutEd.marginLeft = 1;
+ layoutEd.verticalSpacing = 0;
+ layoutEd.horizontalSpacing = 0;
+ cmpEd.setLayout(layoutEd);
+ cmpEd.setLayoutData(new GridData(GridData.FILL_BOTH));
+ // /////////////////////////////////////////////////////////////////
+ container = new SashForm(cmpEd, SWT.VERTICAL);
+ container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ sourceContent = new Composite(container, SWT.NONE);
+ sourceContent.setLayout(new FillLayout());
+ visualContent = new Composite(container, SWT.NONE);
+ visualContent.setLayout(new FillLayout());
- public boolean isSaveAsAllowed() {
- if (sourceEditor != null) {
- return sourceEditor.isSaveAsAllowed();
- } else {
- return false;
+ // Create a preview content
+ previewContent = new Composite(container, SWT.NONE);
+ previewContent.setLayout(new FillLayout());
+
+ // ////////////////////////////////////////////////////
+
+ selectionBar.createToolBarComposite(cmpEdTl, true);
+ // ///////////////////////////////////////////////////
+ if (sourceEditor == null)
+ sourceEditor = new StructuredTextEditor() {
+ public void safelySanityCheckState(IEditorInput input) {
+ super.safelySanityCheckState(input);
}
- }
-
- protected int[] loadSplitterPosition() {
- int[] sizes = new int[3];
- try {
- IEditorInput input = getEditorInput();
- if(!(input instanceof IFileEditorInput)) return null;
- IFile file = ((IFileEditorInput)input).getFile();
- String s = file.getPersistentProperty(SPLITTER_POSITION_KEY1);
- if (s != null) {
- sizes[0] = Integer.parseInt(s);
- }else return null;
- s = file.getPersistentProperty(SPLITTER_POSITION_KEY2);
- if (s != null) {
- sizes[1] = Integer.parseInt(s);
- }else return null;
- s = file.getPersistentProperty(SPLITTER_POSITION_KEY3);
- if (s != null) {
- sizes[2] = Integer.parseInt(s);
- }else return null;
- } catch (Exception e) {
- VpePlugin.getPluginLog().logError(e);
- return null;
- }
- return sizes;
- }
+ };
+ int[] weights = loadSplitterPosition();
+ if (weights != null)
+ container.setWeights(weights);
+ container.addWeightsChangeListener(new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ saveSplitterPosition(container.getWeights());
+ }
+ });
+ parent.addControlListener(new ControlListener() {
+ public void controlMoved(ControlEvent event) {
- protected void saveSplitterPosition(int[] weights) {
- IEditorInput input = getEditorInput();
- if(!(input instanceof IFileEditorInput)) return;
- IFile file = ((IFileEditorInput)input).getFile();
- try {
- String s = String.valueOf(weights[0]);
- file.setPersistentProperty(SPLITTER_POSITION_KEY1, s);
- s = String.valueOf(weights[1]);
- file.setPersistentProperty(SPLITTER_POSITION_KEY2, s);
- s = String.valueOf(weights[2]);
- file.setPersistentProperty(SPLITTER_POSITION_KEY3, s);
- } catch (Exception e) {
- VpePlugin.getPluginLog().logError(e);
- }
- }
- Composite sourceContent=null;
- Composite visualContent=null;
-
- public void setVisualMode(int type){
- switch(type){
- case VISUALSOURCE_MODE:
- if(sourceContent!= null)sourceContent.setVisible(true);
- if(visualContent!= null)visualContent.setVisible(true);
- if(previewContent != null) {
- previewContent.setVisible(false);
- }
- break;
-
- case VISUAL_MODE:
- if(sourceContent!= null)sourceContent.setVisible(false);
- if(visualContent!= null)visualContent.setVisible(true);
- if(previewContent != null) {
- previewContent.setVisible(false);
- }
- break;
-
- case SOURCE_MODE:
- if(sourceContent!= null)sourceContent.setVisible(true);
- if(visualContent!= null)visualContent.setVisible(false);
- if(previewContent != null) {
- previewContent.setVisible(false);
- }
- break;
-
- case PREVIEW_MODE:
- if(sourceContent!= null) {
- sourceContent.setVisible(false);
- }
-
- if(visualContent!= null) {
- visualContent.setVisible(false);
- }
-
- if(previewContent != null) {
- previewWebBrowser.rebuildDom();
- previewContent.setVisible(true);
- }
- break;
- }
+ }
+
+ public void controlResized(ControlEvent event) {
container.layout();
- if(visualMode == SOURCE_MODE && type != SOURCE_MODE) {
- visualMode = type;
- if(controller!=null) {
- controller.visualRefresh();
- controller.sourceSelectionChanged();
- }
- }
- visualMode = type;
+ }
+ });
+ visualEditor = new MozillaEditor();
+ try {
+ visualEditor.init(getEditorSite(), getEditorInput());
+ } catch (Exception e) {
+ VpePlugin.reportProblem(e);
}
-
- public int getVisualMode(){
- return visualMode;
+
+ previewWebBrowser = new MozillaPreview(this, sourceEditor);
+ try {
+ previewWebBrowser.init(getEditorSite(), getEditorInput());
+ } catch (Exception e) {
+ VpePlugin.reportProblem(e);
}
- public void createPartControl(Composite parent) {
- controlCount++;
- if(controlCount > 1)return;
-
- container = new SashForm(parent, SWT.VERTICAL);
- sourceContent = new Composite(container, SWT.NONE);
- sourceContent.setLayout(new FillLayout());
- visualContent = new Composite(container, SWT.NONE);
- visualContent.setLayout(new FillLayout());
-
-
- // Create a preview content
- previewContent = new Composite(container, SWT.NONE);
- previewContent.setLayout(new FillLayout());
-
- if(sourceEditor == null)sourceEditor = new StructuredTextEditor() {
- public void safelySanityCheckState(IEditorInput input) {
- super.safelySanityCheckState(input);
+ try {
+ sourceEditor.addPropertyListener(new IPropertyListener() {
+ public void propertyChanged(Object source, int propId) {
+ if (propId == IWorkbenchPartConstants.PROP_TITLE) {
+ VpeEditorPart.this.setPartName(sourceEditor.getTitle());
+ }
+ VpeEditorPart.this.firePropertyChange(propId);
+ }
+ });
+ sourceEditor.init(getEditorSite(), getEditorInput());
+
+ if (sourceContent != null) {
+ sourceEditor.createPartControl(sourceContent);
+ }
+ if (visualEditor != null) {
+ visualEditor
+ .setEditorLoadWindowListener(new EditorLoadWindowListener() {
+ public void load() {
+ visualEditor.setEditorLoadWindowListener(null);
+ controller = new VpeController(
+ VpeEditorPart.this);
+ selectionBar.setVpeController(controller);
+ controller
+ .setSelectionBarController(selectionBar);
+ try {
+ controller.init(sourceEditor, visualEditor);
+ } catch (Exception e) {
+ VpePlugin.reportProblem(e);
}
- };
- int[] weights = loadSplitterPosition();
- if(weights != null)
- container.setWeights(weights);
- container.addWeightsChangeListener(new PropertyChangeListener(){
- public void propertyChange(PropertyChangeEvent event){
- saveSplitterPosition(container.getWeights());
- }
+ }
});
- parent.addControlListener(new ControlListener(){
- public void controlMoved(ControlEvent event){
-
- }
- public void controlResized(ControlEvent event){
- container.layout();
- }
- });
- visualEditor = new MozillaEditor();
- try {
- visualEditor.init(getEditorSite(), getEditorInput());
- } catch (Exception e) {
- VpePlugin.reportProblem(e);
- }
+ visualEditor.createPartControl(visualContent);
+ }
- previewWebBrowser = new MozillaPreview(this, sourceEditor);
- try {
- previewWebBrowser.init(getEditorSite(), getEditorInput());
- } catch (Exception e) {
- VpePlugin.reportProblem(e);
- }
+ if (previewWebBrowser != null) {
+ previewWebBrowser
+ .setEditorLoadWindowListener(new EditorLoadWindowListener() {
+ public void load() {
+ previewWebBrowser
+ .setEditorLoadWindowListener(null);
+ previewWebBrowser.buildDom();
+ }
+ });
+ previewWebBrowser.createPartControl(previewContent);
+ }
- try {
- sourceEditor.addPropertyListener(
- new IPropertyListener() {
- public void propertyChanged(Object source, int propId) {
- if (propId == IWorkbenchPartConstants.PROP_TITLE) {
- VpeEditorPart.this.setPartName(sourceEditor.getTitle());
- }
- VpeEditorPart.this.firePropertyChange(propId);
- }
- });
- sourceEditor.init(getEditorSite(), getEditorInput());
+ activeEditor = sourceEditor;
- if(sourceContent!=null){
- sourceEditor.createPartControl(sourceContent);
+ sourceContent.addListener(SWT.Activate, new Listener() {
+ public void handleEvent(Event event) {
+ if (event.type == SWT.Activate) {
+ if (activeEditor != sourceEditor) {
+ activeEditor = sourceEditor;
+ setFocus();
}
- if(visualEditor!=null) {
- visualEditor.setEditorLoadWindowListener(new EditorLoadWindowListener() {
- public void load() {
- visualEditor.setEditorLoadWindowListener(null);
- controller = new VpeController(VpeEditorPart.this);
- try {
- controller.init(sourceEditor, visualEditor);
- } catch (Exception e) {
- VpePlugin.reportProblem(e);
- }
- }
- });
- visualEditor.createPartControl(visualContent);
+ }
+ }
+ });
+
+ visualContent.addListener(SWT.Activate, new Listener() {
+ public void handleEvent(Event event) {
+ if (event.type == SWT.Activate) {
+ if (visualEditor != null
+ && activeEditor != visualEditor) {
+ activeEditor = visualEditor;
+ setFocus();
}
-
-
- if(previewWebBrowser!=null) {
- previewWebBrowser.setEditorLoadWindowListener(new EditorLoadWindowListener() {
- public void load() {
- previewWebBrowser.setEditorLoadWindowListener(null);
- previewWebBrowser.buildDom();
- }
- });
- previewWebBrowser.createPartControl(previewContent);
+ }
+ }
+ });
+
+ previewContent.addListener(SWT.Activate, new Listener() {
+ public void handleEvent(Event event) {
+ if (event.type == SWT.Activate) {
+ if (previewWebBrowser != null
+ && activeEditor != previewWebBrowser) {
+ activeEditor = previewWebBrowser;
+ setFocus();
}
-
- activeEditor = sourceEditor;
+ }
+ }
+ });
- sourceContent.addListener(SWT.Activate, new Listener() {
- public void handleEvent(Event event) {
- if (event.type == SWT.Activate) {
- if (activeEditor != sourceEditor) {
- activeEditor = sourceEditor;
- setFocus();
- }
- }
- }
- });
+ IWorkbenchWindow window = getSite().getWorkbenchWindow();
+ window.getPartService().addPartListener(activationListener);
+ window.getShell().addShellListener(activationListener);
- visualContent.addListener(SWT.Activate, new Listener() {
- public void handleEvent(Event event) {
- if (event.type == SWT.Activate) {
- if (visualEditor!=null && activeEditor != visualEditor) {
- activeEditor = visualEditor;
- setFocus();
- }
- }
- }
- });
+ } catch (Exception e) {
+ VpePlugin.reportProblem(e);
+ }
+ // setVisualMode(visualMode);
+ // ///////////////////////////////////////
+ // ///// Add preference listener
+ optionsObject = ModelUtilities.getPreferenceModel().getByPath(
+ VpePreference.EDITOR_PATH);
+ listener = new XModelTreeListener() {
-
- previewContent.addListener(SWT.Activate, new Listener() {
- public void handleEvent(Event event) {
- if (event.type == SWT.Activate) {
- if (previewWebBrowser!=null && activeEditor != previewWebBrowser) {
- activeEditor = previewWebBrowser;
- setFocus();
- }
- }
- }
- });
-
+ public void nodeChanged(XModelTreeEvent event) {
+ String showSelectionBar = VpePreference.SHOW_SELECTION_TAG_BAR
+ .getValue();
+ selectionBar.showBar(showSelectionBar);
+ }
- IWorkbenchWindow window = getSite().getWorkbenchWindow();
- window.getPartService().addPartListener(activationListener);
- window.getShell().addShellListener(activationListener);
+ public void structureChanged(XModelTreeEvent event) {
+ }
- } catch (Exception e) {
- VpePlugin.reportProblem(e);
- }
- //setVisualMode(visualMode);
+ };
+ optionsObject.getModel().addModelTreeListener(listener);
+ // ///////////////////////////////////////
+ cmpEd.layout();
+ }
+
+ public void setFocus() {
+ if (activeEditor != null) {
+ activeEditor.setFocus();
}
+ }
- public void setFocus() {
- if (activeEditor != null) {
- activeEditor.setFocus();
- }
+ public void dispose() {
+ super.dispose();
+ if (optionsObject != null) {
+ optionsObject.getModel().removeModelTreeListener(listener);
}
+ if (activationListener != null) {
+ IWorkbenchWindow window = getSite().getWorkbenchWindow();
+ window.getPartService().removePartListener(activationListener);
+ Shell shell = window.getShell();
+ if (shell != null && !shell.isDisposed())
+ shell.removeShellListener(activationListener);
+ activationListener = null;
+ }
+ if (controller != null) {
+ controller.dispose();
+ controller = null;
+ }
- public void dispose() {
- super.dispose();
+ // editor will disposed as part of multipart editor
+ if (sourceEditor != null) {
+ sourceEditor.dispose();
+ sourceEditor = null;
+ }
- if (activationListener != null) {
- IWorkbenchWindow window= getSite().getWorkbenchWindow();
- window.getPartService().removePartListener(activationListener);
- Shell shell= window.getShell();
- if (shell != null && !shell.isDisposed())
- shell.removeShellListener(activationListener);
- activationListener = null;
- }
- if (controller != null) {
- controller.dispose();
- controller = null;
- }
+ if (visualEditor != null) {
+ visualEditor.dispose();
+ visualEditor = null;
+ }
-
-// editor will disposed as part of multipart editor
- if (sourceEditor != null) {
- sourceEditor.dispose();
- sourceEditor = null;
- }
+ if (previewContent != null) {
+ previewContent.dispose();
+ previewContent = null;
+ }
+ }
- if (visualEditor != null) {
- visualEditor.dispose();
- visualEditor = null;
- }
-
- if (previewContent != null) {
- previewContent.dispose();
- previewContent = null;
- }
+ public Object getAdapter(Class adapter) {
+ if (sourceEditor != null) {
+ return sourceEditor.getAdapter(adapter);
+ } else {
+ return null;
}
+ }
- public Object getAdapter(Class adapter) {
- if (sourceEditor != null) {
- return sourceEditor.getAdapter(adapter);
- } else {
- return null;
+ private class ActivationListener extends ShellAdapter implements
+ IPartListener {
+ private IWorkbenchPart fActivePart;
+ private boolean fIsHandlingActivation = false;
+
+ public void partActivated(IWorkbenchPart part) {
+ fActivePart = part;
+ handleActivation();
+ }
+
+ public void partBroughtToTop(IWorkbenchPart part) {
+ }
+
+ public void partClosed(IWorkbenchPart part) {
+ }
+
+ public void partDeactivated(IWorkbenchPart part) {
+ fActivePart = null;
+ }
+
+ public void partOpened(IWorkbenchPart part) {
+ }
+
+ public void shellActivated(ShellEvent e) {
+ e.widget.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ handleActivation();
}
+ });
}
-
-
- private class ActivationListener extends ShellAdapter implements IPartListener {
- private IWorkbenchPart fActivePart;
- private boolean fIsHandlingActivation = false;
-
- public void partActivated(IWorkbenchPart part) {
- fActivePart = part;
- handleActivation();
- }
-
- public void partBroughtToTop(IWorkbenchPart part) {
- }
-
- public void partClosed(IWorkbenchPart part) {
- }
-
- public void partDeactivated(IWorkbenchPart part) {
- fActivePart = null;
- }
-
- public void partOpened(IWorkbenchPart part) {
- }
-
- public void shellActivated(ShellEvent e) {
- e.widget.getDisplay().asyncExec(new Runnable() {
- public void run() {
- handleActivation();
- }
- });
- }
-
- private void handleActivation() {
- if (fIsHandlingActivation)
- return;
-
- if (fActivePart == multiPageEditor) {
- fIsHandlingActivation = true;
- try {
- if (sourceEditor != null) {
- if (controller != null) {
- controller.refreshTemplates();
- }
- sourceEditor.safelySanityCheckState(getEditorInput());
- }
- } finally {
- fIsHandlingActivation = false;
- }
+
+ private void handleActivation() {
+ if (fIsHandlingActivation)
+ return;
+
+ if (fActivePart == multiPageEditor) {
+ fIsHandlingActivation = true;
+ try {
+ if (sourceEditor != null) {
+ if (controller != null) {
+ controller.refreshTemplates();
}
+ sourceEditor.safelySanityCheckState(getEditorInput());
+ }
+ } finally {
+ fIsHandlingActivation = false;
}
+ }
}
-
- public VpeController getController() {
- return controller;
- }
-
+ }
+
+ public VpeController getController() {
+ return controller;
+ }
+
}
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 2007-08-14
10:44:57 UTC (rev 3112)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2007-08-14
11:04:01 UTC (rev 3113)
@@ -85,8 +85,7 @@
private EditorDomEventListener editorDomEventListener;
private IVpeToolBarManager vpeToolBarManager;
private FormatControllerManager formatControllerManager = new
FormatControllerManager();
- private SelectionBar selectionBar = new SelectionBar();
-
+
public void doSave(IProgressMonitor monitor) {
}
@@ -117,10 +116,6 @@
this.controller = controller;
formatControllerManager.setVpeController(controller);
controller.setToolbarFormatControllerManager(formatControllerManager);
- //Add the Selection Bar to listen VPE
- selectionBar.setVpeController(controller);
-// editor.addControlListener(selectionBar);
- controller.setSelectionBarController(selectionBar);
}
Link link = null;
@@ -201,38 +196,6 @@
});
verBar.pack();
- //Bottom Button to show/hide the Selection Bar
- VpePlugin.getDefault().getPreferenceStore().setDefault(SELECT_BAR, "show");
//$NON-NLS-1$
- VpePlugin.getDefault().savePluginPreferences();
-
- ToolBar bt = new ToolBar(cmpVerticalToolbar, SWT.VERTICAL|SWT.FLAT|SWT.BOTTOM);
- ToolItem bbt = new ToolItem(bt, SWT.FLAT | SWT.CHECK);
- bbt.setToolTipText(VpeUIMessages.SHOW_HIDE_SELECTIONBAR);
- bbt.setImage(ImageDescriptor.createFromFile(MozillaEditor.class,
"icons/tag_line.gif").createImage()); //$NON-NLS-1$
- boolean bshow;
- if
(VpePlugin.getDefault().getPreferenceStore().getString(SELECT_BAR).equals("show")){
//$NON-NLS-1$
- bbt.setSelection(true);
- bshow = true;
- }
- else{
- bbt.setSelection(false);
- bshow = false;
- }
-
- bbt.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- String preferenceValue =
VpePlugin.getDefault().getPreferenceStore().getString(SELECT_BAR);
- selectionBar.showBar(preferenceValue);
- if (preferenceValue.equals("show")) { //$NON-NLS-1$
- VpePlugin.getDefault().getPreferenceStore().setValue(SELECT_BAR, "hide");
//$NON-NLS-1$
- }
- else {
- VpePlugin.getDefault().getPreferenceStore().setValue(SELECT_BAR, "show");
//$NON-NLS-1$
- }
- VpePlugin.getDefault().savePluginPreferences();
- }
- });
-
//Create a composite to the Editor
Composite cmpEd = new Composite (cmpEdTl, SWT.NATIVE);
GridLayout layoutEd = new GridLayout(1, false);
@@ -318,8 +281,7 @@
link.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label fill = new Label(cmpEd, SWT.WRAP);
fill.setLayoutData(new GridData(GridData.FILL_BOTH));
- }
- selectionBar.createToolBarComposite(cmpEdTl, bshow);
+ }
}
private ToolItem createToolItem(ToolBar parent, int type, String image, String
toolTipText) {
@@ -354,10 +316,6 @@
editor.dispose();
editor = null;
}
- if (selectionBar != null) {
- selectionBar.dispose();
- selectionBar = null;
- }
}
public void setEditorLoadWindowListener(EditorLoadWindowListener listener) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/xpl/SashForm.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/xpl/SashForm.java 2007-08-14
10:44:57 UTC (rev 3112)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/xpl/SashForm.java 2007-08-14
11:04:01 UTC (rev 3113)
@@ -73,36 +73,7 @@
int mask = SWT.BORDER;
return style & mask;
}
- public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- Control[] controls = getControls(true);
- if (controls.length == 0) return new Point(wHint, hHint);
-
- int width = 0;
- int height = 0;
- boolean vertical = (orientation == SWT.VERTICAL);
- if (vertical) {
- height += (controls.length - 1) * SASH_WIDTH;
- } else {
- width += (controls.length - 1) * SASH_WIDTH;
- }
- for (int i = 0; i < controls.length; i++) {
- if (vertical) {
- Point size = controls[i].computeSize(wHint, SWT.DEFAULT);
- height += size.y;
- width = Math.max(width, size.x);
- } else {
- Point size = controls[i].computeSize(SWT.DEFAULT, hHint);
- width += size.x;
- height = Math.max(height, size.y);
- }
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
-
- return new Point(width, height);
- }
-
+
public int getOrientation() {
return orientation;
}
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 2007-08-14
10:44:57 UTC (rev 3112)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2007-08-14
11:04:01 UTC (rev 3113)
@@ -43,7 +43,7 @@
public static String PREFERENCES;
public static String REFRESH;
public static String PAGE_DESIGN_OPTIONS;
- public static String SHOW_HIDE_SELECTIONBAR;
+ public static String HIDE_SELECTIONBAR;
public static String MOZILLA_LOADING_ERROR;
public static String MOZILLA_LOADING_ERROR_LINK_TEXT;
public static String MOZILLA_LOADING_ERROR_LINK;
@@ -89,7 +89,9 @@
public static String JUSTIFY;
public static String BULLETS;
public static String NUMBERING;
-
+ public static String CONFIRM_SELECTION_BAR_DIALOG_TITLE;
+ public static String CONFIRM_SELECTION_BAR_DIALOG_MESSAGE;
+ public static String CONFIRM_SELECTION_BAR_DIALOG_TOGGLE_MESSAGE;
}
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 2007-08-14
10:44:57 UTC (rev 3112)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2007-08-14
11:04:01 UTC (rev 3113)
@@ -3,7 +3,7 @@
PREFERENCES=Preferences
REFRESH=Refresh
PAGE_DESIGN_OPTIONS=Page Design Options
-SHOW_HIDE_SELECTIONBAR=Show/Hide Selection Bar
+HIDE_SELECTIONBAR=Hide 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.
@@ -49,3 +49,6 @@
JUSTIFY=Justify
BULLETS=Bullets
NUMBERING=Numbering
+CONFIRM_SELECTION_BAR_DIALOG_TITLE=Confirm hide selection bar
+CONFIRM_SELECTION_BAR_DIALOG_MESSAGE=Hide selection bar ?
+CONFIRM_SELECTION_BAR_DIALOG_TOGGLE_MESSAGE=Always hide selection bar without prompt
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 2007-08-14
10:44:57 UTC (rev 3112)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/SelectionBar.java 2007-08-14
11:04:01 UTC (rev 3113)
@@ -7,225 +7,294 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.vpe.selbar;
-import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.compare.Splitter;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
-import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Layout;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.xml.core.internal.document.ElementImpl;
-import org.w3c.dom.Node;
-
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.ui.util.ModelUtilities;
+import org.jboss.tools.jst.jsp.preferences.VpePreference;
import org.jboss.tools.vpe.VpePlugin;
import org.jboss.tools.vpe.editor.VpeController;
import org.jboss.tools.vpe.editor.selection.VpeSourceSelection;
import org.jboss.tools.vpe.editor.selection.VpeSourceSelectionBuilder;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
+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
+ * @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
*/
-
+
public class SelectionBar extends Layout implements SelectionListener {
- private Splitter splitter;
+ private Splitter splitter;
- private VpeController vpeController = null;
+ private VpeController vpeController = null;
- private ToolBar selBar = null;
+ private ToolBar selBar = null;
+ private ToolBar closeSelectionBar = null;
- private int itemCount = 0;
+ private int itemCount = 0;
- Composite cmpToolBar = null;
+ private Composite cmpToolBar = null;
+ private Composite cmpTlEmpty = null;
+ private Composite cmpBar = null;
+ private Composite closeBar = null;
- Composite cmpBar = null;
+ Listener selbarListener = null;
- Listener selbarListener = null;
+ final static String PREFERENCE_STATUS_BAR_ENABLE = "yes";
+ final static String PREFERENCE_STATUS_BAR_DISABLE = "no";
-
- public Composite createToolBarComposite(Composite parent, boolean show) {
+ public Composite createToolBarComposite(Composite parent, boolean show) {
- splitter = new Splitter(parent, SWT.NONE);
- splitter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ splitter = new Splitter(parent, SWT.NONE);
+ splitter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ /*
+ * The empty composite
+ */
+ cmpTlEmpty = new Composite(splitter, SWT.NONE) {
+ public Point computeSize(int wHint, int hHint, boolean changed) {
+ Point point = super.computeSize(wHint, hHint, changed);
+ point.y = 1;
+ return point;
+ }
+ };
- /*
- * The empty composite
- */
- Composite cmpTlEmpty = new Composite(splitter, SWT.NONE) {
- public Point computeSize(int wHint, int hHint, boolean changed) {
- Point point = super.computeSize(wHint, hHint, changed);
- point.y = 1;
- return point;
- }
- };
+ cmpTlEmpty.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- cmpTlEmpty.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ // Main composite of the visible splitter
+ cmpToolBar = new Composite(splitter, SWT.NONE);
+ cmpToolBar.setLayout(this);
- // Main composite of the visivle splitter
- cmpToolBar = new Composite(splitter, SWT.NONE);
- cmpToolBar.setLayout(this);
-
- GridLayout layoutTl = new GridLayout(1, false);
- layoutTl.marginBottom = 0;
- layoutTl.marginHeight = 0;
- layoutTl.marginWidth = 0;
- layoutTl.verticalSpacing = 0;
- layoutTl.horizontalSpacing = 0;
-
- // Midle composite, witch contain the selectbar
- cmpBar = new Composite(cmpToolBar, SWT.NONE);
- cmpBar.setLayout(layoutTl);
- cmpBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ GridLayout layoutTl = new GridLayout(1, false);
+ layoutTl.marginBottom = 0;
+ layoutTl.marginHeight = 0;
+ layoutTl.marginWidth = 0;
+ layoutTl.verticalSpacing = 0;
+ layoutTl.horizontalSpacing = 0;
- // Create selection bar
- selBar = new ToolBar(cmpBar, SWT.HORIZONTAL | SWT.FLAT);
- if (show == true) {
- splitter.setVisible(cmpTlEmpty, false);
- splitter.setVisible(cmpToolBar, true);
- }
- else {
- splitter.setVisible(cmpTlEmpty, true);
- splitter.setVisible(cmpToolBar, false);
- }
-
+ // Middle composite, witch contain the selectbar
+ cmpBar = new Composite(cmpToolBar, SWT.NONE);
+ cmpBar.setLayout(layoutTl);
+ cmpBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- return splitter;
- }
+ closeBar = new Composite(cmpToolBar, SWT.NONE);
+ closeBar.setLayout(layoutTl);
+ closeBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- public void showBar(String show) {
+ closeSelectionBar = new ToolBar(closeBar, SWT.HORIZONTAL | SWT.FLAT);
+ ToolItem closeItem = new ToolItem(closeSelectionBar, SWT.FLAT);
+ closeItem.setImage(PlatformUI.getWorkbench().getSharedImages()
+ .getImage(ISharedImages.IMG_TOOL_DELETE));
+ closeItem.setToolTipText(VpeUIMessages.HIDE_SELECTIONBAR);
+ closeItem.addListener(SWT.Selection, new Listener() {
- Control[] children = splitter.getChildren();
- if (children != null && children.length > 0) {
- if (show.equals("show")) {
- splitter.setVisible(children[0], true);
- splitter.setVisible(children[1], false);
- splitter.getParent().layout(true, true);
- } else {
- splitter.setVisible(children[0], false);
- splitter.setVisible(children[1], true);
- splitter.getParent().layout(true, true);
- }
+ 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) {
+ MessageDialogWithToggle dialog = MessageDialogWithToggle
+ .openOkCancelConfirm(
+ PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow()
+ .getShell(),
+ VpeUIMessages.CONFIRM_SELECTION_BAR_DIALOG_TITLE,
+ VpeUIMessages.CONFIRM_SELECTION_BAR_DIALOG_MESSAGE,
+ VpeUIMessages.CONFIRM_SELECTION_BAR_DIALOG_TOGGLE_MESSAGE,
+ false, null, null);
+ if (dialog.getReturnCode() != IDialogConstants.OK_ID) {
+ return;
+ }
+ if (dialog.getToggleState()) {
+ optionsObject
+ .setAttributeValue(
+ VpePreference.ATT_ALWAYS_HIDE_SELECTION_BAR_WITHOUT_PROMT,
+ PREFERENCE_STATUS_BAR_ENABLE);
+ }
}
+ optionsObject.setAttributeValue(
+ VpePreference.ATT_SHOW_SELECTION_TAG_BAR,
+ PREFERENCE_STATUS_BAR_DISABLE);
+ showBar(PREFERENCE_STATUS_BAR_DISABLE);
+ }
+ });
+ // Create selection bar
+ selBar = new ToolBar(cmpBar, SWT.HORIZONTAL | SWT.FLAT);
+ if (show == true) {
+ splitter.setVisible(cmpTlEmpty, false);
+ splitter.setVisible(cmpToolBar, true);
+ } else {
+ splitter.setVisible(cmpTlEmpty, true);
+ splitter.setVisible(cmpToolBar, false);
}
- public void setVpeController(VpeController vpeController) {
- this.vpeController = vpeController;
+ return splitter;
+ }
+
+ public void showBar(String show) {
+ if (show.equals(PREFERENCE_STATUS_BAR_ENABLE)) {
+ 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);
}
+ }
- public void selectionChanged() {
+ public void setVpeController(VpeController vpeController) {
+ this.vpeController = vpeController;
+ }
- VpeSourceSelectionBuilder sourceSelectionBuilder = new VpeSourceSelectionBuilder(
- vpeController.getSourceEditor());
- VpeSourceSelection selection = sourceSelectionBuilder.getSelection();
- if (selection == null) {
- return;
- }
+ public void selectionChanged() {
-// Node node = selection.getFocusNode();
- Node node = selection.getStartNode();
- if (node != null && node.getNodeType() == Node.TEXT_NODE) {
- node = node.getParentNode();
- }
+ VpeSourceSelectionBuilder sourceSelectionBuilder = new VpeSourceSelectionBuilder(
+ vpeController.getSourceEditor());
+ VpeSourceSelection selection = sourceSelectionBuilder.getSelection();
+ if (selection == null) {
+ return;
+ }
- int elementCounter = 0;
- while (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
- ToolItem item = null;
- if (selBar.getItemCount() > elementCounter) {
- item = selBar.getItem(selBar.getItemCount() - elementCounter - 1);
- item.setData(node);
- } else {
- item = new ToolItem(selBar, SWT.FLAT, 0);
- item.addSelectionListener(this);
- item.setData(node);
- }
- item.setText(node.getNodeName());
- elementCounter++;
- node = node.getParentNode();
- }
- itemCount = elementCounter;
- cmpToolBar.layout();
+ // Node node = selection.getFocusNode();
+ Node node = selection.getStartNode();
+ if (node != null && node.getNodeType() == Node.TEXT_NODE) {
+ node = node.getParentNode();
}
- protected Point computeSize(Composite composite, int wHint, int hHint,
- boolean flushCache) {
- return selBar.computeSize(SWT.DEFAULT, hHint);
+ int elementCounter = 0;
+ while (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
+ ToolItem item = null;
+ if (selBar.getItemCount() > elementCounter) {
+ item = selBar.getItem(selBar.getItemCount() - elementCounter
+ - 1);
+ item.setData(node);
+ } else {
+ item = new ToolItem(selBar, SWT.FLAT, 0);
+ item.addSelectionListener(this);
+ item.setData(node);
+ }
+ item.setText(node.getNodeName());
+ elementCounter++;
+ node = node.getParentNode();
}
+ itemCount = elementCounter;
+ cmpToolBar.layout();
+ }
- protected void layout(Composite composite, boolean flushCache) {
- Rectangle rect = null;
- try {
- rect = composite.getBounds();
- } catch (SWTException e) {
- VpePlugin.getPluginLog().logError(e);
- }
+ protected Point computeSize(Composite composite, int wHint, int hHint,
+ boolean flushCache) {
+ Point point = selBar.computeSize(SWT.DEFAULT, hHint);
+ point.y = closeBar.getSize().y;
+ return point;
+ }
- int allItems = selBar.getItems().length;
- if (allItems == 0)
- return;
+ protected void layout(Composite composite, boolean flushCache) {
+ Rectangle rect = null;
+ try {
+ rect = composite.getBounds();
+ } catch (SWTException e) {
+ VpePlugin.getPluginLog().logError(e);
+ }
- Rectangle r = selBar.getItem(allItems - 1).getBounds();
- int width = r.x + r.width;
- int height = r.height;
-
+ Rectangle closeBarRect = closeSelectionBar.getItem(0).getBounds();
+ rect.width -= closeBarRect.width;
- if (allItems >= itemCount) {
- int x = 0;
+ int allItems = selBar.getItems().length;
+ if (allItems == 0) {
+ cmpBar.setBounds(new Rectangle(rect.x, rect.y, rect.width,
+ closeBarRect.height));
+ closeBar.setBounds(new Rectangle(rect.width, rect.y, rect.width
+ + closeBarRect.width, closeBarRect.height));
+ return;
+ }
+ Rectangle r = selBar.getItem(allItems - 1).getBounds();
+ int width = r.x + r.width;
+ int height = r.height;
- if (itemCount == 0) {
- x = selBar.getBounds().width;
- } else {
- x = selBar.getItem(allItems - itemCount).getBounds().x;
- }
- rect.x -= x;
- }
+ if (allItems >= itemCount) {
+ int x = 0;
- if (rect.width < (r.x + r.width - Math.abs(rect.x) + 10)) {
- rect.x -= (r.x + r.width - Math.abs(rect.x)) - rect.width;
- }
- cmpBar.setBounds(new Rectangle(rect.x, 0, width, height));
- selBar.setSize(width, height);
+ if (itemCount == 0) {
+ x = selBar.getBounds().width;
+ } else {
+ x = selBar.getItem(allItems - itemCount).getBounds().x;
+ }
+ rect.x -= x;
+
+ if (rect.width < (r.x + r.width - Math.abs(rect.x) + 10)) {
+ rect.x -= (r.x + r.width - Math.abs(rect.x)) - rect.width;
+ }
+ cmpBar.setBounds(new Rectangle(rect.x, 0, width, height));
+ selBar.setSize(width, closeBarRect.height);
+ closeBar.setBounds(new Rectangle(rect.width, rect.y, rect.width
+ + closeBarRect.width, closeBarRect.height));
}
+ }
- public void dispose() {
- if (selBar != null && (!selBar.isDisposed())) {
- for (int i =0; i < selBar.getItemCount(); i++) {
- if (!selBar.getItem(i).isDisposed()) {
- selBar.getItem(i).removeSelectionListener(this);
- }
- }
+ public void dispose() {
+ if (!selBar.isDisposed()) {
+ for (int i = 0; i < selBar.getItemCount(); i++) {
+ if (!selBar.getItem(i).isDisposed()) {
+ selBar.getItem(i).removeSelectionListener(this);
}
+ }
}
-
- public void widgetSelected(SelectionEvent e) {
- ToolItem toolItem = (ToolItem) e.widget;
- int offset = ((ElementImpl)(Node)toolItem.getData()).getStartOffset();
- setSourceFocus(offset);
+ if (!closeSelectionBar.isDisposed()) {
+ for (int i = 0; i < closeSelectionBar.getItemCount(); i++) {
+ if (!closeSelectionBar.getItem(i).isDisposed()) {
+ closeSelectionBar.getItem(i).removeSelectionListener(this);
+ }
+ }
}
+ }
- public void widgetDefaultSelected(SelectionEvent e) {
- }
-
- private void setSourceFocus(int offset) {
- vpeController.getPageContext().getSourceBuilder().getStructuredTextViewer().setSelectedRange(offset,
0);
- vpeController.getPageContext().getSourceBuilder().getStructuredTextViewer().revealRange(offset,
0);
- }
-
- public String toString() {
- StringBuffer st = new StringBuffer("CountItem: ");
- st.append(itemCount);
- st.append(" Parent Composite: " + cmpToolBar.getBounds().width);
- st.append(" Midle composite: " + cmpBar.getBounds().width);
- st.append(" Bar : " + selBar.getBounds().width);
- return st.toString();
- }
-
+ public void widgetSelected(SelectionEvent e) {
+ ToolItem toolItem = (ToolItem) e.widget;
+ int offset = ((ElementImpl) (Node) toolItem.getData()).getStartOffset();
+ setSourceFocus(offset);
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ private void setSourceFocus(int offset) {
+ vpeController.getPageContext().getSourceBuilder()
+ .getStructuredTextViewer().setSelectedRange(offset, 0);
+ vpeController.getPageContext().getSourceBuilder()
+ .getStructuredTextViewer().revealRange(offset, 0);
+ }
+
+ public String toString() {
+ StringBuffer st = new StringBuffer("CountItem: ");
+ st.append(itemCount);
+ st.append(" Parent Composite: " + cmpToolBar.getBounds().width);
+ st.append(" Midle composite: " + cmpBar.getBounds().width);
+ st.append(" Bar : " + selBar.getBounds().width);
+ return st.toString();
+ }
}