Author: mareshkau
Date: 2008-02-07 04:57:05 -0500 (Thu, 07 Feb 2008)
New Revision: 6143
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/editor/IVisualController.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/editor/IVisualEditor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageContributor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorPart.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorSite.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditorPageContext.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1105
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/editor/IVisualController.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/editor/IVisualController.java 2008-02-07
06:15:54 UTC (rev 6142)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/editor/IVisualController.java 2008-02-07
09:57:05 UTC (rev 6143)
@@ -1,27 +1,28 @@
-/*******************************************************************************
- * 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.jst.jsp.editor;
-
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.w3c.dom.Node;
-
-
-public interface IVisualController {
- public IStructuredModel getModel();
- public void drop(Node node, Node parentNode, int offset);
- public IVisualContext getPageContext();
- public void postLongOperation();
- public void preLongOperation();
- public void selectionChanged(SelectionChangedEvent event);
- public void refreshExternalLinks();
- public void visualRefresh();
-}
+/*******************************************************************************
+ * 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.jst.jsp.editor;
+
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.w3c.dom.Node;
+
+
+public interface IVisualController extends SelectionListener {
+ public IStructuredModel getModel();
+ public void drop(Node node, Node parentNode, int offset);
+ public IVisualContext getPageContext();
+ public void postLongOperation();
+ public void preLongOperation();
+ public void selectionChanged(SelectionChangedEvent event);
+ public void refreshExternalLinks();
+ public void visualRefresh();
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/editor/IVisualEditor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/editor/IVisualEditor.java 2008-02-07
06:15:54 UTC (rev 6142)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/editor/IVisualEditor.java 2008-02-07
09:57:05 UTC (rev 6143)
@@ -1,27 +1,31 @@
-/*******************************************************************************
- * 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.jst.jsp.editor;
-
-import org.eclipse.ui.IReusableEditor;
-import org.eclipse.ui.texteditor.ITextEditor;
-
-public interface IVisualEditor extends ITextEditor, IReusableEditor {
- public static final int VISUALSOURCE_MODE = 0;
- public static final int VISUAL_MODE = 1;
- public static final int SOURCE_MODE = 2;
-
- /** PREVIEW_MODE */
- public static final int PREVIEW_MODE = 3;
-
- public void setVisualMode(int mode);
- public IVisualController getController();
-
-}
+/*******************************************************************************
+ * 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.jst.jsp.editor;
+
+import org.eclipse.ui.IReusableEditor;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+public interface IVisualEditor extends ITextEditor, IReusableEditor {
+ public static final int VISUALSOURCE_MODE = 0;
+ public static final int VISUAL_MODE = 1;
+ public static final int SOURCE_MODE = 2;
+
+ /** PREVIEW_MODE */
+ public static final int PREVIEW_MODE = 3;
+
+ public void setVisualMode(int mode);
+ public IVisualController getController();
+ public Object getPreviewWebBrowser();
+ public void createPreviewBrowser();
+ public Object getVisualEditor();
+ public void createVisualEditor();
+
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageContributor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageContributor.java 2008-02-07
06:15:54 UTC (rev 6142)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageContributor.java 2008-02-07
09:57:05 UTC (rev 6143)
@@ -1,216 +1,231 @@
-/*******************************************************************************
- * 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.jst.jsp.jspeditor;
-
-import java.util.ResourceBundle;
-
-import org.jboss.tools.common.model.ui.texteditors.AbstractMultiPageContributor;
-import org.eclipse.jem.internal.java.adapters.nls.ResourceHandler;
-import org.eclipse.jface.action.IStatusLineManager;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.actions.ActionFactory;
-import org.eclipse.ui.handlers.IHandlerService;
-import org.eclipse.ui.ide.IDEActionFactory;
-import org.eclipse.ui.texteditor.IStatusField;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.ui.texteditor.ITextEditorActionConstants;
-import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
-import org.eclipse.ui.texteditor.ITextEditorExtension;
-import org.eclipse.ui.texteditor.RetargetTextEditorAction;
-import org.eclipse.wst.sse.ui.internal.actions.ActionDefinitionIds;
-import org.eclipse.wst.sse.ui.internal.actions.StructuredTextEditorActionConstants;
-
-import org.jboss.tools.common.text.xml.xpl.ToggleOccurencesMarkUpAction;
-
-/**
- * @author Jeremy
- *
- */
-public class JSPMultiPageContributor extends AbstractMultiPageContributor {
- protected RetargetTextEditorAction fShowTooltipAction = null; // show
-
- protected RetargetTextEditorAction fContentAssist = null;
-
- public JSPMultiPageContributor() {
- fToggleOccurencesMarkUp = new ToggleOccurencesMarkUpAction();
- }
-
- public void init(IActionBars bars) {
- super.init(bars);
- initEditMenu(bars);
- ResourceBundle resourceBundle = ResourceHandler.getResourceBundle();
-
- fShowTooltipAction = new RetargetTextEditorAction(resourceBundle,
- StructuredTextEditorActionConstants.ACTION_NAME_INFORMATION
- + StructuredTextEditorActionConstants.DOT);
- fShowTooltipAction
- .setActionDefinitionId(ActionDefinitionIds.INFORMATION);
-
- fContentAssist = new RetargetTextEditorAction(
- resourceBundle,
- StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS
- + StructuredTextEditorActionConstants.DOT);
- fContentAssist
- .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
-
- //TODO-3.3: keep checking if 'quick fix' action appears in WTP
-// fQuickFix = new RetargetTextEditorAction(resourceBundle,
-// StructuredTextEditorActionConstants.ACTION_NAME_QUICK_FIX
-// + StructuredTextEditorActionConstants.DOT);
-// fQuickFix.setActionDefinitionId(ActionDefinitionIds.QUICK_FIX);
- }
-
- protected void createAssistObjects() {
- ResourceBundle resourceBundle = ResourceHandler.getResourceBundle();
-
- fContentAssistProposal = new RetargetTextEditorAction(
- resourceBundle,
- StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS
- + StructuredTextEditorActionConstants.DOT);
- fContentAssistProposal
- .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
-
- fContentAssistTip = new RetargetTextEditorAction(resourceBundle,
- StructuredTextEditorActionConstants.ACTION_NAME_INFORMATION
- + StructuredTextEditorActionConstants.DOT);
- fContentAssistTip
- .setActionDefinitionId(ActionDefinitionIds.INFORMATION);
- }
-
- public void setActiveEditor(IEditorPart part) {
- IEditorPart activeNestedEditor = null;
- if (part instanceof JSPMultiPageEditor) {
- activeNestedEditor = ((JSPMultiPageEditor) part).getActiveEditor();
- }
- setActivePage(activeNestedEditor);
-
- mainPart = part;
-
- IActionBars actionBars = getActionBars();
-
- if (actionBars != null) {
- IStatusLineManager slm = actionBars.getStatusLineManager();
- if (slm != null) {
- slm.setErrorMessage(null);
- slm.setMessage(null);
- }
- }
- }
-
- public void setActivePage(IEditorPart part) {
- if (fActiveEditorPart == part)
- return;
- cleanStatusLine();
- fActiveEditorPart = part;
- IActionBars actionBars = getActionBars();
- if (actionBars != null) {
-
- ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part
- : null;
- if (editor != null) {
-
- actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
- getAction(editor, ITextEditorActionConstants.DELETE));
- actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
- getAction(editor, ITextEditorActionConstants.UNDO));
- actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
- getAction(editor, ITextEditorActionConstants.REDO));
- actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(),
- getAction(editor, ITextEditorActionConstants.CUT));
- actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),
- getAction(editor, ITextEditorActionConstants.COPY));
- actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(),
- getAction(editor, ITextEditorActionConstants.PASTE));
- actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL
- .getId(), getAction(editor,
- ITextEditorActionConstants.SELECT_ALL));
- actionBars.setGlobalActionHandler(ActionFactory.FIND.getId(),
- getAction(editor, ITextEditorActionConstants.FIND));
- actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK
- .getId(), getAction(editor, IDEActionFactory.BOOKMARK
- .getId()));
- actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK
- .getId(), getAction(editor, IDEActionFactory.ADD_TASK
- .getId()));
- actionBars.setGlobalActionHandler(ActionFactory.PRINT.getId(),
- getAction(editor, ITextEditorActionConstants.PRINT));
- actionBars.setGlobalActionHandler(ActionFactory.REVERT.getId(),
- getAction(editor, ITextEditorActionConstants.REVERT));
- actionBars.setGlobalActionHandler(ActionFactory.SAVE.getId(),
- getAction(editor, ITextEditorActionConstants.SAVE));
-
- fShowTooltipAction
- .setAction(getAction(
- editor,
- StructuredTextEditorActionConstants.ACTION_NAME_INFORMATION));
- fContentAssist
- .setAction(getAction(
- editor,
- StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS));
- //TODO-3.3: keep checking if 'quick fix' action appears in WTP
- // fQuickFix
- // .setAction(getAction(
- // editor,
- // StructuredTextEditorActionConstants.ACTION_NAME_QUICK_FIX));
-
-
- }
-
- // re-register action on key binding service
- IEditorPart localPart = (part != null) ? part : mainPart;
- if (localPart != null) {
- IHandlerService handler = (IHandlerService) localPart
- .getEditorSite().getService(IHandlerService.class);
- if (handler == null && mainPart != null) {
- handler = (IHandlerService) mainPart.getEditorSite()
- .getService(IHandlerService.class);
- }
- if (editor != null && handler != null) {
- // editor
- registerKeyBindings(handler, ACTIONS_2, editor);
- String[] ACTIONS_3 = {
- StructuredTextEditorActionConstants.ACTION_NAME_INFORMATION,
- StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS,
-// TODO-3.3 StructuredTextEditorActionConstants.ACTION_NAME_QUICK_FIX
- };
- registerKeyBindings(handler, ACTIONS_3, editor);
- }
- }
- cleanActionBarStatus();
- actionBars.updateActionBars();
- }
- fToggleOccurencesMarkUp.setEditor(getTextEditor(part));
- fToggleOccurencesMarkUp.update();
-
- updateStatus();
- }
-
- protected void updateStatus() {
- if (fActiveEditorPart instanceof ITextEditor) {
- ITextEditor textEditor = (ITextEditor) fActiveEditorPart;
- fContentAssistProposal
- .setAction(getAction(
- textEditor,
- StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS));
- fContentAssistTip
- .setAction(getAction(
- textEditor,
- StructuredTextEditorActionConstants.ACTION_NAME_INFORMATION));
- }
- if (fActiveEditorPart instanceof ITextEditorExtension) {
- ITextEditorExtension extension = (ITextEditorExtension) fActiveEditorPart;
- for (int i = 0; i < STATUSFIELDS.length; i++)
- extension.setStatusField((IStatusField) fStatusFields
- .get(STATUSFIELDS[i]), STATUSFIELDS[i]);
- }
- }
-}
+/*******************************************************************************
+ * 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.jst.jsp.jspeditor;
+
+import java.util.ResourceBundle;
+
+import org.jboss.tools.common.model.ui.texteditors.AbstractMultiPageContributor;
+import org.eclipse.jem.internal.java.adapters.nls.ResourceHandler;
+import org.eclipse.jface.action.IStatusLineManager;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.ide.IDEActionFactory;
+import org.eclipse.ui.texteditor.IStatusField;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
+import org.eclipse.ui.texteditor.ITextEditorExtension;
+import org.eclipse.ui.texteditor.RetargetTextEditorAction;
+import org.eclipse.wst.sse.ui.internal.actions.ActionDefinitionIds;
+import org.eclipse.wst.sse.ui.internal.actions.StructuredTextEditorActionConstants;
+
+import org.jboss.tools.common.text.xml.xpl.ToggleOccurencesMarkUpAction;
+
+/**
+ * @author Jeremy
+ *
+ */
+public class JSPMultiPageContributor extends AbstractMultiPageContributor {
+ protected RetargetTextEditorAction fShowTooltipAction = null; // show
+
+ protected RetargetTextEditorAction fContentAssist = null;
+
+ public JSPMultiPageContributor() {
+ fToggleOccurencesMarkUp = new ToggleOccurencesMarkUpAction();
+ }
+
+ public void init(IActionBars bars) {
+ super.init(bars);
+ initEditMenu(bars);
+ ResourceBundle resourceBundle = ResourceHandler.getResourceBundle();
+
+ fShowTooltipAction = new RetargetTextEditorAction(resourceBundle,
+ StructuredTextEditorActionConstants.ACTION_NAME_INFORMATION
+ + StructuredTextEditorActionConstants.DOT);
+ fShowTooltipAction
+ .setActionDefinitionId(ActionDefinitionIds.INFORMATION);
+
+ fContentAssist = new RetargetTextEditorAction(
+ resourceBundle,
+ StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS
+ + StructuredTextEditorActionConstants.DOT);
+ fContentAssist
+ .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
+
+ //TODO-3.3: keep checking if 'quick fix' action appears in WTP
+// fQuickFix = new RetargetTextEditorAction(resourceBundle,
+// StructuredTextEditorActionConstants.ACTION_NAME_QUICK_FIX
+// + StructuredTextEditorActionConstants.DOT);
+// fQuickFix.setActionDefinitionId(ActionDefinitionIds.QUICK_FIX);
+ }
+
+ protected void createAssistObjects() {
+ ResourceBundle resourceBundle = ResourceHandler.getResourceBundle();
+
+ fContentAssistProposal = new RetargetTextEditorAction(
+ resourceBundle,
+ StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS
+ + StructuredTextEditorActionConstants.DOT);
+ fContentAssistProposal
+ .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
+
+ fContentAssistTip = new RetargetTextEditorAction(resourceBundle,
+ StructuredTextEditorActionConstants.ACTION_NAME_INFORMATION
+ + StructuredTextEditorActionConstants.DOT);
+ fContentAssistTip
+ .setActionDefinitionId(ActionDefinitionIds.INFORMATION);
+ }
+
+ public void setActiveEditor(IEditorPart part) {
+ IEditorPart activeNestedEditor = null;
+ if (part instanceof JSPMultiPageEditor) {
+ activeNestedEditor = ((JSPMultiPageEditor) part).getActiveEditor();
+ }
+ setActivePage(activeNestedEditor);
+
+ mainPart = part;
+
+ IActionBars actionBars = getActionBars();
+
+ if (actionBars != null) {
+ IStatusLineManager slm = actionBars.getStatusLineManager();
+ if (slm != null) {
+ slm.setErrorMessage(null);
+ slm.setMessage(null);
+ }
+ }
+ }
+
+ public void setActivePage(IEditorPart part) {
+ if (fActiveEditorPart == part)
+ return;
+ cleanStatusLine();
+ fActiveEditorPart = part;
+ IActionBars actionBars = getActionBars();
+ if (actionBars != null) {
+
+ ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part
+ : null;
+ if (editor != null) {
+
+ actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
+ getAction(editor, ITextEditorActionConstants.DELETE));
+ actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
+ getAction(editor, ITextEditorActionConstants.UNDO));
+ actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
+ getAction(editor, ITextEditorActionConstants.REDO));
+ actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(),
+ getAction(editor, ITextEditorActionConstants.CUT));
+ actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),
+ getAction(editor, ITextEditorActionConstants.COPY));
+ actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(),
+ getAction(editor, ITextEditorActionConstants.PASTE));
+ actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL
+ .getId(), getAction(editor,
+ ITextEditorActionConstants.SELECT_ALL));
+ actionBars.setGlobalActionHandler(ActionFactory.FIND.getId(),
+ getAction(editor, ITextEditorActionConstants.FIND));
+ actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK
+ .getId(), getAction(editor, IDEActionFactory.BOOKMARK
+ .getId()));
+ actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK
+ .getId(), getAction(editor, IDEActionFactory.ADD_TASK
+ .getId()));
+ actionBars.setGlobalActionHandler(ActionFactory.PRINT.getId(),
+ getAction(editor, ITextEditorActionConstants.PRINT));
+ actionBars.setGlobalActionHandler(ActionFactory.REVERT.getId(),
+ getAction(editor, ITextEditorActionConstants.REVERT));
+ actionBars.setGlobalActionHandler(ActionFactory.SAVE.getId(),
+ getAction(editor, ITextEditorActionConstants.SAVE));
+
+ fShowTooltipAction
+ .setAction(getAction(
+ editor,
+ StructuredTextEditorActionConstants.ACTION_NAME_INFORMATION));
+ fContentAssist
+ .setAction(getAction(
+ editor,
+ StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS));
+ //TODO-3.3: keep checking if 'quick fix' action appears in WTP
+ // fQuickFix
+ // .setAction(getAction(
+ // editor,
+ // StructuredTextEditorActionConstants.ACTION_NAME_QUICK_FIX));
+
+
+ }
+
+ // re-register action on key binding service
+ IEditorPart localPart = (part != null) ? part : mainPart;
+ if (localPart != null) {
+ IHandlerService handler = (IHandlerService) localPart
+ .getEditorSite().getService(IHandlerService.class);
+ if (handler == null && mainPart != null) {
+ handler = (IHandlerService) mainPart.getEditorSite()
+ .getService(IHandlerService.class);
+ }
+ if (editor != null && handler != null) {
+ // editor
+ registerKeyBindings(handler, ACTIONS_2, editor);
+ String[] ACTIONS_3 = {
+ StructuredTextEditorActionConstants.ACTION_NAME_INFORMATION,
+ StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS,
+// TODO-3.3 StructuredTextEditorActionConstants.ACTION_NAME_QUICK_FIX
+ };
+ registerKeyBindings(handler, ACTIONS_3, editor);
+ }
+ }
+ cleanActionBarStatus();
+ actionBars.updateActionBars();
+ }
+ fToggleOccurencesMarkUp.setEditor(getTextEditor(part));
+ fToggleOccurencesMarkUp.update();
+
+ updateStatus();
+ }
+
+ protected void updateStatus() {
+ if (fActiveEditorPart instanceof ITextEditor) {
+ ITextEditor textEditor = (ITextEditor) fActiveEditorPart;
+ fContentAssistProposal
+ .setAction(getAction(
+ textEditor,
+ StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS));
+ fContentAssistTip
+ .setAction(getAction(
+ textEditor,
+ StructuredTextEditorActionConstants.ACTION_NAME_INFORMATION));
+ }
+ if (fActiveEditorPart instanceof ITextEditorExtension) {
+ ITextEditorExtension extension = (ITextEditorExtension) fActiveEditorPart;
+ for (int i = 0; i < STATUSFIELDS.length; i++)
+ extension.setStatusField((IStatusField) fStatusFields
+ .get(STATUSFIELDS[i]), STATUSFIELDS[i]);
+ }
+ }
+
+ public void dispose() {
+ if (fToggleOccurencesMarkUp != null) {
+ fToggleOccurencesMarkUp.setEditor(null);
+ fToggleOccurencesMarkUp = null;
+ }
+ super.dispose();
+ fActiveEditorPart=null;
+ mainPart=null;
+ fContentAssist=null;
+ fContentAssistProposal=null;
+ fContentAssistTip=null;
+ fShowTooltipAction=null;
+
+ }
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java 2008-02-07
06:15:54 UTC (rev 6142)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java 2008-02-07
09:57:05 UTC (rev 6143)
@@ -1,835 +1,865 @@
-/*******************************************************************************
- * 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.jst.jsp.jspeditor;
-
-import java.util.Properties;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.IResourceChangeListener;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.IMenuListener;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.viewers.IPostSelectionProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorActionBarContributor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.INavigationLocation;
-import org.eclipse.ui.INavigationLocationProvider;
-import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.IReusableEditor;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.ide.IGotoMarker;
-import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
-import org.eclipse.ui.texteditor.AbstractTextEditor;
-import org.eclipse.ui.texteditor.IDocumentProvider;
-import org.eclipse.ui.texteditor.IStatusField;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.ui.texteditor.ITextEditorExtension;
-import org.eclipse.ui.texteditor.ITextEditorExtension2;
-import org.eclipse.ui.texteditor.ITextEditorExtension3;
-import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
-import org.eclipse.ui.views.properties.IPropertySheetPage;
-import org.eclipse.wst.sse.ui.StructuredTextEditor;
-import org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage;
-import org.jboss.tools.common.core.resources.XModelObjectEditorInput;
-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.filesystems.impl.DiscardFileHandler;
-import org.jboss.tools.common.model.filesystems.impl.FolderImpl;
-import org.jboss.tools.common.model.plugin.ModelPlugin;
-import org.jboss.tools.common.model.ui.ModelUIPlugin;
-import org.jboss.tools.common.model.ui.editor.EditorDescriptor;
-import org.jboss.tools.common.model.ui.editor.IModelObjectEditorInput;
-import org.jboss.tools.common.model.util.EclipseResourceUtil;
-import org.jboss.tools.common.model.util.XModelTreeListenerSWTSync;
-import org.jboss.tools.common.text.ext.IMultiPageEditor;
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.jboss.tools.jst.jsp.editor.IVisualContext;
-import org.jboss.tools.jst.jsp.editor.IVisualController;
-import org.jboss.tools.jst.jsp.editor.IVisualEditor;
-import org.jboss.tools.jst.jsp.editor.IVisualEditorFactory;
-import org.jboss.tools.jst.jsp.preferences.VpePreference;
-import org.jboss.tools.jst.web.tld.VpeTaglibManager;
-import org.jboss.tools.jst.web.tld.VpeTaglibManagerProvider;
-import org.osgi.framework.Bundle;
-
-// Fix for EXIN-232: The IMultiPageEditor interface implementation is added.
-public class JSPMultiPageEditor extends JSPMultiPageEditorPart implements
- XModelTreeListener, ITextEditor, IGotoMarker, VpeTaglibManagerProvider,
- IReusableEditor, ITextEditorExtension, ITextEditorExtension2,
- ITextEditorExtension3, INavigationLocationProvider, IMultiPageEditor {
-
- private static final String VISUALSOURCE_TAB_LABEL =
"JSPMultiPageEditor.TabLabel.VisualSource";
-
- private static final String VISUAL_TAB_LABEL =
"JSPMultiPageEditor.TabLabel.Visual";
-
- private static final String SOURCE_TAB_LABEL =
"JSPMultiPageEditor.TabLabel.Source";
-
- /** PREVIEW_TAB_LABEL */
- private static final String PREVIEW_TAB_LABEL =
"JSPMultiPageEditor.TabLabel.Preview";
-
- private IVisualEditor visualEditor;
-
- private int visualSourceIndex;
-
- private int visualIndex;
-
- JSPTextEditor sourceEditor;
-
- private int sourceIndex;
-
- /** composite control for default web-browser */
- private IVisualEditor previewWebBrowser;
-
- /** index of tab contain default web-browser */
- private int previewIndex;
-
- private boolean osWindows = true;
-
- protected XModelTreeListenerSWTSync syncListener = new XModelTreeListenerSWTSync(
- this);
-
- private int oldPage = -1;
-
- private ConfigurableContentOutlinePage outlinePage = null;
-
- XModelObject object;
-
- private QualifiedName persistentTabQualifiedName = new QualifiedName("",
- "Selected_tab");
-
- int selectedPageIndex = 0;
-
- static IVisualEditorFactory visualEditorFactory;
-
- static {
- try {
- Bundle b = Platform.getBundle("org.jboss.tools.vpe");
- Class cls = b
- .loadClass("org.jboss.tools.vpe.editor.VpeEditorPartFactory");
- visualEditorFactory = (IVisualEditorFactory) cls.newInstance();
- } catch (Exception e) {
- JspEditorPlugin.getPluginLog().logError("Error in loading visual editor
factory", e);
- }
- }
-
- private void loadSelectedTab() {
- IFile file = getFile();
- try {
- String q = (file == null) ? null :
file.getPersistentProperty(persistentTabQualifiedName);
- if (q == null) {
- if ("Source".equalsIgnoreCase(VpePreference.EDITOR_VIEW_OPTION
- .getValue()))
- selectedPageIndex = 2;
- else if ("Visual"
- .equalsIgnoreCase(VpePreference.EDITOR_VIEW_OPTION
- .getValue()))
- selectedPageIndex = 1;
- else
- selectedPageIndex = 0;
- } else {
- int qi = Integer.parseInt(q);
-
- if (qi >= 0 && qi < getTabFolder().getItemCount())
- selectedPageIndex = qi;
- }
-
- } catch (Exception e) {
- selectedPageIndex = 0;
- }
- }
-
- protected int getSourcePageIndex() {
- return sourceIndex;
- }
-
- private void saveSelectedTab() {
- IFile file = getFile();
- if(file == null) return;
- String q = "" + selectedPageIndex;
- try {
- file.setPersistentProperty(persistentTabQualifiedName, q);
- } catch (CoreException e) {
- JspEditorPlugin.getPluginLog().logWarning(e);
- }
- }
-
- public void superPageChange(int newPageIndex) {
- Control control = getControl(visualSourceIndex);
- if (control != null) {
- control.setVisible(true);
- }
- setFocus();
- IEditorPart activeEditor = getEditor(visualSourceIndex);
- IEditorActionBarContributor contributor = getEditorSite()
- .getActionBarContributor();
- if (contributor != null
- && contributor instanceof MultiPageEditorActionBarContributor) {
- ((MultiPageEditorActionBarContributor) contributor)
- .setActivePage(activeEditor);
- }
- if (activeEditor != null) {
- ISelectionProvider selectionProvider = activeEditor.getSite()
- .getSelectionProvider();
- if (selectionProvider != null) {
- SelectionChangedEvent event = new SelectionChangedEvent(
- selectionProvider, selectionProvider.getSelection());
- ((JSPMultiPageSelectionProvider) getSite()
- .getSelectionProvider()).fireSelectionChanged(event);
- }
- }
- }
-
- protected void pageChange(int newPageIndex) {
- selectedPageIndex = newPageIndex;
- if (osWindows) {
- if (newPageIndex == visualSourceIndex)
- visualEditor.setVisualMode(IVisualEditor.VISUALSOURCE_MODE);
- else if (newPageIndex == visualIndex)
- visualEditor.setVisualMode(IVisualEditor.VISUAL_MODE);
- else if (newPageIndex == sourceIndex)
- visualEditor.setVisualMode(IVisualEditor.SOURCE_MODE);
- else if (newPageIndex == previewIndex) {
- visualEditor.setVisualMode(IVisualEditor.PREVIEW_MODE);
- }
-
- superPageChange(newPageIndex);
- } else {
- super.pageChange(newPageIndex);
- }
- oldPage = newPageIndex;
- }
-
- public void setInput(IEditorInput input) {
- super.setInput(XModelObjectEditorInput.checkInput(input));
- if (getEditorInput() instanceof IModelObjectEditorInput) {
- object = ((IModelObjectEditorInput) getEditorInput())
- .getXModelObject();
- }
- if (sourceEditor != null
- && sourceEditor.getEditorInput() != getEditorInput()
- && sourceEditor.getEditorInput() != null) {
- if (sourceEditor instanceof AbstractTextEditor) {
- try {
- ((AbstractTextEditor) sourceEditor)
- .setInput(getEditorInput());
- } catch (Exception exc) {
- JspEditorPlugin.getPluginLog().logError(exc);
- }
- }
- visualEditor.setInput(getEditorInput());
- updateTitle();
- }
- updateFile();
- }
-
- private void updateFile() {
- IFile file = getFile();
- if (file == null) return;
- try {
- file.refreshLocal(0, null);
- } catch (CoreException e) {
- JspEditorPlugin.getPluginLog().logWarning(e);
- }
- }
-
- private IFile getFile() {
- IEditorInput input = getEditorInput();
- return (input instanceof IFileEditorInput) ? ((IFileEditorInput) input)
- .getFile() : null;
- }
-
- public String getContentDescription() {
- return "";
- }
-
- /**
- *
- */
- private ISelectionProvider selectionProvider = null;
-
- protected IEditorSite createSite(IEditorPart editor) {
- JSPMultiPageEditorSite site = new JSPMultiPageEditorSite(this, editor) {
- private ISelectionChangedListener postSelectionChangedListener = null;
-
- private ISelectionChangedListener getPostSelectionChangedListener() {
- if (postSelectionChangedListener == null) {
- postSelectionChangedListener = new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- handlePostSelectionChanged(event);
- }
- };
- }
- return postSelectionChangedListener;
- }
-
- protected void handlePostSelectionChanged(
- SelectionChangedEvent event) {
- ISelectionProvider parentProvider = getMultiPageEditor()
- .getSite().getSelectionProvider();
- ISelection s = event.getSelection();
- if (s == null || s.isEmpty())
- return;
- if (s instanceof ITextSelection) {
- if (parentProvider instanceof JSPMultiPageSelectionProvider) {
- ((JSPMultiPageSelectionProvider) parentProvider)
- .firePostSelectionChanged(event);
- }
- }
- }
-
- public String getId() {
- return getSite().getId(); //$NON-NLS-1$
- }
-
- /**
- *
- */
- public ISelectionProvider getSelectionProvider() {
- return selectionProvider;
- }
-
- /**
- *
- */
- public void setSelectionProvider(ISelectionProvider provider) {
- ISelectionProvider oldSelectionProvider = getSelectionProvider();
- if (oldSelectionProvider != null) {
- if (oldSelectionProvider instanceof IPostSelectionProvider) {
- ((IPostSelectionProvider) oldSelectionProvider)
- .removePostSelectionChangedListener(getPostSelectionChangedListener());
- }
- }
-
- selectionProvider = provider;
- if (oldSelectionProvider != null) {
- oldSelectionProvider
- .removeSelectionChangedListener(getSelectionChangedListener());
- }
- if (selectionProvider != null) {
- selectionProvider
- .addSelectionChangedListener(getSelectionChangedListener());
- }
-
- if (provider != null) {
- if (provider instanceof IPostSelectionProvider) {
- ((IPostSelectionProvider) provider)
- .addPostSelectionChangedListener(getPostSelectionChangedListener());
- }
- }
- }
-
- public Object getService(Class api) {
- // TODO megration to eclipse 3.2
- return null;
- }
-
- public boolean hasService(Class api) {
- // TODO megration to eclipse 3.2
- return false;
- }
- };
- return site;
- }
-
- protected void createPages() {
-
- // Sergey Vasilyev
- /*
- * TODO to author of this class VPE work on linux! this check not need
- * in future
- */
- // String os_name = System.getProperty("os.name");
- if (true) {// (os_name.startsWith("Windows")){
- osWindows = true;
- createPagesForWindows();
- } else {
- osWindows = false;
- }
- if (selectedPageIndex == sourceIndex) {
- visualEditor.setVisualMode(IVisualEditor.SOURCE_MODE);
- // switchOutlineToJSPEditor();
- }
- loadSelectedTab();
- setActivePage(selectedPageIndex);
- pageChange(selectedPageIndex);
-
- new ResourceChangeListener(this, getContainer());
- if (getModelObject() != null) {
- getModelObject().getModel().addModelTreeListener(syncListener);
- }
- }
-
- private void createPagesForWindows() {
- sourceEditor = new JSPTextEditor(this);
- visualEditor = visualEditorFactory.createVisualEditor(this,
- sourceEditor, false);
-
- try {
- visualSourceIndex = addPage(visualEditor, getEditorInput());
- setPageText(visualSourceIndex, JSPEditorMessages
- .getString(VISUALSOURCE_TAB_LABEL));
- setPartName(visualEditor.getTitle());
- } catch (PartInitException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- try {
- visualIndex = addPage(visualEditor, getEditorInput());
- setPageText(visualIndex, JSPEditorMessages
- .getString(VISUAL_TAB_LABEL));
- setPartName(visualEditor.getTitle());
- } catch (PartInitException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
-
- try {
- sourceIndex = addPage(visualEditor, getEditorInput());
- setPageText(sourceIndex, JSPEditorMessages
- .getString(SOURCE_TAB_LABEL));
- setPartName(visualEditor.getTitle());
- } catch (PartInitException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
-
- // Add tab contain default web-browser
- try {
- previewIndex = addPage(visualEditor, getEditorInput());
- setPageText(previewIndex, JSPEditorMessages
- .getString(PREVIEW_TAB_LABEL));
- setPartName(visualEditor.getTitle());
- } catch (PartInitException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
-
- }
-
- public void doSave(IProgressMonitor monitor) {
- sourceEditor.doSave(monitor);
- }
-
- class PCL implements IPropertyListener {
- public void propertyChanged(Object source, int i) {
- firePropertyChange(i);
- if (i == IEditorPart.PROP_INPUT
- && getEditorInput() != sourceEditor.getEditorInput()) {
- setInput(sourceEditor.getEditorInput());
- setPartName(sourceEditor.getPartName());
- setTitleToolTip(sourceEditor.getTitleToolTip());
- }
- }
- }
-
- public void doSaveAs() {
- XModelObject old = getModelObject();
- PCL pcl = new PCL();
- sourceEditor.addPropertyListener(pcl);
- sourceEditor.doSaveAs();
- sourceEditor.removePropertyListener(pcl);
- try {
- if (old.isModified())
- new DiscardFileHandler().executeHandler(old, new Properties());
- } catch (Exception e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- }
-
- public void gotoMarker(final IMarker marker) {
- setActivePage(sourceIndex);
- pageChange(sourceIndex);
- IGotoMarker adapter = (IGotoMarker) sourceEditor
- .getAdapter(IGotoMarker.class);
- if (adapter != null) {
- adapter.gotoMarker(marker);
- }
- }
-
- public boolean isSaveAsAllowed() {
- return sourceEditor.isSaveAsAllowed();
- }
-
- public JSPTextEditor getJspEditor() {
- return sourceEditor;
- }
-
- public StructuredTextEditor getSourceEditor() {
- return sourceEditor;
- }
-
- public IVisualEditor getVisualEditor() {
- return visualEditor;
- }
-
- public IEditorPart getActivePageEditor() {
- return getActiveEditor();
- }
-
- protected XModelObject getModelObject() {
- return object;
- }
-
- public void dispose() {
- saveSelectedTab();
- XModelObject o = getModelObject();
- visualEditor.dispose();
- super.dispose();
- if (o != null) {
- o.getModel().removeModelTreeListener(syncListener);
- }
- if (o != null && o.isModified() && o.isActive()) {
- try {
- ((FolderImpl) o.getParent()).discardChildFile(o);
- } catch (Exception e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- }
- }
-
- public Object getAdapter(Class adapter) {
- if (IContentOutlinePage.class.equals(adapter)) {
- if (osWindows) {
- if (visualEditor != null) {
- if (outlinePage == null)
- outlinePage = (ConfigurableContentOutlinePage) visualEditor
- .getAdapter(adapter);
- return outlinePage;
- }
- } else {
- if (sourceEditor != null) {
- return sourceEditor.getAdapter(adapter);
- }
- }
- } else if (IPropertySheetPage.class.equals(adapter)) {
- if (sourceEditor != null)
- return sourceEditor.getAdapter(adapter);
- } else if (adapter == EditorDescriptor.class)
- return new EditorDescriptor(new String[] { "jsp", "html" });
-
- if (sourceEditor != null) {
- return sourceEditor.getAdapter(adapter);
- }
-
- return super.getAdapter(adapter);
- }
-
- public void nodeChanged(XModelTreeEvent event) {
- if (event.getModelObject() == getModelObject()) {
- setContentDescription(getEditorInput().getName());
- if (sourceEditor != null)
- sourceEditor.updateModification();
- }
- }
-
- public void structureChanged(XModelTreeEvent event) {
- }
-
- public void close(boolean save) {
- sourceEditor.close(save);
- }
-
- public void doRevertToSaved() {
- sourceEditor.doRevertToSaved();
- }
-
- public IAction getAction(String actionId) {
- return sourceEditor.getAction(actionId);
- }
-
- public IDocumentProvider getDocumentProvider() {
- return sourceEditor.getDocumentProvider();
- }
-
- public IRegion getHighlightRange() {
- return sourceEditor.getHighlightRange();
- }
-
- public ISelectionProvider getSelectionProvider() {
- return sourceEditor.getSelectionProvider();
- }
-
- public boolean isEditable() {
- return sourceEditor.isEditable();
- }
-
- public void removeActionActivationCode(String actionId) {
- sourceEditor.removeActionActivationCode(actionId);
- }
-
- public void resetHighlightRange() {
- sourceEditor.resetHighlightRange();
- }
-
- public void selectAndReveal(int offset, int length) {
- sourceEditor.selectAndReveal(offset, length);
- }
-
- public void setAction(String actionID, IAction action) {
- sourceEditor.setAction(actionID, action);
- }
-
- public void setActionActivationCode(String actionId,
- char activationCharacter, int activationKeyCode,
- int activationStateMask) {
- sourceEditor.setActionActivationCode(actionId, activationCharacter,
- activationKeyCode, activationStateMask);
- }
-
- public void setHighlightRange(int offset, int length, boolean moveCursor) {
- sourceEditor.setHighlightRange(offset, length, moveCursor);
- }
-
- public void showHighlightRangeOnly(boolean showHighlightRangeOnly) {
- sourceEditor.showHighlightRangeOnly(showHighlightRangeOnly);
- }
-
- public boolean showsHighlightRangeOnly() {
- return sourceEditor.showsHighlightRangeOnly();
- }
-
- public VpeTaglibManager getTaglibManager() {
- if (visualEditor != null) {
- IVisualController controller = visualEditor.getController();
- if (controller != null) {
- IVisualContext context = controller.getPageContext();
- if (context != null) {
- return context;
- }
- }
- }
- return null;
- }
-
- void updateTitle() {
- setPartName(getEditorInput().getName());
- }
-
- public void runDropCommand(String flavor, String data) {
- if (sourceEditor != null)
- sourceEditor.runDropCommand(flavor, data);
- }
-
- public void setStatusField(IStatusField field, String category) {
- if (sourceEditor != null)
- sourceEditor.setStatusField(field, category);
- }
-
- public boolean isEditorInputReadOnly() {
- if (sourceEditor != null) {
- return sourceEditor.isEditorInputReadOnly();
- }
- return false;
- }
-
- public void addRulerContextMenuListener(IMenuListener listener) {
- if (sourceEditor != null)
- sourceEditor.addRulerContextMenuListener(listener);
- }
-
- public void removeRulerContextMenuListener(IMenuListener listener) {
- if (sourceEditor != null)
- sourceEditor.removeRulerContextMenuListener(listener);
- }
-
- public boolean isEditorInputModifiable() {
- if (sourceEditor != null) {
- return sourceEditor.isEditorInputModifiable();
- }
- return false;
- }
-
- public boolean validateEditorInputState() {
- if (sourceEditor != null) {
- return sourceEditor.validateEditorInputState();
- }
- return false;
- }
-
- public InsertMode getInsertMode() {
- if (sourceEditor != null) {
- return sourceEditor.getInsertMode();
- }
- return null;
- }
-
- public void setInsertMode(InsertMode mode) {
- if (sourceEditor != null)
- sourceEditor.setInsertMode(mode);
- }
-
- public void showChangeInformation(boolean show) {
- if (sourceEditor != null)
- sourceEditor.showChangeInformation(show);
- }
-
- public boolean isChangeInformationShowing() {
- if (sourceEditor != null) {
- return sourceEditor.isChangeInformationShowing();
- }
- return false;
- }
-
- public INavigationLocation createEmptyNavigationLocation() {
- if (sourceEditor != null) {
- return sourceEditor.createEmptyNavigationLocation();
- }
- return null;
- }
-
- public INavigationLocation createNavigationLocation() {
- if (sourceEditor != null) {
- return sourceEditor.createNavigationLocation();
- }
- return null;
- }
-}
-
-class ResourceChangeListener implements IResourceChangeListener {
- IEditorPart editorPart;
-
- Composite container;
-
- ResourceChangeListener(IEditorPart editorPart, Composite container) {
- this.editorPart = editorPart;
- this.container = container;
- IWorkspace workspace = ModelUIPlugin.getWorkspace();
- if (workspace == null)
- return;
- workspace.addResourceChangeListener(this);
- container.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- IWorkspace workspace = ModelUIPlugin.getWorkspace();
- if (workspace == null)
- return;
- workspace
- .removeResourceChangeListener(ResourceChangeListener.this);
- }
- });
- }
-
- public void resourceChanged(IResourceChangeEvent event) {
- IEditorInput ei = editorPart.getEditorInput();
- if (!(ei instanceof IFileEditorInput))
- return;
- IFileEditorInput fi = (IFileEditorInput) ei;
- IFile f = fi.getFile();
- if (f == null)
- return;
- IPath path = getPathChange(event, f);
- if (path == null) {
- if (f != null && !f.exists())
- closeEditor();
- return;
- }
- f = ModelPlugin.getWorkspace().getRoot().getFile(path);
- XModelObject p = f == null ? null : EclipseResourceUtil
- .getObjectByResource(f.getParent());
- if (p instanceof FolderImpl) {
- ((FolderImpl) p).update();
- }
- XModelObject o = EclipseResourceUtil.getObjectByResource(f);
- if (f != null && f.exists() && o != null) {
- if (editorPart instanceof JSPMultiPageEditor) {
- JSPMultiPageEditor e = (JSPMultiPageEditor) editorPart;
- if (ei instanceof XModelObjectEditorInput) {
- IEditorInput e2 = XModelObjectEditorInput.createInstance(o);
- e.setInput(e2);
- e.updateTitle();
- if (e.sourceEditor instanceof AbstractTextEditor) {
- if (e.sourceEditor != null
- && e.sourceEditor.getEditorInput() != e
- .getEditorInput()) {
- try {
- ((AbstractTextEditor) e.sourceEditor)
- .setInput(e2);
- } catch (Exception exc) {
- JspEditorPlugin.getPluginLog().logError(exc);
- }
- }
- ((XModelObjectEditorInput) ei).synchronize();
- }
- }
- }
- }
- if (f == null || f.exists())
- return;
- closeEditor();
- }
-
- private void closeEditor() {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- editorPart.getSite().getPage().closeEditor(editorPart, false);
- }
- });
- }
-
- private IPath getPathChange(IResourceChangeEvent event, IFile f) {
- return getPathChange(event.getDelta(), f.getFullPath());
- }
-
- private IPath getPathChange(IResourceDelta delta, IPath p) {
- if (delta == null || delta.getFullPath() == null)
- return null;
- if (!delta.getFullPath().isPrefixOf(p))
- return null;
- if (delta != null && delta.getKind() == IResourceDelta.CHANGED) {
- IResourceDelta[] ds = delta.getAffectedChildren();
- if (ds == null)
- return null;
- if (ds.length == 2) {
- if (ds[1].getKind() == IResourceDelta.REMOVED) {
- IPath d = ds[1].getFullPath();
- if (d.equals(p))
- return ds[0].getFullPath();
- if (d.isPrefixOf(p)) {
- return ds[0].getFullPath().append(
- p.removeFirstSegments(d.segmentCount()));
- }
- } else if (ds[0].getKind() == IResourceDelta.REMOVED) {
- IPath d = ds[0].getFullPath();
- if (d.equals(p))
- return ds[1].getFullPath();
- if (d.isPrefixOf(p)) {
- return ds[1].getFullPath().append(
- p.removeFirstSegments(d.segmentCount()));
- }
- }
- }
- for (int i = 0; i < ds.length; i++) {
- IPath ps = getPathChange(ds[i], p);
- if (ps != null)
- return ps;
- }
- }
- return null;
- }
+/*******************************************************************************
+ * 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.jst.jsp.jspeditor;
+
+import java.util.Properties;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.IPostSelectionProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorActionBarContributor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.INavigationLocation;
+import org.eclipse.ui.INavigationLocationProvider;
+import org.eclipse.ui.IPropertyListener;
+import org.eclipse.ui.IReusableEditor;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IGotoMarker;
+import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.IStatusField;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.ITextEditorExtension;
+import org.eclipse.ui.texteditor.ITextEditorExtension2;
+import org.eclipse.ui.texteditor.ITextEditorExtension3;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage;
+import org.jboss.tools.common.core.resources.XModelObjectEditorInput;
+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.filesystems.impl.DiscardFileHandler;
+import org.jboss.tools.common.model.filesystems.impl.FolderImpl;
+import org.jboss.tools.common.model.plugin.ModelPlugin;
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
+import org.jboss.tools.common.model.ui.editor.EditorDescriptor;
+import org.jboss.tools.common.model.ui.editor.IModelObjectEditorInput;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.model.util.XModelTreeListenerSWTSync;
+import org.jboss.tools.common.text.ext.IMultiPageEditor;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.editor.IVisualContext;
+import org.jboss.tools.jst.jsp.editor.IVisualController;
+import org.jboss.tools.jst.jsp.editor.IVisualEditor;
+import org.jboss.tools.jst.jsp.editor.IVisualEditorFactory;
+import org.jboss.tools.jst.jsp.preferences.VpePreference;
+import org.jboss.tools.jst.web.tld.VpeTaglibManager;
+import org.jboss.tools.jst.web.tld.VpeTaglibManagerProvider;
+import org.osgi.framework.Bundle;
+
+// Fix for EXIN-232: The IMultiPageEditor interface implementation is added.
+public class JSPMultiPageEditor extends JSPMultiPageEditorPart implements
+ XModelTreeListener, ITextEditor, IGotoMarker, VpeTaglibManagerProvider,
+ IReusableEditor, ITextEditorExtension, ITextEditorExtension2,
+ ITextEditorExtension3, INavigationLocationProvider, IMultiPageEditor {
+
+ private static final String VISUALSOURCE_TAB_LABEL =
"JSPMultiPageEditor.TabLabel.VisualSource";
+
+ private static final String VISUAL_TAB_LABEL =
"JSPMultiPageEditor.TabLabel.Visual";
+
+ private static final String SOURCE_TAB_LABEL =
"JSPMultiPageEditor.TabLabel.Source";
+
+ /** PREVIEW_TAB_LABEL */
+ private static final String PREVIEW_TAB_LABEL =
"JSPMultiPageEditor.TabLabel.Preview";
+
+ private IVisualEditor visualEditor;
+
+ private int visualSourceIndex;
+
+ private int visualIndex;
+
+ JSPTextEditor sourceEditor;
+
+ private int sourceIndex;
+
+ /** composite control for default web-browser */
+ //private IVisualEditor previewWebBrowser;
+
+ /** index of tab contain default web-browser */
+ private int previewIndex;
+
+ private boolean osWindows = true;
+
+ protected XModelTreeListenerSWTSync syncListener = new XModelTreeListenerSWTSync(
+ this);
+
+ private int oldPage = -1;
+
+ private ConfigurableContentOutlinePage outlinePage = null;
+
+ XModelObject object;
+
+ private QualifiedName persistentTabQualifiedName = new QualifiedName("",
+ "Selected_tab");
+
+ int selectedPageIndex = 0;
+
+ static IVisualEditorFactory visualEditorFactory;
+
+ static {
+ try {
+ Bundle b = Platform.getBundle("org.jboss.tools.vpe");
+ Class cls = b
+ .loadClass("org.jboss.tools.vpe.editor.VpeEditorPartFactory");
+ visualEditorFactory = (IVisualEditorFactory) cls.newInstance();
+ } catch (Exception e) {
+ JspEditorPlugin.getPluginLog().logError("Error in loading visual editor
factory", e);
+ }
+ }
+
+ private void loadSelectedTab() {
+ IFile file = getFile();
+ try {
+ String q = (file == null) ? null :
file.getPersistentProperty(persistentTabQualifiedName);
+ if (q == null) {
+ if ("Source".equalsIgnoreCase(VpePreference.EDITOR_VIEW_OPTION
+ .getValue()))
+ selectedPageIndex = 2;
+ else if ("Visual"
+ .equalsIgnoreCase(VpePreference.EDITOR_VIEW_OPTION
+ .getValue()))
+ selectedPageIndex = 1;
+ else
+ selectedPageIndex = 0;
+ } else {
+ int qi = Integer.parseInt(q);
+
+ if (qi >= 0 && qi < getTabFolder().getItemCount())
+ selectedPageIndex = qi;
+ }
+
+ } catch (Exception e) {
+ selectedPageIndex = 0;
+ }
+ }
+
+ protected int getSourcePageIndex() {
+ return sourceIndex;
+ }
+
+ private void saveSelectedTab() {
+ IFile file = getFile();
+ if(file == null) return;
+ String q = "" + selectedPageIndex;
+ try {
+ file.setPersistentProperty(persistentTabQualifiedName, q);
+ } catch (CoreException e) {
+ JspEditorPlugin.getPluginLog().logWarning(e);
+ }
+ }
+
+ public void superPageChange(int newPageIndex) {
+ Control control = getControl(visualSourceIndex);
+ if (control != null) {
+ control.setVisible(true);
+ }
+ setFocus();
+ IEditorPart activeEditor = getEditor(visualSourceIndex);
+ IEditorActionBarContributor contributor = getEditorSite()
+ .getActionBarContributor();
+ if (contributor != null
+ && contributor instanceof MultiPageEditorActionBarContributor) {
+ ((MultiPageEditorActionBarContributor) contributor)
+ .setActivePage(activeEditor);
+ }
+ if (activeEditor != null) {
+ ISelectionProvider selectionProvider = activeEditor.getSite()
+ .getSelectionProvider();
+ if (selectionProvider != null) {
+ SelectionChangedEvent event = new SelectionChangedEvent(
+ selectionProvider, selectionProvider.getSelection());
+ ((JSPMultiPageSelectionProvider) getSite()
+ .getSelectionProvider()).fireSelectionChanged(event);
+ }
+ }
+ }
+
+ protected void pageChange(int newPageIndex) {
+ selectedPageIndex = newPageIndex;
+ if (osWindows) {
+ if (newPageIndex == visualSourceIndex) {
+ if (visualEditor.getVisualEditor() == null) {
+ visualEditor.createVisualEditor();
+ }
+ visualEditor.setVisualMode(IVisualEditor.VISUALSOURCE_MODE);
+ }
+ else if (newPageIndex == visualIndex) {
+ if (visualEditor.getVisualEditor() == null) {
+ visualEditor.createVisualEditor();
+ }
+ visualEditor.setVisualMode(IVisualEditor.VISUAL_MODE);
+ }
+ else if (newPageIndex == sourceIndex)
+ visualEditor.setVisualMode(IVisualEditor.SOURCE_MODE);
+ else if (newPageIndex == previewIndex) {
+ if (visualEditor.getPreviewWebBrowser() == null) {
+ visualEditor.createPreviewBrowser();
+ }
+ visualEditor.setVisualMode(IVisualEditor.PREVIEW_MODE);
+ }
+
+ superPageChange(newPageIndex);
+ } else {
+ super.pageChange(newPageIndex);
+ }
+ oldPage = newPageIndex;
+ }
+
+ public void setInput(IEditorInput input) {
+ super.setInput(XModelObjectEditorInput.checkInput(input));
+ if (getEditorInput() instanceof IModelObjectEditorInput) {
+ object = ((IModelObjectEditorInput) getEditorInput())
+ .getXModelObject();
+ }
+ if (sourceEditor != null
+ && sourceEditor.getEditorInput() != getEditorInput()
+ && sourceEditor.getEditorInput() != null) {
+ if (sourceEditor instanceof AbstractTextEditor) {
+ try {
+ ((AbstractTextEditor) sourceEditor)
+ .setInput(getEditorInput());
+ } catch (Exception exc) {
+ JspEditorPlugin.getPluginLog().logError(exc);
+ }
+ }
+ visualEditor.setInput(getEditorInput());
+ updateTitle();
+ }
+ updateFile();
+ }
+
+ private void updateFile() {
+ IFile file = getFile();
+ if (file == null) return;
+ try {
+ file.refreshLocal(0, null);
+ } catch (CoreException e) {
+ JspEditorPlugin.getPluginLog().logWarning(e);
+ }
+ }
+
+ private IFile getFile() {
+ IEditorInput input = getEditorInput();
+ return (input instanceof IFileEditorInput) ? ((IFileEditorInput) input)
+ .getFile() : null;
+ }
+
+ public String getContentDescription() {
+ return "";
+ }
+
+ /**
+ *
+ */
+ private ISelectionProvider selectionProvider = null;
+
+ private JSPMultiPageEditorSite site;
+
+ protected IEditorSite createSite(IEditorPart editor) {
+ site = new JSPMultiPageEditorSite(this, editor) {
+ private ISelectionChangedListener postSelectionChangedListener = null;
+
+ private ISelectionChangedListener getPostSelectionChangedListener() {
+ if (postSelectionChangedListener == null) {
+ postSelectionChangedListener = new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ handlePostSelectionChanged(event);
+ }
+ };
+ }
+ return postSelectionChangedListener;
+ }
+
+ protected void handlePostSelectionChanged(
+ SelectionChangedEvent event) {
+ ISelectionProvider parentProvider = getMultiPageEditor()
+ .getSite().getSelectionProvider();
+ ISelection s = event.getSelection();
+ if (s == null || s.isEmpty())
+ return;
+ if (s instanceof ITextSelection) {
+ if (parentProvider instanceof JSPMultiPageSelectionProvider) {
+ ((JSPMultiPageSelectionProvider) parentProvider)
+ .firePostSelectionChanged(event);
+ }
+ }
+ }
+
+ public String getId() {
+ return getSite().getId(); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ */
+ public ISelectionProvider getSelectionProvider() {
+ return selectionProvider;
+ }
+
+ /**
+ *
+ */
+ public void setSelectionProvider(ISelectionProvider provider) {
+ ISelectionProvider oldSelectionProvider = getSelectionProvider();
+ if (oldSelectionProvider != null) {
+ if (oldSelectionProvider instanceof IPostSelectionProvider) {
+ ((IPostSelectionProvider) oldSelectionProvider)
+ .removePostSelectionChangedListener(getPostSelectionChangedListener());
+ }
+ }
+
+ selectionProvider = provider;
+ if (oldSelectionProvider != null) {
+ oldSelectionProvider
+ .removeSelectionChangedListener(getSelectionChangedListener());
+ }
+ if (selectionProvider != null) {
+ selectionProvider
+ .addSelectionChangedListener(getSelectionChangedListener());
+ }
+
+ if (provider != null) {
+ if (provider instanceof IPostSelectionProvider) {
+ ((IPostSelectionProvider) provider)
+ .addPostSelectionChangedListener(getPostSelectionChangedListener());
+ }
+ }
+
+
+ }
+
+ public Object getService(Class api) {
+ // TODO megration to eclipse 3.2
+ return null;
+ }
+
+ public boolean hasService(Class api) {
+ // TODO megration to eclipse 3.2
+ return false;
+ }
+
+ public void dispose() {
+ ISelectionProvider provider = getSelectionProvider();
+ if (provider instanceof IPostSelectionProvider &&
postSelectionChangedListener != null) {
+ ((IPostSelectionProvider) provider)
+ .removePostSelectionChangedListener(postSelectionChangedListener);
+
+ }
+ postSelectionChangedListener = null;
+ super.dispose();
+ }
+ };
+ return site;
+ }
+
+ protected void createPages() {
+
+ // Sergey Vasilyev
+ /*
+ * TODO to author of this class VPE work on linux! this check not need
+ * in future
+ */
+ // String os_name = System.getProperty("os.name");
+ if (true) {// (os_name.startsWith("Windows")){
+ osWindows = true;
+ createPagesForWindows();
+ } else {
+ osWindows = false;
+ }
+ if (selectedPageIndex == sourceIndex) {
+ visualEditor.setVisualMode(IVisualEditor.SOURCE_MODE);
+ // switchOutlineToJSPEditor();
+ }
+ loadSelectedTab();
+ setActivePage(selectedPageIndex);
+ pageChange(selectedPageIndex);
+
+ new ResourceChangeListener(this, getContainer());
+ if (getModelObject() != null) {
+ getModelObject().getModel().addModelTreeListener(syncListener);
+ }
+ }
+
+ private void createPagesForWindows() {
+ sourceEditor = new JSPTextEditor(this);
+ visualEditor = visualEditorFactory.createVisualEditor(this,
+ sourceEditor, false);
+
+ try {
+ visualSourceIndex = addPage(visualEditor, getEditorInput());
+ setPageText(visualSourceIndex, JSPEditorMessages
+ .getString(VISUALSOURCE_TAB_LABEL));
+ setPartName(visualEditor.getTitle());
+ } catch (PartInitException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ try {
+ visualIndex = addPage(visualEditor, getEditorInput());
+ setPageText(visualIndex, JSPEditorMessages
+ .getString(VISUAL_TAB_LABEL));
+ setPartName(visualEditor.getTitle());
+ } catch (PartInitException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+
+ try {
+ sourceIndex = addPage(visualEditor, getEditorInput());
+ setPageText(sourceIndex, JSPEditorMessages
+ .getString(SOURCE_TAB_LABEL));
+ setPartName(visualEditor.getTitle());
+ } catch (PartInitException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+
+ // Add tab contain default web-browser
+ try {
+ previewIndex = addPage(visualEditor, getEditorInput());
+ setPageText(previewIndex, JSPEditorMessages
+ .getString(PREVIEW_TAB_LABEL));
+ setPartName(visualEditor.getTitle());
+ } catch (PartInitException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+
+ }
+
+ public void doSave(IProgressMonitor monitor) {
+ sourceEditor.doSave(monitor);
+ }
+
+ class PCL implements IPropertyListener {
+ public void propertyChanged(Object source, int i) {
+ firePropertyChange(i);
+ if (i == IEditorPart.PROP_INPUT
+ && getEditorInput() != sourceEditor.getEditorInput()) {
+ setInput(sourceEditor.getEditorInput());
+ setPartName(sourceEditor.getPartName());
+ setTitleToolTip(sourceEditor.getTitleToolTip());
+ }
+ }
+ }
+
+ public void doSaveAs() {
+ XModelObject old = getModelObject();
+ PCL pcl = new PCL();
+ sourceEditor.addPropertyListener(pcl);
+ sourceEditor.doSaveAs();
+ sourceEditor.removePropertyListener(pcl);
+ try {
+ if (old.isModified())
+ new DiscardFileHandler().executeHandler(old, new Properties());
+ } catch (Exception e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ }
+
+ public void gotoMarker(final IMarker marker) {
+ setActivePage(sourceIndex);
+ pageChange(sourceIndex);
+ IGotoMarker adapter = (IGotoMarker) sourceEditor
+ .getAdapter(IGotoMarker.class);
+ if (adapter != null) {
+ adapter.gotoMarker(marker);
+ }
+ }
+
+ public boolean isSaveAsAllowed() {
+ return sourceEditor.isSaveAsAllowed();
+ }
+
+ public JSPTextEditor getJspEditor() {
+ return sourceEditor;
+ }
+
+ public StructuredTextEditor getSourceEditor() {
+ return sourceEditor;
+ }
+
+ public IVisualEditor getVisualEditor() {
+ return visualEditor;
+ }
+
+ public IEditorPart getActivePageEditor() {
+ return getActiveEditor();
+ }
+
+ protected XModelObject getModelObject() {
+ return object;
+ }
+
+ public void dispose() {
+ saveSelectedTab();
+ XModelObject o = getModelObject();
+ visualEditor.dispose();
+ site.dispose();
+ super.dispose();
+ if (o != null) {
+ o.getModel().removeModelTreeListener(syncListener);
+ }
+ if (syncListener != null)
+ syncListener.dispose();
+ syncListener=null;
+ if (o != null && o.isModified() && o.isActive()) {
+ try {
+ ((FolderImpl) o.getParent()).discardChildFile(o);
+ } catch (Exception e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ }
+ }
+
+ public Object getAdapter(Class adapter) {
+ if (IContentOutlinePage.class.equals(adapter)) {
+ if (osWindows) {
+ if (visualEditor != null) {
+ if (outlinePage == null)
+ outlinePage = (ConfigurableContentOutlinePage) visualEditor
+ .getAdapter(adapter);
+ return outlinePage;
+ }
+ } else {
+ if (sourceEditor != null) {
+ return sourceEditor.getAdapter(adapter);
+ }
+ }
+ } else if (IPropertySheetPage.class.equals(adapter)) {
+ if (sourceEditor != null)
+ return sourceEditor.getAdapter(adapter);
+ } else if (adapter == EditorDescriptor.class)
+ return new EditorDescriptor(new String[] { "jsp", "html" });
+
+ if (sourceEditor != null) {
+ return sourceEditor.getAdapter(adapter);
+ }
+
+ return super.getAdapter(adapter);
+ }
+
+ public void nodeChanged(XModelTreeEvent event) {
+ if (event.getModelObject() == getModelObject()) {
+ setContentDescription(getEditorInput().getName());
+ if (sourceEditor != null)
+ sourceEditor.updateModification();
+ }
+ }
+
+ public void structureChanged(XModelTreeEvent event) {
+ }
+
+ public void close(boolean save) {
+ sourceEditor.close(save);
+ }
+
+ public void doRevertToSaved() {
+ sourceEditor.doRevertToSaved();
+ }
+
+ public IAction getAction(String actionId) {
+ return sourceEditor.getAction(actionId);
+ }
+
+ public IDocumentProvider getDocumentProvider() {
+ return sourceEditor.getDocumentProvider();
+ }
+
+ public IRegion getHighlightRange() {
+ return sourceEditor.getHighlightRange();
+ }
+
+ public ISelectionProvider getSelectionProvider() {
+ return sourceEditor.getSelectionProvider();
+ }
+
+ public boolean isEditable() {
+ return sourceEditor.isEditable();
+ }
+
+ public void removeActionActivationCode(String actionId) {
+ sourceEditor.removeActionActivationCode(actionId);
+ }
+
+ public void resetHighlightRange() {
+ sourceEditor.resetHighlightRange();
+ }
+
+ public void selectAndReveal(int offset, int length) {
+ sourceEditor.selectAndReveal(offset, length);
+ }
+
+ public void setAction(String actionID, IAction action) {
+ sourceEditor.setAction(actionID, action);
+ }
+
+ public void setActionActivationCode(String actionId,
+ char activationCharacter, int activationKeyCode,
+ int activationStateMask) {
+ sourceEditor.setActionActivationCode(actionId, activationCharacter,
+ activationKeyCode, activationStateMask);
+ }
+
+ public void setHighlightRange(int offset, int length, boolean moveCursor) {
+ sourceEditor.setHighlightRange(offset, length, moveCursor);
+ }
+
+ public void showHighlightRangeOnly(boolean showHighlightRangeOnly) {
+ sourceEditor.showHighlightRangeOnly(showHighlightRangeOnly);
+ }
+
+ public boolean showsHighlightRangeOnly() {
+ return sourceEditor.showsHighlightRangeOnly();
+ }
+
+ public VpeTaglibManager getTaglibManager() {
+ if (visualEditor != null) {
+ IVisualController controller = visualEditor.getController();
+ if (controller != null) {
+ IVisualContext context = controller.getPageContext();
+ if (context != null) {
+ return context;
+ }
+ }
+ }
+ return null;
+ }
+
+ void updateTitle() {
+ setPartName(getEditorInput().getName());
+ }
+
+ public void runDropCommand(String flavor, String data) {
+ if (sourceEditor != null)
+ sourceEditor.runDropCommand(flavor, data);
+ }
+
+ public void setStatusField(IStatusField field, String category) {
+ if (sourceEditor != null)
+ sourceEditor.setStatusField(field, category);
+ }
+
+ public boolean isEditorInputReadOnly() {
+ if (sourceEditor != null) {
+ return sourceEditor.isEditorInputReadOnly();
+ }
+ return false;
+ }
+
+ public void addRulerContextMenuListener(IMenuListener listener) {
+ if (sourceEditor != null)
+ sourceEditor.addRulerContextMenuListener(listener);
+ }
+
+ public void removeRulerContextMenuListener(IMenuListener listener) {
+ if (sourceEditor != null)
+ sourceEditor.removeRulerContextMenuListener(listener);
+ }
+
+ public boolean isEditorInputModifiable() {
+ if (sourceEditor != null) {
+ return sourceEditor.isEditorInputModifiable();
+ }
+ return false;
+ }
+
+ public boolean validateEditorInputState() {
+ if (sourceEditor != null) {
+ return sourceEditor.validateEditorInputState();
+ }
+ return false;
+ }
+
+ public InsertMode getInsertMode() {
+ if (sourceEditor != null) {
+ return sourceEditor.getInsertMode();
+ }
+ return null;
+ }
+
+ public void setInsertMode(InsertMode mode) {
+ if (sourceEditor != null)
+ sourceEditor.setInsertMode(mode);
+ }
+
+ public void showChangeInformation(boolean show) {
+ if (sourceEditor != null)
+ sourceEditor.showChangeInformation(show);
+ }
+
+ public boolean isChangeInformationShowing() {
+ if (sourceEditor != null) {
+ return sourceEditor.isChangeInformationShowing();
+ }
+ return false;
+ }
+
+ public INavigationLocation createEmptyNavigationLocation() {
+ if (sourceEditor != null) {
+ return sourceEditor.createEmptyNavigationLocation();
+ }
+ return null;
+ }
+
+ public INavigationLocation createNavigationLocation() {
+ if (sourceEditor != null) {
+ return sourceEditor.createNavigationLocation();
+ }
+ return null;
+ }
+}
+
+class ResourceChangeListener implements IResourceChangeListener {
+ IEditorPart editorPart;
+
+ Composite container;
+
+ ResourceChangeListener(IEditorPart editorPart, Composite container) {
+ this.editorPart = editorPart;
+ this.container = container;
+ IWorkspace workspace = ModelUIPlugin.getWorkspace();
+ if (workspace == null)
+ return;
+ workspace.addResourceChangeListener(this);
+ container.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ IWorkspace workspace = ModelUIPlugin.getWorkspace();
+ if (workspace == null)
+ return;
+ workspace
+ .removeResourceChangeListener(ResourceChangeListener.this);
+ }
+ });
+ }
+
+ public void resourceChanged(IResourceChangeEvent event) {
+ IEditorInput ei = editorPart.getEditorInput();
+ if (!(ei instanceof IFileEditorInput))
+ return;
+ IFileEditorInput fi = (IFileEditorInput) ei;
+ IFile f = fi.getFile();
+ if (f == null)
+ return;
+ IPath path = getPathChange(event, f);
+ if (path == null) {
+ if (f != null && !f.exists())
+ closeEditor();
+ return;
+ }
+ f = ModelPlugin.getWorkspace().getRoot().getFile(path);
+ XModelObject p = f == null ? null : EclipseResourceUtil
+ .getObjectByResource(f.getParent());
+ if (p instanceof FolderImpl) {
+ ((FolderImpl) p).update();
+ }
+ XModelObject o = EclipseResourceUtil.getObjectByResource(f);
+ if (f != null && f.exists() && o != null) {
+ if (editorPart instanceof JSPMultiPageEditor) {
+ JSPMultiPageEditor e = (JSPMultiPageEditor) editorPart;
+ if (ei instanceof XModelObjectEditorInput) {
+ IEditorInput e2 = XModelObjectEditorInput.createInstance(o);
+ e.setInput(e2);
+ e.updateTitle();
+ if (e.sourceEditor instanceof AbstractTextEditor) {
+ if (e.sourceEditor != null
+ && e.sourceEditor.getEditorInput() != e
+ .getEditorInput()) {
+ try {
+ ((AbstractTextEditor) e.sourceEditor)
+ .setInput(e2);
+ } catch (Exception exc) {
+ JspEditorPlugin.getPluginLog().logError(exc);
+ }
+ }
+ ((XModelObjectEditorInput) ei).synchronize();
+ }
+ }
+ }
+ }
+ if (f == null || f.exists())
+ return;
+ closeEditor();
+ }
+
+ private void closeEditor() {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ editorPart.getSite().getPage().closeEditor(editorPart, false);
+ }
+ });
+ }
+
+ private IPath getPathChange(IResourceChangeEvent event, IFile f) {
+ return getPathChange(event.getDelta(), f.getFullPath());
+ }
+
+ private IPath getPathChange(IResourceDelta delta, IPath p) {
+ if (delta == null || delta.getFullPath() == null)
+ return null;
+ if (!delta.getFullPath().isPrefixOf(p))
+ return null;
+ if (delta != null && delta.getKind() == IResourceDelta.CHANGED) {
+ IResourceDelta[] ds = delta.getAffectedChildren();
+ if (ds == null)
+ return null;
+ if (ds.length == 2) {
+ if (ds[1].getKind() == IResourceDelta.REMOVED) {
+ IPath d = ds[1].getFullPath();
+ if (d.equals(p))
+ return ds[0].getFullPath();
+ if (d.isPrefixOf(p)) {
+ return ds[0].getFullPath().append(
+ p.removeFirstSegments(d.segmentCount()));
+ }
+ } else if (ds[0].getKind() == IResourceDelta.REMOVED) {
+ IPath d = ds[0].getFullPath();
+ if (d.equals(p))
+ return ds[1].getFullPath();
+ if (d.isPrefixOf(p)) {
+ return ds[1].getFullPath().append(
+ p.removeFirstSegments(d.segmentCount()));
+ }
+ }
+ }
+ for (int i = 0; i < ds.length; i++) {
+ IPath ps = getPathChange(ds[i], p);
+ if (ps != null)
+ return ps;
+ }
+ }
+ return null;
+ }
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorPart.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorPart.java 2008-02-07
06:15:54 UTC (rev 6142)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorPart.java 2008-02-07
09:57:05 UTC (rev 6143)
@@ -1,328 +1,329 @@
-/*******************************************************************************
- * 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.jst.jsp.jspeditor;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.jface.util.Assert;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.custom.CTabItem;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Item;
-import org.eclipse.ui.IEditorActionBarContributor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.IKeyBindingService;
-import org.eclipse.ui.INestableKeyBindingService;
-import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.part.EditorPart;
-import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
-import org.eclipse.ui.part.MultiPageEditorSite;
-import org.eclipse.ui.part.MultiPageSelectionProvider;
-import org.jboss.tools.common.core.resources.XModelObjectEditorInput;
-
-/**
- *
- */
-public abstract class JSPMultiPageEditorPart extends EditorPart {
-
- private CTabFolder container;
-
- private ArrayList nestedEditors = new ArrayList(3);
-
- protected JSPMultiPageEditorPart() {
- super();
- }
-
- public int addPage(Control control) {
- createItem(control);
- return getPageCount() - 1;
- }
-
- /**
- *
- */
-
- Composite ppp = null;
-
- public int addPage(IEditorPart editor, IEditorInput input)
- throws PartInitException {
- IEditorSite site = createSite(editor);
- editor.init(site, input);
- Composite parent2;
- if (ppp != null) {
- parent2 = ppp;
- } else {
- parent2 = new Composite(getContainer(), SWT.NONE);
- ppp = parent2;
- }
- parent2.setLayout(new FillLayout());
- editor.createPartControl(parent2);
- editor.addPropertyListener(new IPropertyListener() {
- public void propertyChanged(Object source, int propertyId) {
- JSPMultiPageEditorPart.this.handlePropertyChange(propertyId);
- }
- });
- Item item = createItem(parent2);
- item.setData(editor);
- nestedEditors.add(editor);
- return getPageCount() - 1;
- }
-
- /**
- *
- * @param parent
- * @return
- */
- private CTabFolder createContainer(Composite parent) {
- final CTabFolder newContainer = new CTabFolder(parent, SWT.BOTTOM
- | SWT.FLAT);
- newContainer.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- int newPageIndex = newContainer.indexOf((CTabItem) e.item);
- pageChange(newPageIndex);
- }
- });
- return newContainer;
- }
-
- /*
- *
- */
- private CTabItem createItem(Control control) {
- CTabItem item = new CTabItem(getTabFolder(), SWT.NONE);
- item.setControl(control);
- return item;
- }
-
- protected abstract void createPages();
-
- public final void createPartControl(Composite parent) {
- this.container = createContainer(parent);
- createPages();
- // set the active page (page 0 by default), unless it has already been
- // done
- if (getActivePage() == -1)
- setActivePage(0);
- }
-
- protected abstract IEditorSite createSite(IEditorPart editor);
-
- public void dispose() {
- for (int i = 0; i < nestedEditors.size(); ++i) {
- IEditorPart editor = (IEditorPart) nestedEditors.get(i);
- disposePart(editor);
- }
- nestedEditors.clear();
- }
-
- protected IEditorPart getActiveEditor() {
- int index = getActivePage();
- if (index != -1)
- return getEditor(0);
- return null;
- }
-
- protected int getActivePage() {
- CTabFolder tabFolder = getTabFolder();
- if (tabFolder != null && !tabFolder.isDisposed())
- return tabFolder.getSelectionIndex();
- return -1;
- }
-
- protected Composite getContainer() {
- return container;
- }
-
- protected Control getControl(int pageIndex) {
- return getItem(0).getControl();
- }
-
- protected IEditorPart getEditor(int pageIndex) {
- Item item = getItem(pageIndex);
- if (item != null) {
- Object data = item.getData();
- if (data instanceof IEditorPart) {
- return (IEditorPart) data;
- }
- }
- return null;
- }
-
- private CTabItem getItem(int pageIndex) {
- return getTabFolder().getItem(pageIndex);
- }
-
- protected int getPageCount() {
- CTabFolder folder = getTabFolder();
- // May not have been created yet, or may have been disposed.
- if (folder != null && !folder.isDisposed())
- return folder.getItemCount();
- return 0;
- }
-
- protected Image getPageImage(int pageIndex) {
- return getItem(pageIndex).getImage();
- }
-
- protected String getPageText(int pageIndex) {
- return getItem(pageIndex).getText();
- }
-
- protected CTabFolder getTabFolder() {
- return container;
- }
-
- protected void handlePropertyChange(int propertyId) {
- firePropertyChange(propertyId);
- }
-
- public void init(IEditorSite site, IEditorInput input)
- throws PartInitException {
- setSite(site);
- setInput(XModelObjectEditorInput.checkInput(input));
- site.setSelectionProvider(new JSPMultiPageSelectionProvider(this));
- }
-
- public boolean isDirty() {
- // use nestedEditors to avoid SWT requests; see bug 12996
- for (Iterator i = nestedEditors.iterator(); i.hasNext();) {
- IEditorPart editor = (IEditorPart) i.next();
- if (editor.isDirty()) {
- return true;
- }
- }
- return false;
- }
-
- protected void pageChange(int newPageIndex) {
- Control control = getControl(newPageIndex);
- if (control != null) {
- control.setVisible(true);
- }
-
- setFocus();
- IEditorPart activeEditor = getEditor(newPageIndex);
- IEditorActionBarContributor contributor = getEditorSite()
- .getActionBarContributor();
- if (contributor != null
- && contributor instanceof MultiPageEditorActionBarContributor) {
- ((MultiPageEditorActionBarContributor) contributor)
- .setActivePage(activeEditor);
- }
- if (activeEditor != null) {
- ISelectionProvider selectionProvider = activeEditor.getSite()
- .getSelectionProvider();
- if (selectionProvider != null) {
- SelectionChangedEvent event = new SelectionChangedEvent(
- selectionProvider, selectionProvider.getSelection());
- ((MultiPageSelectionProvider) getSite().getSelectionProvider())
- .fireSelectionChanged(event);
- }
- }
- }
-
- private void disposePart(final IWorkbenchPart part) {
- SafeRunner.run(new SafeRunnable() {
- public void run() {
- if (part.getSite() instanceof MultiPageEditorSite) {
- MultiPageEditorSite partSite = (MultiPageEditorSite) part
- .getSite();
- partSite.dispose();
- }
- part.dispose();
- }
-
- public void handleException(Throwable e) {
- }
- });
- }
-
- public void removePage(int pageIndex) {
- Assert.isTrue(pageIndex >= 0 && pageIndex < getPageCount());
- IEditorPart editor = getEditor(pageIndex);
- getItem(pageIndex).dispose();
- if (editor != null) {
- nestedEditors.remove(editor);
- disposePart(editor);
- }
- }
-
- protected void setActivePage(int pageIndex) {
- Assert.isTrue(pageIndex >= 0 && pageIndex < getPageCount());
- getTabFolder().setSelection(pageIndex);
- }
-
- protected void setControl(int pageIndex, Control control) {
- getItem(pageIndex).setControl(control);
- }
-
- public void setFocus() {
- setFocus(getActivePage());
- }
-
- private void setFocus(int pageIndex) {
- final IKeyBindingService service = getSite().getKeyBindingService();
- if (pageIndex < 0 || pageIndex >= getPageCount()) {
- if (service instanceof INestableKeyBindingService) {
- final INestableKeyBindingService nestableService = (INestableKeyBindingService)
service;
- nestableService.activateKeyBindingService(null);
- }
- return;
- }
-
- IEditorPart editor = getEditor(pageIndex);
- if (editor != null) {
- editor.setFocus();
- if (service instanceof INestableKeyBindingService) {
- INestableKeyBindingService nestableService = (INestableKeyBindingService) service;
- if (editor != null) {
- nestableService.activateKeyBindingService(editor
- .getEditorSite());
- } else {
- nestableService.activateKeyBindingService(null);
- }
- }
- } else {
- if (service instanceof INestableKeyBindingService) {
- INestableKeyBindingService nestableService = (INestableKeyBindingService) service;
- nestableService.activateKeyBindingService(null);
- }
-
- Control control = getControl(pageIndex);
- if (control != null) {
- control.setFocus();
- }
- }
- }
-
- protected void setPageImage(int pageIndex, Image image) {
- getItem(pageIndex).setImage(image);
- }
-
- protected void setPageText(int pageIndex, String text) {
- getItem(pageIndex).setText(text);
- }
-}
+/*******************************************************************************
+ * 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.jst.jsp.jspeditor;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Item;
+import org.eclipse.ui.IEditorActionBarContributor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IKeyBindingService;
+import org.eclipse.ui.INestableKeyBindingService;
+import org.eclipse.ui.IPropertyListener;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.EditorPart;
+import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
+import org.eclipse.ui.part.MultiPageEditorSite;
+import org.eclipse.ui.part.MultiPageSelectionProvider;
+import org.jboss.tools.common.core.resources.XModelObjectEditorInput;
+
+/**
+ *
+ */
+public abstract class JSPMultiPageEditorPart extends EditorPart {
+
+ private CTabFolder container;
+
+ private ArrayList nestedEditors = new ArrayList(3);
+
+ protected JSPMultiPageEditorPart() {
+ super();
+ }
+
+ public int addPage(Control control) {
+ createItem(control);
+ return getPageCount() - 1;
+ }
+
+ /**
+ *
+ */
+
+ Composite ppp = null;
+
+ public int addPage(IEditorPart editor, IEditorInput input)
+ throws PartInitException {
+ Composite parent2;
+ if (ppp == null) {
+ IEditorSite site = createSite(editor);
+ editor.init(site, input);
+ parent2 = new Composite(getContainer(), SWT.NONE);
+ ppp = parent2;
+ parent2.setLayout(new FillLayout());
+ editor.createPartControl(parent2);
+ editor.addPropertyListener(new IPropertyListener() {
+ public void propertyChanged(Object source, int propertyId) {
+ JSPMultiPageEditorPart.this
+ .handlePropertyChange(propertyId);
+ }
+ });
+ } else {
+ parent2 = ppp;
+ }
+ Item item = createItem(parent2);
+ item.setData(editor);
+ nestedEditors.add(editor);
+ return getPageCount() - 1;
+ }
+
+ /**
+ *
+ * @param parent
+ * @return
+ */
+ private CTabFolder createContainer(Composite parent) {
+ final CTabFolder newContainer = new CTabFolder(parent, SWT.BOTTOM
+ | SWT.FLAT);
+ newContainer.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ int newPageIndex = newContainer.indexOf((CTabItem) e.item);
+ pageChange(newPageIndex);
+ }
+ });
+ return newContainer;
+ }
+
+ /*
+ *
+ */
+ private CTabItem createItem(Control control) {
+ CTabItem item = new CTabItem(getTabFolder(), SWT.NONE);
+ item.setControl(control);
+ return item;
+ }
+
+ protected abstract void createPages();
+
+ public final void createPartControl(Composite parent) {
+ this.container = createContainer(parent);
+ createPages();
+ // set the active page (page 0 by default), unless it has already been
+ // done
+ if (getActivePage() == -1)
+ setActivePage(0);
+ }
+
+ protected abstract IEditorSite createSite(IEditorPart editor);
+
+ public void dispose() {
+ for (int i = 0; i < nestedEditors.size(); ++i) {
+ IEditorPart editor = (IEditorPart) nestedEditors.get(i);
+ disposePart(editor);
+ }
+ nestedEditors.clear();
+ }
+
+ protected IEditorPart getActiveEditor() {
+ int index = getActivePage();
+ if (index != -1)
+ return getEditor(0);
+ return null;
+ }
+
+ protected int getActivePage() {
+ CTabFolder tabFolder = getTabFolder();
+ if (tabFolder != null && !tabFolder.isDisposed())
+ return tabFolder.getSelectionIndex();
+ return -1;
+ }
+
+ protected Composite getContainer() {
+ return container;
+ }
+
+ protected Control getControl(int pageIndex) {
+ return getItem(0).getControl();
+ }
+
+ protected IEditorPart getEditor(int pageIndex) {
+ Item item = getItem(pageIndex);
+ if (item != null) {
+ Object data = item.getData();
+ if (data instanceof IEditorPart) {
+ return (IEditorPart) data;
+ }
+ }
+ return null;
+ }
+
+ private CTabItem getItem(int pageIndex) {
+ return getTabFolder().getItem(pageIndex);
+ }
+
+ protected int getPageCount() {
+ CTabFolder folder = getTabFolder();
+ // May not have been created yet, or may have been disposed.
+ if (folder != null && !folder.isDisposed())
+ return folder.getItemCount();
+ return 0;
+ }
+
+ protected Image getPageImage(int pageIndex) {
+ return getItem(pageIndex).getImage();
+ }
+
+ protected String getPageText(int pageIndex) {
+ return getItem(pageIndex).getText();
+ }
+
+ protected CTabFolder getTabFolder() {
+ return container;
+ }
+
+ protected void handlePropertyChange(int propertyId) {
+ firePropertyChange(propertyId);
+ }
+
+ public void init(IEditorSite site, IEditorInput input)
+ throws PartInitException {
+ setSite(site);
+ setInput(XModelObjectEditorInput.checkInput(input));
+ site.setSelectionProvider(new JSPMultiPageSelectionProvider(this));
+ }
+
+ public boolean isDirty() {
+ // use nestedEditors to avoid SWT requests; see bug 12996
+ for (Iterator i = nestedEditors.iterator(); i.hasNext();) {
+ IEditorPart editor = (IEditorPart) i.next();
+ if (editor.isDirty()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected void pageChange(int newPageIndex) {
+ Control control = getControl(newPageIndex);
+ if (control != null) {
+ control.setVisible(true);
+ }
+
+ setFocus();
+ IEditorPart activeEditor = getEditor(newPageIndex);
+ IEditorActionBarContributor contributor = getEditorSite()
+ .getActionBarContributor();
+ if (contributor != null
+ && contributor instanceof MultiPageEditorActionBarContributor) {
+ ((MultiPageEditorActionBarContributor) contributor)
+ .setActivePage(activeEditor);
+ }
+ if (activeEditor != null) {
+ ISelectionProvider selectionProvider = activeEditor.getSite()
+ .getSelectionProvider();
+ if (selectionProvider != null) {
+ SelectionChangedEvent event = new SelectionChangedEvent(
+ selectionProvider, selectionProvider.getSelection());
+ ((MultiPageSelectionProvider) getSite().getSelectionProvider())
+ .fireSelectionChanged(event);
+ }
+ }
+ }
+
+ private void disposePart(final IWorkbenchPart part) {
+ SafeRunner.run(new SafeRunnable() {
+ public void run() {
+ if (part.getSite() instanceof MultiPageEditorSite) {
+ MultiPageEditorSite partSite = (MultiPageEditorSite) part
+ .getSite();
+ partSite.dispose();
+ }
+ part.dispose();
+ }
+
+ public void handleException(Throwable e) {
+ }
+ });
+ }
+
+ public void removePage(int pageIndex) {
+ Assert.isTrue(pageIndex >= 0 && pageIndex < getPageCount());
+ IEditorPart editor = getEditor(pageIndex);
+ getItem(pageIndex).dispose();
+ if (editor != null) {
+ nestedEditors.remove(editor);
+ disposePart(editor);
+ }
+ }
+
+ protected void setActivePage(int pageIndex) {
+ Assert.isTrue(pageIndex >= 0 && pageIndex < getPageCount());
+ getTabFolder().setSelection(pageIndex);
+ }
+
+ protected void setControl(int pageIndex, Control control) {
+ getItem(pageIndex).setControl(control);
+ }
+
+ public void setFocus() {
+ setFocus(getActivePage());
+ }
+
+ private void setFocus(int pageIndex) {
+ final IKeyBindingService service = getSite().getKeyBindingService();
+ if (pageIndex < 0 || pageIndex >= getPageCount()) {
+ if (service instanceof INestableKeyBindingService) {
+ final INestableKeyBindingService nestableService = (INestableKeyBindingService)
service;
+ nestableService.activateKeyBindingService(null);
+ }
+ return;
+ }
+
+ IEditorPart editor = getEditor(pageIndex);
+ if (editor != null) {
+ editor.setFocus();
+ if (service instanceof INestableKeyBindingService) {
+ INestableKeyBindingService nestableService = (INestableKeyBindingService) service;
+ if (editor != null) {
+ nestableService.activateKeyBindingService(editor
+ .getEditorSite());
+ } else {
+ nestableService.activateKeyBindingService(null);
+ }
+ }
+ } else {
+ if (service instanceof INestableKeyBindingService) {
+ INestableKeyBindingService nestableService = (INestableKeyBindingService) service;
+ nestableService.activateKeyBindingService(null);
+ }
+
+ Control control = getControl(pageIndex);
+ if (control != null) {
+ control.setFocus();
+ }
+ }
+ }
+
+ protected void setPageImage(int pageIndex, Image image) {
+ getItem(pageIndex).setImage(image);
+ }
+
+ protected void setPageText(int pageIndex, String text) {
+ getItem(pageIndex).setText(text);
+ }
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorSite.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorSite.java 2008-02-07
06:15:54 UTC (rev 6142)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorSite.java 2008-02-07
09:57:05 UTC (rev 6143)
@@ -1,216 +1,222 @@
-/*******************************************************************************
- * 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.jst.jsp.jspeditor;
-
-import java.util.ArrayList;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.util.Assert;
-import org.eclipse.jface.viewers.ILabelDecorator;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jst.jsp.core.internal.provisional.contenttype.ContentTypeIdForJSP;
-
-import org.eclipse.ui.*;
-import org.eclipse.ui.internal.PopupMenuExtender;
-import org.eclipse.ui.internal.WorkbenchPlugin;
-
-/**
- *
- * @author eskimo(dgolovin(a)exadel.com)
- *
- */
-public abstract class JSPMultiPageEditorSite implements IEditorSite {
-
- private IEditorPart fEditorPart;
-
- private JSPMultiPageEditorPart fEditor;
-
- private ISelectionChangedListener fSelChangeListener = null;
-
- private IKeyBindingService fParentService = null;
-
- private IKeyBindingService fService = null;
-
- private ArrayList fMenuExts;
-
- public JSPMultiPageEditorSite(JSPMultiPageEditorPart multiPageEditor,
- IEditorPart editor) {
- Assert.isNotNull(multiPageEditor);
- Assert.isNotNull(editor);
- this.fEditor = multiPageEditor;
- this.fEditorPart = editor;
- }
-
- public void dispose() {
- if (fMenuExts != null) {
- for (int i = 0; i < fMenuExts.size(); i++) {
- ((PopupMenuExtender) fMenuExts.get(i)).dispose();
- }
- fMenuExts = null;
- }
-
- if (fService != null) {
- IKeyBindingService parentService = getEditor().getSite()
- .getKeyBindingService();
- if (parentService instanceof INestableKeyBindingService) {
- INestableKeyBindingService nestableParent = (INestableKeyBindingService)
parentService;
- nestableParent.removeKeyBindingService(this);
- }
- fService = null;
- }
- }
-
- public IEditorActionBarContributor getActionBarContributor() {
- return null;
- }
-
- public IActionBars getActionBars() {
- return fEditor.getEditorSite().getActionBars();
- }
-
- public ILabelDecorator getDecoratorManager() {
- return getWorkbenchWindow().getWorkbench().getDecoratorManager()
- .getLabelDecorator();
- }
-
- public IEditorPart getEditor() {
- return fEditorPart;
- }
-
- public String getId() {
- return ContentTypeIdForJSP.ContentTypeID_JSP + ".source"; //$NON-NLS-1$;
- }
-
- public IKeyBindingService getKeyBindingService() {
- if (fService == null) {
- fService = getMultiPageEditor().getEditorSite()
- .getKeyBindingService();
- fParentService = fService;
- if (fService instanceof INestableKeyBindingService) {
- INestableKeyBindingService nestableService = (INestableKeyBindingService) fService;
- fService = nestableService.getKeyBindingService(this);
-
- } else {
- WorkbenchPlugin
- .log("MultiPageEditorSite.getKeyBindingService() Parent key binding fService
was not an instance of INestableKeyBindingService. It was an instance of " +
fService.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- return fParentService;
- }
-
- public JSPMultiPageEditorPart getMultiPageEditor() {
- return fEditor;
- }
-
- public IWorkbenchPage getPage() {
- return getMultiPageEditor().getSite().getPage();
- }
-
- public String getPluginId() {
- return "";
- }
-
- public String getRegisteredName() {
- return "";
- }
-
- protected ISelectionChangedListener getSelectionChangedListener() {
- if (fSelChangeListener == null) {
- fSelChangeListener = new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- JSPMultiPageEditorSite.this.handleSelectionChanged(event);
- }
- };
- }
- return fSelChangeListener;
- }
-
- public Shell getShell() {
- return getMultiPageEditor().getSite().getShell();
- }
-
- public IWorkbenchWindow getWorkbenchWindow() {
- return getMultiPageEditor().getSite().getWorkbenchWindow();
- }
-
- protected void handleSelectionChanged(SelectionChangedEvent event) {
- ISelectionProvider parentProvider = getMultiPageEditor().getSite()
- .getSelectionProvider();
- if (parentProvider instanceof JSPMultiPageSelectionProvider) {
- SelectionChangedEvent newEvent = new SelectionChangedEvent(
- parentProvider, event.getSelection());
- ((JSPMultiPageSelectionProvider) parentProvider)
- .fireSelectionChanged(newEvent);
- }
- }
-
- public void registerContextMenu(String menuID, MenuManager menuMgr,
- ISelectionProvider selProvider) {
- if (fMenuExts == null) {
- fMenuExts = new ArrayList(1);
- }
- if (findMenuExtender(menuMgr, selProvider) == null) {
- PopupMenuExtender extender = new PopupMenuExtender(menuID, menuMgr,
- selProvider, fEditorPart);
- fMenuExts.add(extender);
- }
- }
-
- private PopupMenuExtender findMenuExtender(MenuManager menuMgr,
- ISelectionProvider selProvider) {
- for (int i = 0; fMenuExts != null && i < fMenuExts.size(); i++) {
- PopupMenuExtender extender = (PopupMenuExtender) fMenuExts
- .get(i);
- if (extender.matches(menuMgr, selProvider, fEditorPart))
- return extender;
- }
- return null;
- }
-
- public void registerContextMenu(MenuManager menuManager,
- ISelectionProvider selProvider) {
- getMultiPageEditor().getSite().registerContextMenu(menuManager,
- selProvider);
- }
-
- public void progressEnd(Job job) {
- }
-
- public void progressStart(Job job) {
- }
-
- public Object getAdapter(Class adapter) {
- return null;
- }
-
- public IWorkbenchPart getPart() {
- return null;
- }
-
- public final void registerContextMenu(final MenuManager menuManager,
- final ISelectionProvider selectionProvider,
- final boolean includeEditorInput) {
- registerContextMenu(getId(), menuManager, selectionProvider,
- includeEditorInput);
- }
-
- public final void registerContextMenu(final String menuId,
- final MenuManager menuManager,
- final ISelectionProvider selectionProvider,
- final boolean includeEditorInput) {
- if (fMenuExts == null) {
- fMenuExts = new ArrayList(1);
- }
- }
-}
+/*******************************************************************************
+ * 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.jst.jsp.jspeditor;
+
+import java.util.ArrayList;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.ILabelDecorator;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jst.jsp.core.internal.provisional.contenttype.ContentTypeIdForJSP;
+
+import org.eclipse.ui.*;
+import org.eclipse.ui.internal.PopupMenuExtender;
+import org.eclipse.ui.internal.WorkbenchPlugin;
+
+/**
+ *
+ * @author eskimo(dgolovin(a)exadel.com)
+ *
+ */
+public abstract class JSPMultiPageEditorSite implements IEditorSite {
+
+ private IEditorPart fEditorPart;
+
+ private JSPMultiPageEditorPart fEditor;
+
+ private ISelectionChangedListener fSelChangeListener = null;
+
+ private IKeyBindingService fParentService = null;
+
+ private IKeyBindingService fService = null;
+
+ private ArrayList fMenuExts;
+
+ public JSPMultiPageEditorSite(JSPMultiPageEditorPart multiPageEditor,
+ IEditorPart editor) {
+ Assert.isNotNull(multiPageEditor);
+ Assert.isNotNull(editor);
+ this.fEditor = multiPageEditor;
+ this.fEditorPart = editor;
+ }
+
+ public void dispose() {
+ if (fMenuExts != null) {
+ for (int i = 0; i < fMenuExts.size(); i++) {
+ ((PopupMenuExtender) fMenuExts.get(i)).dispose();
+ }
+ fMenuExts = null;
+ }
+
+ if (fService != null) {
+ IKeyBindingService parentService = getEditor().getSite()
+ .getKeyBindingService();
+ if (parentService instanceof INestableKeyBindingService) {
+ INestableKeyBindingService nestableParent = (INestableKeyBindingService)
parentService;
+ nestableParent.removeKeyBindingService(this);
+ }
+ fService = null;
+ }
+ fEditor = null;
+ fEditorPart = null;
+ if (fSelChangeListener != null) {
+ getSelectionProvider().removeSelectionChangedListener(fSelChangeListener);
+ fSelChangeListener = null;
+ }
+ }
+
+ public IEditorActionBarContributor getActionBarContributor() {
+ return null;
+ }
+
+ public IActionBars getActionBars() {
+ return fEditor.getEditorSite().getActionBars();
+ }
+
+ public ILabelDecorator getDecoratorManager() {
+ return getWorkbenchWindow().getWorkbench().getDecoratorManager()
+ .getLabelDecorator();
+ }
+
+ public IEditorPart getEditor() {
+ return fEditorPart;
+ }
+
+ public String getId() {
+ return ContentTypeIdForJSP.ContentTypeID_JSP + ".source"; //$NON-NLS-1$;
+ }
+
+ public IKeyBindingService getKeyBindingService() {
+ if (fService == null) {
+ fService = getMultiPageEditor().getEditorSite()
+ .getKeyBindingService();
+ fParentService = fService;
+ if (fService instanceof INestableKeyBindingService) {
+ INestableKeyBindingService nestableService = (INestableKeyBindingService) fService;
+ fService = nestableService.getKeyBindingService(this);
+
+ } else {
+ WorkbenchPlugin
+ .log("MultiPageEditorSite.getKeyBindingService() Parent key binding fService
was not an instance of INestableKeyBindingService. It was an instance of " +
fService.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ return fParentService;
+ }
+
+ public JSPMultiPageEditorPart getMultiPageEditor() {
+ return fEditor;
+ }
+
+ public IWorkbenchPage getPage() {
+ return getMultiPageEditor().getSite().getPage();
+ }
+
+ public String getPluginId() {
+ return "";
+ }
+
+ public String getRegisteredName() {
+ return "";
+ }
+
+ protected ISelectionChangedListener getSelectionChangedListener() {
+ if (fSelChangeListener == null) {
+ fSelChangeListener = new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ JSPMultiPageEditorSite.this.handleSelectionChanged(event);
+ }
+ };
+ }
+ return fSelChangeListener;
+ }
+
+ public Shell getShell() {
+ return getMultiPageEditor().getSite().getShell();
+ }
+
+ public IWorkbenchWindow getWorkbenchWindow() {
+ return getMultiPageEditor().getSite().getWorkbenchWindow();
+ }
+
+ protected void handleSelectionChanged(SelectionChangedEvent event) {
+ ISelectionProvider parentProvider = getMultiPageEditor().getSite()
+ .getSelectionProvider();
+ if (parentProvider instanceof JSPMultiPageSelectionProvider) {
+ SelectionChangedEvent newEvent = new SelectionChangedEvent(
+ parentProvider, event.getSelection());
+ ((JSPMultiPageSelectionProvider) parentProvider)
+ .fireSelectionChanged(newEvent);
+ }
+ }
+
+ public void registerContextMenu(String menuID, MenuManager menuMgr,
+ ISelectionProvider selProvider) {
+ if (fMenuExts == null) {
+ fMenuExts = new ArrayList(1);
+ }
+ if (findMenuExtender(menuMgr, selProvider) == null) {
+ PopupMenuExtender extender = new PopupMenuExtender(menuID, menuMgr,
+ selProvider, fEditorPart);
+ fMenuExts.add(extender);
+ }
+ }
+
+ private PopupMenuExtender findMenuExtender(MenuManager menuMgr,
+ ISelectionProvider selProvider) {
+ for (int i = 0; fMenuExts != null && i < fMenuExts.size(); i++) {
+ PopupMenuExtender extender = (PopupMenuExtender) fMenuExts
+ .get(i);
+ if (extender.matches(menuMgr, selProvider, fEditorPart))
+ return extender;
+ }
+ return null;
+ }
+
+ public void registerContextMenu(MenuManager menuManager,
+ ISelectionProvider selProvider) {
+ getMultiPageEditor().getSite().registerContextMenu(menuManager,
+ selProvider);
+ }
+
+ public void progressEnd(Job job) {
+ }
+
+ public void progressStart(Job job) {
+ }
+
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+
+ public IWorkbenchPart getPart() {
+ return null;
+ }
+
+ public final void registerContextMenu(final MenuManager menuManager,
+ final ISelectionProvider selectionProvider,
+ final boolean includeEditorInput) {
+ registerContextMenu(getId(), menuManager, selectionProvider,
+ includeEditorInput);
+ }
+
+ public final void registerContextMenu(final String menuId,
+ final MenuManager menuManager,
+ final ISelectionProvider selectionProvider,
+ final boolean includeEditorInput) {
+ if (fMenuExts == null) {
+ fMenuExts = new ArrayList(1);
+ }
+ }
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java 2008-02-07
06:15:54 UTC (rev 6142)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java 2008-02-07
09:57:05 UTC (rev 6143)
@@ -1,1133 +1,1158 @@
-/*******************************************************************************
- * 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.jst.jsp.jspeditor;
-
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Properties;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextListener;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.TextEvent;
-import org.eclipse.jface.text.formatter.IContentFormatter;
-import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.jface.text.source.IOverviewRuler;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.IVerticalRuler;
-import org.eclipse.jface.text.source.SourceViewerConfiguration;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP;
-import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.dnd.DND;
-import org.eclipse.swt.dnd.DragSource;
-import org.eclipse.swt.dnd.DropTarget;
-import org.eclipse.swt.dnd.DropTargetAdapter;
-import org.eclipse.swt.dnd.DropTargetEvent;
-import org.eclipse.swt.dnd.DropTargetListener;
-import org.eclipse.swt.dnd.FileTransfer;
-import org.eclipse.swt.dnd.HTMLTransfer;
-import org.eclipse.swt.dnd.TextTransfer;
-import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.events.FocusAdapter;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.editors.text.ILocationProvider;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.ui.texteditor.ITextEditorActionConstants;
-import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
-import org.eclipse.ui.views.properties.IPropertySheetPage;
-import org.eclipse.ui.views.properties.PropertySheetPage;
-import org.eclipse.ui.views.properties.PropertySheetSorter;
-import org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.ui.StructuredTextEditor;
-import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration;
-import org.eclipse.wst.sse.ui.internal.IModelProvider;
-import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
-import org.eclipse.wst.sse.ui.internal.actions.StructuredTextEditorActionConstants;
-import org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage;
-import org.eclipse.wst.sse.ui.internal.properties.ConfigurablePropertySheetPage;
-import
org.eclipse.wst.sse.ui.internal.provisional.extensions.ConfigurationPointCalculator;
-import org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration;
-import org.eclipse.wst.xml.core.internal.document.AttrImpl;
-import org.eclipse.wst.xml.core.internal.document.ElementImpl;
-import org.jboss.tools.common.core.resources.XModelObjectEditorInput;
-import org.jboss.tools.common.meta.action.XActionInvoker;
-import org.jboss.tools.common.model.XModelBuffer;
-import org.jboss.tools.common.model.XModelObject;
-import org.jboss.tools.common.model.XModelTransferBuffer;
-import org.jboss.tools.common.model.filesystems.impl.FileAnyImpl;
-import org.jboss.tools.common.model.filesystems.impl.FolderImpl;
-import org.jboss.tools.common.model.ui.ModelUIPlugin;
-import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
-import org.jboss.tools.common.model.ui.editor.IModelObjectEditorInput;
-import org.jboss.tools.common.model.ui.editors.dnd.DropCommandFactory;
-import org.jboss.tools.common.model.ui.editors.dnd.DropData;
-import org.jboss.tools.common.model.ui.editors.dnd.IDropCommand;
-import org.jboss.tools.common.model.ui.editors.dnd.JSPTagProposalFactory;
-import org.jboss.tools.common.model.ui.editors.dnd.context.DropContext;
-import org.jboss.tools.common.model.ui.editors.dnd.context.InnerDragBuffer;
-import org.jboss.tools.common.model.ui.texteditors.TextMerge;
-import org.jboss.tools.common.model.ui.texteditors.dnd.TextEditorDrop;
-import org.jboss.tools.common.model.ui.texteditors.dnd.TextEditorDropProvider;
-import org.jboss.tools.common.model.ui.views.palette.IIgnoreSelection;
-import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
-import org.jboss.tools.common.model.util.XModelObjectLoaderUtil;
-import org.jboss.tools.common.text.xml.IOccurrencePreferenceProvider;
-import org.jboss.tools.common.text.xml.XmlEditorPlugin;
-import org.jboss.tools.common.text.xml.ui.FreeCaretStyledText;
-import org.jboss.tools.jst.jsp.ExtendedStructuredTextViewerConfigurationHTML;
-import org.jboss.tools.jst.jsp.ExtendedStructuredTextViewerConfigurationJSP;
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.jboss.tools.jst.jsp.editor.IJSPTextEditor;
-import org.jboss.tools.jst.jsp.editor.ITextFormatter;
-import org.jboss.tools.jst.jsp.editor.IVisualController;
-import org.jboss.tools.jst.jsp.outline.JSPContentOutlineConfiguration;
-import org.jboss.tools.jst.jsp.outline.JSPPropertySheetConfiguration;
-import org.jboss.tools.jst.jsp.preferences.VpePreference;
-import org.jboss.tools.jst.jsp.support.kb.WTPTextJspKbConnector;
-import org.jboss.tools.jst.jsp.text.xpl.IStructuredTextOccurrenceStructureProvider;
-import
org.jboss.tools.jst.jsp.text.xpl.StructuredTextOccurrenceStructureProviderRegistry;
-import org.jboss.tools.jst.jsp.ui.action.ExtendedFormatAction;
-import org.jboss.tools.jst.jsp.ui.action.IExtendedAction;
-import org.jboss.tools.jst.web.tld.VpeTaglibManager;
-import org.jboss.tools.jst.web.tld.VpeTaglibManagerProvider;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-
-/**
- * @author Jeremy
- *
- */
-public class JSPTextEditor extends StructuredTextEditor implements
- ITextListener, IJSPTextEditor, ITextFormatter,
- IOccurrencePreferenceProvider {
- private IStructuredTextOccurrenceStructureProvider fOccurrenceModelUpdater;
-
- TextEditorDrop dnd = new TextEditorDrop();
-
- JSPMultiPageEditor parentEditor;
-
- long timeStamp = -1;
-
- long savedTimeStamp = -1;
-
- IVisualController vpeController;
-
- public JSPTextEditor(JSPMultiPageEditor parentEditor) {
- JspEditorPlugin.getDefault().initDefaultPluginPreferences();
- dnd.setTextEditorDropProvider(new TextEditorDropProviderImpl());
- this.parentEditor = parentEditor;
- super
- .setSourceViewerConfiguration(new ExtendedStructuredTextViewerConfigurationJSP());
- }
-
- protected void setSourceViewerConfiguration(SourceViewerConfiguration config) {
- if (config instanceof StructuredTextViewerConfigurationJSP) {
- if (!(config instanceof ExtendedStructuredTextViewerConfigurationJSP)) {
- config = new ExtendedStructuredTextViewerConfigurationJSP();
- }
- } else if (config instanceof StructuredTextViewerConfigurationHTML) {
- if (!(config instanceof ExtendedStructuredTextViewerConfigurationHTML)) {
- config = new ExtendedStructuredTextViewerConfigurationHTML();
- }
- } else {
- config = new ExtendedStructuredTextViewerConfigurationJSP();
- }
- super.setSourceViewerConfiguration(config);
- }
-
- protected void initializeDrop(ITextViewer textViewer) {
-
- Composite c = textViewer.getTextWidget();
- Label l = new Label(c, SWT.NONE);
- l.dispose();
- }
-
- private ConfigurableContentOutlinePage fOutlinePage = null;
-
- private OutlinePageListener fOutlinePageListener = null;
-
- private IPropertySheetPage fPropertySheetPage;
-
- public Object getAdapter(Class adapter) {
- if (ISourceViewer.class.equals(adapter)) {
- return JSPTextEditor.this.getSourceViewer();
- } else if (IContentOutlinePage.class.equals(adapter)) {
- if (fOutlinePage == null || fOutlinePage.getControl() == null
- || fOutlinePage.getControl().isDisposed()) {
- IStructuredModel internalModel = getModel();
- ContentOutlineConfiguration cfg = new JSPContentOutlineConfiguration(
- this);
- if (cfg != null) {
- ConfigurableContentOutlinePage outlinePage = new ConfigurableContentOutlinePage();
- outlinePage.setConfiguration(cfg);
- if (internalModel != null) {
- outlinePage.setInputContentTypeIdentifier(internalModel
- .getContentTypeIdentifier());
- outlinePage.setInput(internalModel);
- }
-
- if (fOutlinePageListener == null) {
- fOutlinePageListener = new OutlinePageListener();
- }
-
- outlinePage
- .addSelectionChangedListener(fOutlinePageListener);
- outlinePage.addDoubleClickListener(fOutlinePageListener);
-
- fOutlinePage = outlinePage;
- }
- }
- return fOutlinePage;
- } else if (IPropertySheetPage.class == adapter) {
- if (fPropertySheetPage == null
- || fPropertySheetPage.getControl() == null
- || fPropertySheetPage.getControl().isDisposed()) {
- JSPPropertySheetConfiguration cfg = new JSPPropertySheetConfiguration();
- if (cfg != null) {
- ConfigurablePropertySheetPage propertySheetPage = new
ConfigurablePropertySheetPage();
- propertySheetPage.setConfiguration(cfg);
- fPropertySheetPage = propertySheetPage;
- setSorter(cfg.getSorter(), propertySheetPage);
- }
- }
- return fPropertySheetPage;
- }
- return super.getAdapter(adapter);
- }
-
- private void setSorter(PropertySheetSorter sorter,
- ConfigurablePropertySheetPage sheet) {
- try {
- Method method = PropertySheetPage.class.getDeclaredMethod(
- "setSorter", new Class[] { PropertySheetSorter.class });
- method.setAccessible(true);
- method.invoke(sheet, new Object[] { sorter });
- } catch (Exception e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- }
-
- public String getEditorId() {
- return JSPUIPlugin.ID;
- }
-
- public IStructuredTextOccurrenceStructureProvider getOccurrencePreferenceProvider() {
- return fOccurrenceModelUpdater;
- }
-
- public void createPartControl(Composite parent) {
- super.createPartControl(parent);
-
- StructuredTextOccurrenceStructureProviderRegistry registry = XmlEditorPlugin
- .getDefault().getOccurrenceStructureProviderRegistry(
- JspEditorPlugin.PLUGIN_ID);
- fOccurrenceModelUpdater = registry
- .getCurrentOccurrenceProvider(JspEditorPlugin.PLUGIN_ID);
-
- if (fOccurrenceModelUpdater != null)
- fOccurrenceModelUpdater.install(this, getTextViewer());
-
- installActivePropmtSupport();
-
- createDrop();
- setModified(false);
- getSourceViewer().removeTextListener(this);
- getSourceViewer().addTextListener(this);
-
- Object dtid = getSourceViewer().getTextWidget().getData("DropTarget");
- if (dtid != null) {
- if (dtid instanceof DropTarget) {
- DropTarget dropTarget = (DropTarget) dtid;
- dropTarget.addDropListener(new DropTargetAdapter() {
- private FreeCaretStyledText getFreeCaretControl(
- Object sourceOrTarget) {
- if (sourceOrTarget == null)
- return null;
-
- Object control = null;
-
- if (sourceOrTarget instanceof DropTarget) {
- control = ((DropTarget) sourceOrTarget)
- .getControl();
- } else if (sourceOrTarget instanceof DragSource) {
- control = ((DragSource) sourceOrTarget)
- .getControl();
- } else
- return null;
-
- if (control instanceof FreeCaretStyledText)
- return (FreeCaretStyledText) control;
- return null;
- }
-
- private int getPosition(StyledText t, int x, int y) {
- try {
- Point pp = t.toControl(x, y);
- x = pp.x;
- y = pp.y;
- int lineIndex = (t.getTopPixel() + y)
- / t.getLineHeight();
- if (lineIndex >= t.getLineCount()) {
- return t.getCharCount();
- } else {
- int c = 0;
- try {
- c = t.getOffsetAtLocation(new Point(x, y));
- if (c < 0)
- c = 0;
- } catch (Exception ex) {
- c = t.getOffsetAtLine(lineIndex + 1)
- - (t.getLineDelimiter() == null ? 0
- : t.getLineDelimiter()
- .length());
- }
- return c;
- }
- } catch (Exception e) {
- return 0;
- }
- }
-
- public void dragEnter(DropTargetEvent event) {
- getFreeCaretControl(event.widget).enableFreeCaret(true);
- }
-
- public void dragLeave(DropTargetEvent event) {
- getFreeCaretControl(event.widget).enableFreeCaret(false);
- }
-
- public void dragOperationChanged(DropTargetEvent event) {
- getFreeCaretControl(event.widget).enableFreeCaret(false);
- }
-
- public void dragOver(DropTargetEvent event) {
- FreeCaretStyledText fcst = getFreeCaretControl(event.widget);
- int pos = getPosition(fcst, event.x, event.y);
- Point p = fcst.getLocationAtOffset(pos);
- fcst.myRedraw(p.x, p.y);
- }
-
- public void drop(DropTargetEvent event) {
- getFreeCaretControl(event.widget).enableFreeCaret(false);
- }
- });
- }
- }
- }
-
- protected ISourceViewer createSourceViewer(Composite parent,
- IVerticalRuler ruler, int styles) {
- ISourceViewer sv = super.createSourceViewer(parent, ruler, styles);
- sv.getTextWidget().addFocusListener(new TextFocusListener());
- return sv;
- }
-
- protected StructuredTextViewer createStructedTextViewer(Composite parent,
- IVerticalRuler verticalRuler, int styles) {
- return new JSPStructuredTextViewer(parent, verticalRuler,
- getOverviewRuler(), isOverviewRulerVisible(), styles,
- parentEditor, this);
- }
-
- class TextFocusListener extends FocusAdapter {
- public void focusLost(FocusEvent e) {
- if (JSPTextEditor.super.isDirty()) {
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- try {
- Thread.sleep(200);
- } catch (InterruptedException exc) {
- JspEditorPlugin.getPluginLog().logError(exc);
- }
- save();
- }
- });
- }
- }
- }
-
- public void save() {
- if (!lock && isModified()) {
- lock = true;
- try {
- FileAnyImpl f = (FileAnyImpl) getModelObject();
- if (f != null)
- f.edit(getSourceViewer().getDocument().get());
- } catch (Exception e) {
- JspEditorPlugin.getPluginLog().logError(e);
- } finally {
- setModified(false);
- lock = false;
- }
- }
- }
-
- boolean modified = false;
-
- public void setModified(boolean set) {
- if (this.modified != set) {
- this.modified = set;
- if (set) {
- XModelObject o = getModelObject();
- if (o != null)
- o.setModified(true);
- }
- super.firePropertyChange(IEditorPart.PROP_DIRTY);
- }
- }
-
- public void updateModification() {
- XModelObject object = getModelObject();
- if (object != null && !object.isModified() && isModified()) {
- setModified(false);
- } else {
- firePropertyChange(ITextEditor.PROP_DIRTY);
- }
- }
-
- public boolean isModified() {
- return modified;
- }
-
- protected void doSetInput(IEditorInput input) throws CoreException {
- super.doSetInput(XModelObjectEditorInput.checkInput(input));
- if (getSourceViewer() != null
- && getSourceViewer().getDocument() != null) {
- getSourceViewer().removeTextListener(this);
- getSourceViewer().addTextListener(this);
- }
- if (listener != null)
- listener.dispose();
- listener = null;
- XModelObject o = getModelObject();
- if (o instanceof FileAnyImpl) {
- listener = new BodyListenerImpl((FileAnyImpl) o);
- }
- }
-
- boolean lock = false;
-
- public boolean isDirty() {
- if (getEditorInput() instanceof IModelObjectEditorInput) {
- XModelObject o = getModelObject();
- if (o != null && o.isModified())
- return true;
- else {
- return isModified();
- }
- } else {
- return super.isDirty();
- }
- }
-
- public void doSave(IProgressMonitor monitor) {
- XModelObject o = getModelObject();
- super.doSave(monitor);
- if (o != null && (monitor == null || !monitor.isCanceled())) {
- if (o != null)
- save();
- if (getEditorInput() instanceof ILocationProvider) {
- XModelObject p = o.getParent();
- if (p instanceof FolderImpl) {
- ((FolderImpl) p).saveChild(o);
- }
- } else {
- o.setModified(false);
- XModelObjectLoaderUtil.updateModifiedOnSave(o);
- }
- super.firePropertyChange(IEditorPart.PROP_DIRTY);
- }
- }
-
- public void firePropertyChangeDirty() {
- super.firePropertyChange(IEditorPart.PROP_DIRTY);
- }
-
- public XModelObject getModelObject() {
- if (getEditorInput() instanceof IModelObjectEditorInput) {
- return ((IModelObjectEditorInput) getEditorInput())
- .getXModelObject();
- }
- return null;
- }
-
- class TextEditorDropProviderImpl implements TextEditorDropProvider {
-
- public ISourceViewer getSourceViewer() {
- return JSPTextEditor.this.getSourceViewer();
- }
-
- public XModelObject getModelObject() {
- return JSPTextEditor.this.getModelObject();
- }
-
- public void insert(Properties p) {
- PaletteInsertHelper.insertIntoEditor(getSourceViewer(), p);
- }
-
- }
-
- public void textChanged(TextEvent event) {
- if (event.getDocumentEvent() != null) {
- setModified(true);
- }
- }
-
- public void doRevertToSaved() {
- save();
- XModelObject o = getModelObject();
- if (o == null) {
- super.doRevertToSaved();
- return;
- }
- Properties p = new Properties();
- XActionInvoker.invoke("DiscardActions.Discard", o, p);
- if (!"true".equals(p.getProperty("done")))
- return;
- super.doRevertToSaved();
- if (o.isModified())
- o.setModified(false);
- modified = false;
- firePropertyChange(IEditorPart.PROP_DIRTY);
- updatePartControl(getEditorInput());
- }
-
- public IAnnotationModel getAnnotationModel() {
- return getSourceViewer().getAnnotationModel();
- }
-
- private WTPTextJspKbConnector wtpTextJspKbConnector;
-
- private void installActivePropmtSupport() {
- try {
- IDocument document = getTextViewer().getDocument();
- IStructuredModel model = null;
- if (getDocumentProvider() instanceof IModelProvider) {
- model = ((IModelProvider) getDocumentProvider())
- .getModel(getEditorInput());
- } else {
- if (document instanceof IStructuredDocument) {
- model = getModel();
- }
- }
- if (wtpTextJspKbConnector == null
- && model != null
- && (getContentType().toLowerCase().indexOf("jsp") != -1 ||
getContentType()
- .toLowerCase().indexOf("html") != -1)) {
- wtpTextJspKbConnector = new WTPTextJspKbConnector(
- getEditorInput(), document, model);
- wtpTextJspKbConnector.setTaglibManagerProvider(parentEditor);
- }
- } catch (Exception x) {
- JspEditorPlugin.getPluginLog().logError("Error while installing active prpmpting
support", x);
- }
- }
-
- private String getContentType() {
- String type = null;
- try {
- type = getModel().getContentTypeIdentifier();
- } finally {
- if (type == null)
- type = "";
- }
- return type;
- }
-
- public WTPTextJspKbConnector getWTPTextJspKbConnector() {
- return wtpTextJspKbConnector;
- }
-
- public static class JSPStructuredTextViewer extends StructuredTextViewer
- implements VpeTaglibManagerProvider, IIgnoreSelection {
-
- boolean insertFromPallete = false;
-
- private VpeTaglibManagerProvider provider;
-
- private JSPTextEditor editor;
-
- private boolean ignore = false;
-
- public JSPStructuredTextViewer(Composite parent,
- IVerticalRuler verticalRuler, int styles) {
- super(parent, verticalRuler, null, false, styles);
- }
-
- public JSPStructuredTextViewer(Composite parent,
- IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
- boolean showAnnotationsOverview, int styles,
- VpeTaglibManagerProvider provider, JSPTextEditor editor) {
- super(parent, verticalRuler, overviewRuler,
- showAnnotationsOverview, styles);
- this.provider = provider;
- this.editor = editor;
- }
-
- protected StyledText createTextWidget(Composite parent, int styles) {
- return new FreeCaretStyledText(parent, styles);
- }
-
- public VpeTaglibManager getTaglibManager() {
- if (provider != null) {
- return provider.getTaglibManager();
- }
- return null;
- }
-
- public boolean doesIgnore() {
- return ignore;
- }
-
- public void setIgnore(boolean ignore) {
- this.ignore = ignore;
- }
-
- public void doOperation(int operation) {
- if (operation == UNDO || operation == REDO
- || operation == FORMAT_DOCUMENT
- || operation == FORMAT_ACTIVE_ELEMENTS) {
- if (editor.getVPEController() != null) {
- editor.getVPEController().preLongOperation();
- }
- }
-
- super.doOperation(operation);
-
- if (operation == UNDO || operation == REDO
- || operation == FORMAT_DOCUMENT
- || operation == FORMAT_ACTIVE_ELEMENTS) {
- if (editor.getVPEController() != null) {
- editor.getVPEController().postLongOperation();
- }
- }
- }
- }
-
- public JSPMultiPageEditor getParentEditor() {
- return parentEditor;
- }
-
- public void setVPEController(IVisualController c) {
- vpeController = c;
- }
-
- public IVisualController getVPEController() {
- return vpeController;
- }
-
- public void runDropCommand(final String flavor, final String data) {
- XModelBuffer b = XModelTransferBuffer.getInstance().getBuffer();
- final XModelObject o = b == null ? null : b.source();
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- if (parentEditor.getVisualEditor().getController() != null) {
- if(o != null && !XModelTransferBuffer.getInstance().isEnabled()) {
- XModelTransferBuffer.getInstance().enable();
- XModelTransferBuffer.getInstance().getBuffer().addSource(o);
- }
- try {
- DropData dropData = new DropData(flavor,
- data,
- parentEditor.getVisualEditor().getController()
- .getPageContext(),
- getEditorInput(), getSourceViewer(),
- getSelectionProvider());
- dropData.setAttributeName(dropContext.getAttributeName());
- IDropCommand dropCommand = DropCommandFactory.getInstance().getDropCommand(flavor,
JSPTagProposalFactory.getInstance());
-
- boolean promptAttributes =
"yes".equals(VpePreference.ALWAYS_REQUEST_FOR_ATTRIBUTE.getValue());
- dropCommand.getDefaultModel().setPromptForTagAttributesRequired(promptAttributes);
- dropCommand.execute(dropData);
- } finally {
- XModelTransferBuffer.getInstance().disable();
- }
- }
- }
- });
- }
-
- private void createDrop() {
- DropTarget target = new DropTarget(getSourceViewer().getTextWidget(),
- DND.DROP_MOVE | DND.DROP_COPY);
- Transfer[] types = new Transfer[] { ModelTransfer.getInstance(),
- HTMLTransfer.getInstance(), TextTransfer.getInstance(),
- FileTransfer.getInstance() };
- target.setTransfer(types);
- target.addDropListener(new DTL());
- }
-
- DropContext dropContext = new DropContext();
-
- class DTL implements DropTargetListener {
- int lastpos = -1;
-
- int lastdetail = -1;
-
- public void dragEnter(DropTargetEvent event) {
- lastpos = -1;
- }
-
- public void dragLeave(DropTargetEvent event) {
- lastpos = -1;
- }
-
- public void dragOperationChanged(DropTargetEvent event) {
- }
-
- public void dragOver(DropTargetEvent event) {
- if (!isEditable()
- || (getModelObject() != null && !getModelObject()
- .isObjectEditable())) {
- event.detail = DND.DROP_NONE;
- return;
- }
- dropContext.setDropTargetEvent(event);
- if (dropContext.getFlavor() == null) {
- event.detail = DND.DROP_NONE;
- return;
- }
- // Drop from VPE to Source is forbidden
- if (dropContext.getFlavor().equals("text/html")) {
- if (InnerDragBuffer.object != null) {
- event.detail = DND.DROP_NONE;
- }
- return;
- }
- int pos = getPosition(event.x, event.y);
- if (lastpos == pos && pos >= 0) {
- pos = lastpos;
- event.detail = lastdetail;
- return;
- }
- lastpos = pos;
- dropContext.clean();
- getSourceViewer().getDocument();
- IndexedRegion region = getModel().getIndexedRegion(pos);
- if (region instanceof ElementImpl) {
- ElementImpl jspElement = (ElementImpl) region;
- NamedNodeMap attributes = jspElement.getAttributes();
- if (pos == jspElement.getStartOffset()
- || pos == jspElement.getEndStartOffset()) {
- event.detail = lastdetail = DND.DROP_MOVE;
- return;
- }
- for (int i = 0; i < attributes.getLength(); i++) {
- Node attribute = attributes.item(i);
- if (attribute instanceof AttrImpl) {
- AttrImpl jspAttr = (AttrImpl) attribute;
- ITextRegion valueRegion = jspAttr.getValueRegion();
- if (valueRegion == null) {
- event.detail = lastdetail = DND.DROP_NONE;
- return;
- }
- int startPos = jspElement.getStartOffset()
- + valueRegion.getStart();
- int endPos = jspElement.getStartOffset()
- + valueRegion.getTextEnd();
- if (pos > startPos && pos < endPos) {
- dropContext.setOverAttributeValue(true);
- dropContext.setAttributeName(jspAttr.getNodeName());
- event.detail = lastdetail = DND.DROP_MOVE;
- return;
- }
- }
- }
- event.detail = lastdetail = DND.DROP_NONE;
- } else if (region instanceof Text
- && isInsideResponseRedirect((Text) region, pos
- - region.getStartOffset())) {
- dropContext.setOverAttributeValue(true);
- event.detail = lastdetail = DND.DROP_MOVE;
- } else if (region instanceof Text) {
- event.detail = lastdetail = DND.DROP_MOVE;
- } else if (region instanceof DocumentType) {
- event.detail = lastdetail = DND.DROP_NONE;
- } else if (region == null) {
- //new place
- event.detail = lastdetail = DND.DROP_MOVE;
- }
- }
-
- public void drop(DropTargetEvent event) {
- int offset = getPosition(event.x, event.y);
- selectAndReveal(offset, 0);
- dropContext.runDropCommand(JSPTextEditor.this, event);
- }
-
- public void dropAccept(DropTargetEvent event) {
- }
-
- }
-
- private int getPosition(int x, int y) {
- try {
- ISourceViewer v = getSourceViewer();
- StyledText t = v.getTextWidget();
- Point pp = t.toControl(x, y);
- x = pp.x;
- y = pp.y;
- int lineIndex = (t.getTopPixel() + y) / t.getLineHeight();
- if (lineIndex >= t.getLineCount()) {
- return t.getCharCount();
- } else {
- int c = 0;
- try {
- c = t.getOffsetAtLocation(new Point(x, y));
- if (c < 0)
- c = 0;
- } catch (Exception ex) {
- c = t.getOffsetAtLine(lineIndex + 1)
- - (t.getLineDelimiter() == null ? 0 : t
- .getLineDelimiter().length());
- }
- return c;
- }
- } catch (Exception e) {
- return 0;
- }
- }
-
- public String[] getConfigurationPoints() {
- String contentTypeIdentifierID = null;
- if (getModel() != null)
- contentTypeIdentifierID = getModel().getContentTypeIdentifier();
- return ConfigurationPointCalculator.getConfigurationPoints(this,
- contentTypeIdentifierID, ConfigurationPointCalculator.SOURCE,
- StructuredTextEditor.class);
- }
-
- public void formatTextRegion(IDocument document, IRegion region) {
- SourceViewerConfiguration conf = getSourceViewerConfiguration();
-
- if (conf instanceof StructuredTextViewerConfiguration) {
- StructuredTextViewerConfiguration stvc = (StructuredTextViewerConfiguration) conf;
- IContentFormatter f = stvc.getContentFormatter(getSourceViewer());
- f.format(document, region);
- }
- }
-
- Point storedSelection = new Point(0, 0);
-
- protected void handleCursorPositionChanged() {
- super.handleCursorPositionChanged();
- ISelection selection = getSelectionProvider().getSelection();
- Point p = getTextViewer().getTextWidget().getSelection();
- if (storedSelection == null || !storedSelection.equals(p)) {
- storedSelection = p;
- if (selection instanceof ITextSelection) {
- ITextSelection ts = (ITextSelection) selection;
- if (ts.getLength() == 0) {
- if (vpeController != null) {
- vpeController
- .selectionChanged(new SelectionChangedEvent(
- getSelectionProvider(),
- getSelectionProvider().getSelection()));
- }
- }
- }
- }
- }
-
- static int firingSelectionFailedCount = 0;
-
- private class OutlinePageListener implements IDoubleClickListener,
- ISelectionChangedListener {
- public void doubleClick(DoubleClickEvent event) {
- if (event.getSelection().isEmpty())
- return;
-
- int start = -1;
- int length = 0;
- if (event.getSelection() instanceof IStructuredSelection) {
- ISelection currentSelection = getSelectionProvider()
- .getSelection();
- if (currentSelection instanceof IStructuredSelection) {
- Object current = ((IStructuredSelection) currentSelection)
- .toArray();
- Object newSelection = ((IStructuredSelection) event
- .getSelection()).toArray();
- if (!current.equals(newSelection)) {
- IStructuredSelection selection = (IStructuredSelection) event
- .getSelection();
- Object o = selection.getFirstElement();
- if (o instanceof IndexedRegion) {
- start = ((IndexedRegion) o).getStartOffset();
- length = ((IndexedRegion) o).getEndOffset() - start;
- } else if (o instanceof ITextRegion) {
- start = ((ITextRegion) o).getStart();
- length = ((ITextRegion) o).getEnd() - start;
- } else if (o instanceof IRegion) {
- start = ((ITextRegion) o).getStart();
- length = ((ITextRegion) o).getLength();
- }
- }
- }
- } else if (event.getSelection() instanceof ITextSelection) {
- start = ((ITextSelection) event.getSelection()).getOffset();
- length = ((ITextSelection) event.getSelection()).getLength();
- }
- if (start > -1) {
- getSourceViewer().setRangeIndication(start, length, false);
- selectAndReveal(start, length);
- }
- }
-
- public void selectionChanged(SelectionChangedEvent event) {
- if (event.getSelection().isEmpty() || isFiringSelection())
- return;
-
- boolean ignoreSelection = false;
- if (getSourceViewer() != null
- && getSourceViewer() instanceof IIgnoreSelection) {
- IIgnoreSelection is = ((IIgnoreSelection) getSourceViewer());
- ignoreSelection = is.doesIgnore();
- }
- if (getSourceViewer() != null
- && getSourceViewer().getTextWidget() != null
- && !getSourceViewer().getTextWidget().isDisposed()
- && !getSourceViewer().getTextWidget().isFocusControl()
- && !ignoreSelection) {
- int start = -1;
- int length = 0;
- if (event.getSelection() instanceof IStructuredSelection) {
- ISelection current = getSelectionProvider().getSelection();
- if (current instanceof IStructuredSelection) {
- Object[] currentSelection = ((IStructuredSelection) current)
- .toArray();
- Object[] newSelection = ((IStructuredSelection) event
- .getSelection()).toArray();
- if (!Arrays.equals(currentSelection, newSelection)) {
- if (newSelection.length > 0) {
- /*
- * No ordering is guaranteed for multiple
- * selection
- */
- Object o = newSelection[0];
- if (o instanceof IndexedRegion) {
- start = ((IndexedRegion) o)
- .getStartOffset();
- int end = ((IndexedRegion) o)
- .getEndOffset();
- if (newSelection.length > 1) {
- for (int i = 1; i < newSelection.length; i++) {
- start = Math
- .min(
- start,
- ((IndexedRegion) newSelection[i])
- .getStartOffset());
- end = Math
- .max(
- end,
- ((IndexedRegion) newSelection[i])
- .getEndOffset());
- }
- length = end - start;
- }
- } else if (o instanceof ITextRegion) {
- start = ((ITextRegion) o).getStart();
- int end = ((ITextRegion) o).getEnd();
- if (newSelection.length > 1) {
- for (int i = 1; i < newSelection.length; i++) {
- start = Math
- .min(
- start,
- ((ITextRegion) newSelection[i])
- .getStart());
- end = Math
- .max(
- end,
- ((ITextRegion) newSelection[i])
- .getEnd());
- }
- length = end - start;
- }
- } else if (o instanceof IRegion) {
- start = ((IRegion) o).getOffset();
- int end = start + ((IRegion) o).getLength();
- if (newSelection.length > 1) {
- for (int i = 1; i < newSelection.length; i++) {
- start = Math.min(start,
- ((IRegion) newSelection[i])
- .getOffset());
- end = Math
- .max(
- end,
- ((IRegion) newSelection[i])
- .getOffset()
- + ((IRegion) newSelection[i])
- .getLength());
- }
- length = end - start;
- }
- }
- }
- }
- }
- } else if (event.getSelection() instanceof ITextSelection) {
- start = ((ITextSelection) event.getSelection()).getOffset();
- }
- if (start > -1) {
- updateRangeIndication0(event.getSelection());
- selectAndReveal(start, length);
- }
- }
- }
-
- Method m = null;
-
- private boolean isFiringSelection() {
- if (getSelectionProvider() == null)
- return false;
- if (firingSelectionFailedCount > 0)
- return false;
- try {
- if (m == null) {
- Class c = getSelectionProvider().getClass();
- m = c.getDeclaredMethod("isFiringSelection", new Class[0]);
- m.setAccessible(true);
- }
- Boolean b = (Boolean) m.invoke(getSelectionProvider(),
- new Object[0]);
- return b.booleanValue();
- } catch (Exception e) {
- firingSelectionFailedCount++;
- JspEditorPlugin.getPluginLog().logError(e);
- }
- return false;
- }
- }
-
- private void updateRangeIndication0(ISelection selection) {
- if (selection instanceof IStructuredSelection
- && !((IStructuredSelection) selection).isEmpty()) {
- Object[] objects = ((IStructuredSelection) selection).toArray();
- if (objects.length > 0) {
- int start = ((IndexedRegion) objects[0]).getStartOffset();
- int end = ((IndexedRegion) objects[objects.length - 1])
- .getEndOffset();
- getSourceViewer().setRangeIndication(start, end - start, false);
- } else {
- getSourceViewer().removeRangeIndication();
- }
- } else {
- if (selection instanceof ITextSelection) {
- getSourceViewer().setRangeIndication(
- ((ITextSelection) selection).getOffset(),
- ((ITextSelection) selection).getLength(), false);
- } else {
- getSourceViewer().removeRangeIndication();
- }
- }
- }
-
- protected IExtendedAction createExtendedAction(String actionID) {
- if (StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_DOCUMENT
- .equals(actionID)
- || ITextEditorActionConstants.UNDO.equals(actionID)
- || ITextEditorActionConstants.REDO.equals(actionID)) {
- return new ExtendedFormatAction(this, actionID);
- }
- return null;
- }
-
- protected void initializeEditor() {
- super.initializeEditor();
- getPreferenceStore();
- }
-
- public void dispose() {
- if (fOccurrenceModelUpdater != null) {
- fOccurrenceModelUpdater.uninstall();
- fOccurrenceModelUpdater = null;
- }
- super.dispose();
- if (listener != null)
- listener.dispose();
- listener = null;
- }
-
- BodyListenerImpl listener = null;
-
- class BodyListenerImpl implements FileAnyImpl.BodyListener {
- FileAnyImpl file;
-
- BodyListenerImpl(FileAnyImpl file) {
- this.file = file;
- file.addListener(this);
- }
-
- public void bodyChanged(String body) {
- setText(body);
- }
-
- public void dispose() {
- file.removeListener(this);
- }
- }
-
- public void setText(String text) {
- if (getSourceViewer() == null
- || getSourceViewer().getDocument() == null)
- return;
- String txt = getSourceViewer().getDocument().get();
- if (txt != null && txt.length() > 0) {
- if (!TextMerge.replace(getSourceViewer().getDocument(), text)) {
- getSourceViewer().getDocument().set(text);
- }
- } else {
- getSourceViewer().getDocument().set(text);
- }
- }
-
- boolean isInsideResponseRedirect(Text textNode, int off) {
- if (off < 0)
- return false;
- String START = "response.sendRedirect(\"";
- String END = "\")";
- String text = textNode.getNodeValue();
- int i = 0;
- while (i < text.length() && i < off) {
- int i1 = text.indexOf(START, i);
- if (i1 < 0 || i1 + START.length() > off)
- return false;
- int i2 = text.indexOf(END, i1 + START.length());
- if (i2 < 0 || i2 >= off)
- return true;
- i = i2 + END.length();
- }
- return false;
- }
-}
+/*******************************************************************************
+ * 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.jst.jsp.jspeditor;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextListener;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.TextEvent;
+import org.eclipse.jface.text.formatter.IContentFormatter;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.IOverviewRuler;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP;
+import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DragSource;
+import org.eclipse.swt.dnd.DropTarget;
+import org.eclipse.swt.dnd.DropTargetAdapter;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.DropTargetListener;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.swt.dnd.HTMLTransfer;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.editors.text.ILocationProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.eclipse.ui.views.properties.PropertySheetPage;
+import org.eclipse.ui.views.properties.PropertySheetSorter;
+import org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration;
+import org.eclipse.wst.sse.ui.internal.IModelProvider;
+import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
+import org.eclipse.wst.sse.ui.internal.actions.StructuredTextEditorActionConstants;
+import org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage;
+import org.eclipse.wst.sse.ui.internal.properties.ConfigurablePropertySheetPage;
+import
org.eclipse.wst.sse.ui.internal.provisional.extensions.ConfigurationPointCalculator;
+import org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration;
+import org.eclipse.wst.xml.core.internal.document.AttrImpl;
+import org.eclipse.wst.xml.core.internal.document.ElementImpl;
+import org.jboss.tools.common.core.resources.XModelObjectEditorInput;
+import org.jboss.tools.common.meta.action.XActionInvoker;
+import org.jboss.tools.common.model.XModelBuffer;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.XModelTransferBuffer;
+import org.jboss.tools.common.model.filesystems.impl.FileAnyImpl;
+import org.jboss.tools.common.model.filesystems.impl.FolderImpl;
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
+import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
+import org.jboss.tools.common.model.ui.editor.IModelObjectEditorInput;
+import org.jboss.tools.common.model.ui.editors.dnd.DropCommandFactory;
+import org.jboss.tools.common.model.ui.editors.dnd.DropData;
+import org.jboss.tools.common.model.ui.editors.dnd.IDropCommand;
+import org.jboss.tools.common.model.ui.editors.dnd.JSPTagProposalFactory;
+import org.jboss.tools.common.model.ui.editors.dnd.context.DropContext;
+import org.jboss.tools.common.model.ui.editors.dnd.context.InnerDragBuffer;
+import org.jboss.tools.common.model.ui.texteditors.TextMerge;
+import org.jboss.tools.common.model.ui.texteditors.dnd.TextEditorDrop;
+import org.jboss.tools.common.model.ui.texteditors.dnd.TextEditorDropProvider;
+import org.jboss.tools.common.model.ui.views.palette.IIgnoreSelection;
+import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
+import org.jboss.tools.common.model.util.XModelObjectLoaderUtil;
+import org.jboss.tools.common.text.xml.IOccurrencePreferenceProvider;
+import org.jboss.tools.common.text.xml.XmlEditorPlugin;
+import org.jboss.tools.common.text.xml.ui.FreeCaretStyledText;
+import org.jboss.tools.jst.jsp.ExtendedStructuredTextViewerConfigurationHTML;
+import org.jboss.tools.jst.jsp.ExtendedStructuredTextViewerConfigurationJSP;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.editor.IJSPTextEditor;
+import org.jboss.tools.jst.jsp.editor.ITextFormatter;
+import org.jboss.tools.jst.jsp.editor.IVisualController;
+import org.jboss.tools.jst.jsp.outline.JSPContentOutlineConfiguration;
+import org.jboss.tools.jst.jsp.outline.JSPPropertySheetConfiguration;
+import org.jboss.tools.jst.jsp.preferences.VpePreference;
+import org.jboss.tools.jst.jsp.support.kb.WTPTextJspKbConnector;
+import org.jboss.tools.jst.jsp.text.xpl.IStructuredTextOccurrenceStructureProvider;
+import
org.jboss.tools.jst.jsp.text.xpl.StructuredTextOccurrenceStructureProviderRegistry;
+import org.jboss.tools.jst.jsp.ui.action.ExtendedFormatAction;
+import org.jboss.tools.jst.jsp.ui.action.IExtendedAction;
+import org.jboss.tools.jst.web.tld.VpeTaglibManager;
+import org.jboss.tools.jst.web.tld.VpeTaglibManagerProvider;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
+/**
+ * @author Jeremy
+ *
+ */
+public class JSPTextEditor extends StructuredTextEditor implements
+ ITextListener, IJSPTextEditor, ITextFormatter,
+ IOccurrencePreferenceProvider {
+ private IStructuredTextOccurrenceStructureProvider fOccurrenceModelUpdater;
+
+ TextEditorDrop dnd = new TextEditorDrop();
+
+ JSPMultiPageEditor parentEditor;
+
+ long timeStamp = -1;
+
+ long savedTimeStamp = -1;
+
+ IVisualController vpeController;
+
+ public JSPTextEditor(JSPMultiPageEditor parentEditor) {
+ JspEditorPlugin.getDefault().initDefaultPluginPreferences();
+ dnd.setTextEditorDropProvider(new TextEditorDropProviderImpl());
+ this.parentEditor = parentEditor;
+ super
+ .setSourceViewerConfiguration(new ExtendedStructuredTextViewerConfigurationJSP());
+ }
+
+ protected void setSourceViewerConfiguration(SourceViewerConfiguration config) {
+ if (config instanceof StructuredTextViewerConfigurationJSP) {
+ if (!(config instanceof ExtendedStructuredTextViewerConfigurationJSP)) {
+ config = new ExtendedStructuredTextViewerConfigurationJSP();
+ }
+ } else if (config instanceof StructuredTextViewerConfigurationHTML) {
+ if (!(config instanceof ExtendedStructuredTextViewerConfigurationHTML)) {
+ config = new ExtendedStructuredTextViewerConfigurationHTML();
+ }
+ } else {
+ config = new ExtendedStructuredTextViewerConfigurationJSP();
+ }
+ super.setSourceViewerConfiguration(config);
+ }
+
+ protected void initializeDrop(ITextViewer textViewer) {
+
+ Composite c = textViewer.getTextWidget();
+ Label l = new Label(c, SWT.NONE);
+ l.dispose();
+ }
+
+ private ConfigurableContentOutlinePage fOutlinePage = null;
+
+ private OutlinePageListener fOutlinePageListener = null;
+
+ private IPropertySheetPage fPropertySheetPage;
+
+ public Object getAdapter(Class adapter) {
+ if (ISourceViewer.class.equals(adapter)) {
+ return JSPTextEditor.this.getSourceViewer();
+ } else if (IContentOutlinePage.class.equals(adapter)) {
+ if (fOutlinePage == null || fOutlinePage.getControl() == null
+ || fOutlinePage.getControl().isDisposed()) {
+ IStructuredModel internalModel = getModel();
+ ContentOutlineConfiguration cfg = new JSPContentOutlineConfiguration(
+ this);
+ if (cfg != null) {
+ ConfigurableContentOutlinePage outlinePage = new ConfigurableContentOutlinePage();
+ outlinePage.setConfiguration(cfg);
+ if (internalModel != null) {
+ outlinePage.setInputContentTypeIdentifier(internalModel
+ .getContentTypeIdentifier());
+ outlinePage.setInput(internalModel);
+ }
+
+ if (fOutlinePageListener == null) {
+ fOutlinePageListener = new OutlinePageListener();
+ }
+
+ outlinePage
+ .addSelectionChangedListener(fOutlinePageListener);
+ outlinePage.addDoubleClickListener(fOutlinePageListener);
+
+ fOutlinePage = outlinePage;
+ }
+ }
+ return fOutlinePage;
+ } else if (IPropertySheetPage.class == adapter) {
+ if (fPropertySheetPage == null
+ || fPropertySheetPage.getControl() == null
+ || fPropertySheetPage.getControl().isDisposed()) {
+ JSPPropertySheetConfiguration cfg = new JSPPropertySheetConfiguration();
+ if (cfg != null) {
+ ConfigurablePropertySheetPage propertySheetPage = new
ConfigurablePropertySheetPage();
+ propertySheetPage.setConfiguration(cfg);
+ fPropertySheetPage = propertySheetPage;
+ setSorter(cfg.getSorter(), propertySheetPage);
+ }
+ }
+ return fPropertySheetPage;
+ }
+ return super.getAdapter(adapter);
+ }
+
+ private void setSorter(PropertySheetSorter sorter,
+ ConfigurablePropertySheetPage sheet) {
+ try {
+ Method method = PropertySheetPage.class.getDeclaredMethod(
+ "setSorter", new Class[] { PropertySheetSorter.class });
+ method.setAccessible(true);
+ method.invoke(sheet, new Object[] { sorter });
+ } catch (Exception e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ }
+
+ public String getEditorId() {
+ return JSPUIPlugin.ID;
+ }
+
+ public IStructuredTextOccurrenceStructureProvider getOccurrencePreferenceProvider() {
+ return fOccurrenceModelUpdater;
+ }
+
+ public void createPartControl(Composite parent) {
+ super.createPartControl(parent);
+
+ StructuredTextOccurrenceStructureProviderRegistry registry = XmlEditorPlugin
+ .getDefault().getOccurrenceStructureProviderRegistry(
+ JspEditorPlugin.PLUGIN_ID);
+ fOccurrenceModelUpdater = registry
+ .getCurrentOccurrenceProvider(JspEditorPlugin.PLUGIN_ID);
+
+ if (fOccurrenceModelUpdater != null)
+ fOccurrenceModelUpdater.install(this, getTextViewer());
+
+ installActivePropmtSupport();
+
+ createDrop();
+ setModified(false);
+ getSourceViewer().removeTextListener(this);
+ getSourceViewer().addTextListener(this);
+
+ Object dtid = getSourceViewer().getTextWidget().getData("DropTarget");
+ if (dtid != null) {
+ if (dtid instanceof DropTarget) {
+ DropTarget dropTarget = (DropTarget) dtid;
+ dropTarget.addDropListener(new DropTargetAdapter() {
+ private FreeCaretStyledText getFreeCaretControl(
+ Object sourceOrTarget) {
+ if (sourceOrTarget == null)
+ return null;
+
+ Object control = null;
+
+ if (sourceOrTarget instanceof DropTarget) {
+ control = ((DropTarget) sourceOrTarget)
+ .getControl();
+ } else if (sourceOrTarget instanceof DragSource) {
+ control = ((DragSource) sourceOrTarget)
+ .getControl();
+ } else
+ return null;
+
+ if (control instanceof FreeCaretStyledText)
+ return (FreeCaretStyledText) control;
+ return null;
+ }
+
+ private int getPosition(StyledText t, int x, int y) {
+ try {
+ Point pp = t.toControl(x, y);
+ x = pp.x;
+ y = pp.y;
+ int lineIndex = (t.getTopPixel() + y)
+ / t.getLineHeight();
+ if (lineIndex >= t.getLineCount()) {
+ return t.getCharCount();
+ } else {
+ int c = 0;
+ try {
+ c = t.getOffsetAtLocation(new Point(x, y));
+ if (c < 0)
+ c = 0;
+ } catch (Exception ex) {
+ c = t.getOffsetAtLine(lineIndex + 1)
+ - (t.getLineDelimiter() == null ? 0
+ : t.getLineDelimiter()
+ .length());
+ }
+ return c;
+ }
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ public void dragEnter(DropTargetEvent event) {
+ getFreeCaretControl(event.widget).enableFreeCaret(true);
+ }
+
+ public void dragLeave(DropTargetEvent event) {
+ getFreeCaretControl(event.widget).enableFreeCaret(false);
+ }
+
+ public void dragOperationChanged(DropTargetEvent event) {
+ getFreeCaretControl(event.widget).enableFreeCaret(false);
+ }
+
+ public void dragOver(DropTargetEvent event) {
+ FreeCaretStyledText fcst = getFreeCaretControl(event.widget);
+ int pos = getPosition(fcst, event.x, event.y);
+ Point p = fcst.getLocationAtOffset(pos);
+ fcst.myRedraw(p.x, p.y);
+ }
+
+ public void drop(DropTargetEvent event) {
+ getFreeCaretControl(event.widget).enableFreeCaret(false);
+ }
+ });
+ }
+ }
+ }
+
+ protected ISourceViewer createSourceViewer(Composite parent,
+ IVerticalRuler ruler, int styles) {
+ ISourceViewer sv = super.createSourceViewer(parent, ruler, styles);
+ sv.getTextWidget().addFocusListener(new TextFocusListener());
+ return sv;
+ }
+
+ protected StructuredTextViewer createStructedTextViewer(Composite parent,
+ IVerticalRuler verticalRuler, int styles) {
+ return new JSPStructuredTextViewer(parent, verticalRuler,
+ getOverviewRuler(), isOverviewRulerVisible(), styles,
+ parentEditor, this);
+ }
+
+ class TextFocusListener extends FocusAdapter {
+ public void focusLost(FocusEvent e) {
+ if (JSPTextEditor.super.isDirty()) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException exc) {
+ JspEditorPlugin.getPluginLog().logError(exc);
+ }
+ save();
+ }
+ });
+ }
+ }
+ }
+
+ public void save() {
+ if (!lock && isModified()) {
+ lock = true;
+ try {
+ FileAnyImpl f = (FileAnyImpl) getModelObject();
+ if (f != null)
+ f.edit(getSourceViewer().getDocument().get());
+ } catch (Exception e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ } finally {
+ setModified(false);
+ lock = false;
+ }
+ }
+ }
+
+ boolean modified = false;
+
+ public void setModified(boolean set) {
+ if (this.modified != set) {
+ this.modified = set;
+ if (set) {
+ XModelObject o = getModelObject();
+ if (o != null)
+ o.setModified(true);
+ }
+ super.firePropertyChange(IEditorPart.PROP_DIRTY);
+ }
+ }
+
+ public void updateModification() {
+ XModelObject object = getModelObject();
+ if (object != null && !object.isModified() && isModified()) {
+ setModified(false);
+ } else {
+ firePropertyChange(ITextEditor.PROP_DIRTY);
+ }
+ }
+
+ public boolean isModified() {
+ return modified;
+ }
+
+ protected void doSetInput(IEditorInput input) throws CoreException {
+ super.doSetInput(XModelObjectEditorInput.checkInput(input));
+ if (getSourceViewer() != null
+ && getSourceViewer().getDocument() != null) {
+ getSourceViewer().removeTextListener(this);
+ getSourceViewer().addTextListener(this);
+ }
+ if (listener != null)
+ listener.dispose();
+ listener = null;
+ XModelObject o = getModelObject();
+ if (o instanceof FileAnyImpl) {
+ listener = new BodyListenerImpl((FileAnyImpl) o);
+ }
+ }
+
+ boolean lock = false;
+
+ public boolean isDirty() {
+ if (getEditorInput() instanceof IModelObjectEditorInput) {
+ XModelObject o = getModelObject();
+ if (o != null && o.isModified())
+ return true;
+ else {
+ return isModified();
+ }
+ } else {
+ return super.isDirty();
+ }
+ }
+
+ public void doSave(IProgressMonitor monitor) {
+ XModelObject o = getModelObject();
+ super.doSave(monitor);
+ if (o != null && (monitor == null || !monitor.isCanceled())) {
+ if (o != null)
+ save();
+ if (getEditorInput() instanceof ILocationProvider) {
+ XModelObject p = o.getParent();
+ if (p instanceof FolderImpl) {
+ ((FolderImpl) p).saveChild(o);
+ }
+ } else {
+ o.setModified(false);
+ XModelObjectLoaderUtil.updateModifiedOnSave(o);
+ }
+ super.firePropertyChange(IEditorPart.PROP_DIRTY);
+ }
+ }
+
+ public void firePropertyChangeDirty() {
+ super.firePropertyChange(IEditorPart.PROP_DIRTY);
+ }
+
+ public XModelObject getModelObject() {
+ if (getEditorInput() instanceof IModelObjectEditorInput) {
+ return ((IModelObjectEditorInput) getEditorInput())
+ .getXModelObject();
+ }
+ return null;
+ }
+
+ class TextEditorDropProviderImpl implements TextEditorDropProvider {
+
+ public ISourceViewer getSourceViewer() {
+ return JSPTextEditor.this.getSourceViewer();
+ }
+
+ public XModelObject getModelObject() {
+ return JSPTextEditor.this.getModelObject();
+ }
+
+ public void insert(Properties p) {
+ PaletteInsertHelper.insertIntoEditor(getSourceViewer(), p);
+ }
+
+ }
+
+ public void textChanged(TextEvent event) {
+ if (event.getDocumentEvent() != null) {
+ setModified(true);
+ }
+ }
+
+ public void doRevertToSaved() {
+ save();
+ XModelObject o = getModelObject();
+ if (o == null) {
+ super.doRevertToSaved();
+ return;
+ }
+ Properties p = new Properties();
+ XActionInvoker.invoke("DiscardActions.Discard", o, p);
+ if (!"true".equals(p.getProperty("done")))
+ return;
+ super.doRevertToSaved();
+ if (o.isModified())
+ o.setModified(false);
+ modified = false;
+ firePropertyChange(IEditorPart.PROP_DIRTY);
+ updatePartControl(getEditorInput());
+ }
+
+ public IAnnotationModel getAnnotationModel() {
+ return getSourceViewer().getAnnotationModel();
+ }
+
+ private WTPTextJspKbConnector wtpTextJspKbConnector;
+
+ private void installActivePropmtSupport() {
+ try {
+ IDocument document = getTextViewer().getDocument();
+ IStructuredModel model = null;
+ if (getDocumentProvider() instanceof IModelProvider) {
+ model = ((IModelProvider) getDocumentProvider())
+ .getModel(getEditorInput());
+ } else {
+ if (document instanceof IStructuredDocument) {
+ model = getModel();
+ }
+ }
+ if (wtpTextJspKbConnector == null
+ && model != null
+ && (getContentType().toLowerCase().indexOf("jsp") != -1 ||
getContentType()
+ .toLowerCase().indexOf("html") != -1)) {
+ wtpTextJspKbConnector = new WTPTextJspKbConnector(
+ getEditorInput(), document, model);
+ wtpTextJspKbConnector.setTaglibManagerProvider(parentEditor);
+ }
+ } catch (Exception x) {
+ JspEditorPlugin.getPluginLog().logError("Error while installing active prpmpting
support", x);
+ }
+ }
+
+ private String getContentType() {
+ String type = null;
+ try {
+ type = getModel().getContentTypeIdentifier();
+ } finally {
+ if (type == null)
+ type = "";
+ }
+ return type;
+ }
+
+ public WTPTextJspKbConnector getWTPTextJspKbConnector() {
+ return wtpTextJspKbConnector;
+ }
+
+ public static class JSPStructuredTextViewer extends StructuredTextViewer
+ implements VpeTaglibManagerProvider, IIgnoreSelection {
+
+ boolean insertFromPallete = false;
+
+ private VpeTaglibManagerProvider provider;
+
+ private JSPTextEditor editor;
+
+ private boolean ignore = false;
+
+ public JSPStructuredTextViewer(Composite parent,
+ IVerticalRuler verticalRuler, int styles) {
+ super(parent, verticalRuler, null, false, styles);
+ }
+
+ public JSPStructuredTextViewer(Composite parent,
+ IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
+ boolean showAnnotationsOverview, int styles,
+ VpeTaglibManagerProvider provider, JSPTextEditor editor) {
+ super(parent, verticalRuler, overviewRuler,
+ showAnnotationsOverview, styles);
+ this.provider = provider;
+ this.editor = editor;
+ }
+
+ protected StyledText createTextWidget(Composite parent, int styles) {
+ return new FreeCaretStyledText(parent, styles);
+ }
+
+ public VpeTaglibManager getTaglibManager() {
+ if (provider != null) {
+ return provider.getTaglibManager();
+ }
+ return null;
+ }
+
+ public boolean doesIgnore() {
+ return ignore;
+ }
+
+ public void setIgnore(boolean ignore) {
+ this.ignore = ignore;
+ }
+
+ public void doOperation(int operation) {
+ if (operation == UNDO || operation == REDO
+ || operation == FORMAT_DOCUMENT
+ || operation == FORMAT_ACTIVE_ELEMENTS) {
+ if (editor.getVPEController() != null) {
+ editor.getVPEController().preLongOperation();
+ }
+ }
+
+ super.doOperation(operation);
+
+ if (operation == UNDO || operation == REDO
+ || operation == FORMAT_DOCUMENT
+ || operation == FORMAT_ACTIVE_ELEMENTS) {
+ if (editor.getVPEController() != null) {
+ editor.getVPEController().postLongOperation();
+ }
+ }
+ }
+
+ protected void handleDispose() {
+ if (editor != null && editor.getSourceViewer() != null &&
editor.getSourceViewer().getTextWidget() != null && editor.getVPEController() !=
null) {
+ StyledText widget = editor.getSourceViewer().getTextWidget();
+ widget.removeSelectionListener(editor.getVPEController());
+ }
+ super.handleDispose();
+ }
+ }
+
+ public JSPMultiPageEditor getParentEditor() {
+ return parentEditor;
+ }
+
+ public void setVPEController(IVisualController c) {
+ vpeController = c;
+ }
+
+ public IVisualController getVPEController() {
+ return vpeController;
+ }
+
+ public void runDropCommand(final String flavor, final String data) {
+ XModelBuffer b = XModelTransferBuffer.getInstance().getBuffer();
+ final XModelObject o = b == null ? null : b.source();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ if (parentEditor.getVisualEditor().getController() != null) {
+ if(o != null && !XModelTransferBuffer.getInstance().isEnabled()) {
+ XModelTransferBuffer.getInstance().enable();
+ XModelTransferBuffer.getInstance().getBuffer().addSource(o);
+ }
+ try {
+ DropData dropData = new DropData(flavor,
+ data,
+ parentEditor.getVisualEditor().getController()
+ .getPageContext(),
+ getEditorInput(), getSourceViewer(),
+ getSelectionProvider());
+ dropData.setAttributeName(dropContext.getAttributeName());
+ IDropCommand dropCommand = DropCommandFactory.getInstance().getDropCommand(flavor,
JSPTagProposalFactory.getInstance());
+
+ boolean promptAttributes =
"yes".equals(VpePreference.ALWAYS_REQUEST_FOR_ATTRIBUTE.getValue());
+ dropCommand.getDefaultModel().setPromptForTagAttributesRequired(promptAttributes);
+ dropCommand.execute(dropData);
+ } finally {
+ XModelTransferBuffer.getInstance().disable();
+ }
+ }
+ }
+ });
+ }
+
+ private void createDrop() {
+ DropTarget target = new DropTarget(getSourceViewer().getTextWidget(),
+ DND.DROP_MOVE | DND.DROP_COPY);
+ Transfer[] types = new Transfer[] { ModelTransfer.getInstance(),
+ HTMLTransfer.getInstance(), TextTransfer.getInstance(),
+ FileTransfer.getInstance() };
+ target.setTransfer(types);
+ target.addDropListener(new DTL());
+ }
+
+ DropContext dropContext = new DropContext();
+
+ class DTL implements DropTargetListener {
+ int lastpos = -1;
+
+ int lastdetail = -1;
+
+ public void dragEnter(DropTargetEvent event) {
+ lastpos = -1;
+ }
+
+ public void dragLeave(DropTargetEvent event) {
+ lastpos = -1;
+ }
+
+ public void dragOperationChanged(DropTargetEvent event) {
+ }
+
+ public void dragOver(DropTargetEvent event) {
+ if (!isEditable()
+ || (getModelObject() != null && !getModelObject()
+ .isObjectEditable())) {
+ event.detail = DND.DROP_NONE;
+ return;
+ }
+ dropContext.setDropTargetEvent(event);
+ if (dropContext.getFlavor() == null) {
+ event.detail = DND.DROP_NONE;
+ return;
+ }
+ // Drop from VPE to Source is forbidden
+ if (dropContext.getFlavor().equals("text/html")) {
+ if (InnerDragBuffer.object != null) {
+ event.detail = DND.DROP_NONE;
+ }
+ return;
+ }
+ int pos = getPosition(event.x, event.y);
+ if (lastpos == pos && pos >= 0) {
+ pos = lastpos;
+ event.detail = lastdetail;
+ return;
+ }
+ lastpos = pos;
+ dropContext.clean();
+ getSourceViewer().getDocument();
+ IndexedRegion region = getModel().getIndexedRegion(pos);
+ if (region instanceof ElementImpl) {
+ ElementImpl jspElement = (ElementImpl) region;
+ NamedNodeMap attributes = jspElement.getAttributes();
+ if (pos == jspElement.getStartOffset()
+ || pos == jspElement.getEndStartOffset()) {
+ event.detail = lastdetail = DND.DROP_MOVE;
+ return;
+ }
+ for (int i = 0; i < attributes.getLength(); i++) {
+ Node attribute = attributes.item(i);
+ if (attribute instanceof AttrImpl) {
+ AttrImpl jspAttr = (AttrImpl) attribute;
+ ITextRegion valueRegion = jspAttr.getValueRegion();
+ if (valueRegion == null) {
+ event.detail = lastdetail = DND.DROP_NONE;
+ return;
+ }
+ int startPos = jspElement.getStartOffset()
+ + valueRegion.getStart();
+ int endPos = jspElement.getStartOffset()
+ + valueRegion.getTextEnd();
+ if (pos > startPos && pos < endPos) {
+ dropContext.setOverAttributeValue(true);
+ dropContext.setAttributeName(jspAttr.getNodeName());
+ event.detail = lastdetail = DND.DROP_MOVE;
+ return;
+ }
+ }
+ }
+ event.detail = lastdetail = DND.DROP_NONE;
+ } else if (region instanceof Text
+ && isInsideResponseRedirect((Text) region, pos
+ - region.getStartOffset())) {
+ dropContext.setOverAttributeValue(true);
+ event.detail = lastdetail = DND.DROP_MOVE;
+ } else if (region instanceof Text) {
+ event.detail = lastdetail = DND.DROP_MOVE;
+ } else if (region instanceof DocumentType) {
+ event.detail = lastdetail = DND.DROP_NONE;
+ } else if (region == null) {
+ //new place
+ event.detail = lastdetail = DND.DROP_MOVE;
+ }
+ }
+
+ public void drop(DropTargetEvent event) {
+ int offset = getPosition(event.x, event.y);
+ selectAndReveal(offset, 0);
+ dropContext.runDropCommand(JSPTextEditor.this, event);
+ }
+
+ public void dropAccept(DropTargetEvent event) {
+ }
+
+ }
+
+ private int getPosition(int x, int y) {
+ try {
+ ISourceViewer v = getSourceViewer();
+ StyledText t = v.getTextWidget();
+ Point pp = t.toControl(x, y);
+ x = pp.x;
+ y = pp.y;
+ int lineIndex = (t.getTopPixel() + y) / t.getLineHeight();
+ if (lineIndex >= t.getLineCount()) {
+ return t.getCharCount();
+ } else {
+ int c = 0;
+ try {
+ c = t.getOffsetAtLocation(new Point(x, y));
+ if (c < 0)
+ c = 0;
+ } catch (Exception ex) {
+ c = t.getOffsetAtLine(lineIndex + 1)
+ - (t.getLineDelimiter() == null ? 0 : t
+ .getLineDelimiter().length());
+ }
+ return c;
+ }
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ public String[] getConfigurationPoints() {
+ String contentTypeIdentifierID = null;
+ if (getModel() != null)
+ contentTypeIdentifierID = getModel().getContentTypeIdentifier();
+ return ConfigurationPointCalculator.getConfigurationPoints(this,
+ contentTypeIdentifierID, ConfigurationPointCalculator.SOURCE,
+ StructuredTextEditor.class);
+ }
+
+ public void formatTextRegion(IDocument document, IRegion region) {
+ SourceViewerConfiguration conf = getSourceViewerConfiguration();
+
+ if (conf instanceof StructuredTextViewerConfiguration) {
+ StructuredTextViewerConfiguration stvc = (StructuredTextViewerConfiguration) conf;
+ IContentFormatter f = stvc.getContentFormatter(getSourceViewer());
+ f.format(document, region);
+ }
+ }
+
+ Point storedSelection = new Point(0, 0);
+
+ protected void handleCursorPositionChanged() {
+ super.handleCursorPositionChanged();
+ ISelection selection = getSelectionProvider().getSelection();
+ Point p = getTextViewer().getTextWidget().getSelection();
+ if (storedSelection == null || !storedSelection.equals(p)) {
+ storedSelection = p;
+ if (selection instanceof ITextSelection) {
+ ITextSelection ts = (ITextSelection) selection;
+ if (ts.getLength() == 0) {
+ if (vpeController != null) {
+ vpeController
+ .selectionChanged(new SelectionChangedEvent(
+ getSelectionProvider(),
+ getSelectionProvider().getSelection()));
+ }
+ }
+ }
+ }
+ }
+
+ static int firingSelectionFailedCount = 0;
+
+ private class OutlinePageListener implements IDoubleClickListener,
+ ISelectionChangedListener {
+ public void doubleClick(DoubleClickEvent event) {
+ if (event.getSelection().isEmpty())
+ return;
+
+ int start = -1;
+ int length = 0;
+ if (event.getSelection() instanceof IStructuredSelection) {
+ ISelection currentSelection = getSelectionProvider()
+ .getSelection();
+ if (currentSelection instanceof IStructuredSelection) {
+ Object current = ((IStructuredSelection) currentSelection)
+ .toArray();
+ Object newSelection = ((IStructuredSelection) event
+ .getSelection()).toArray();
+ if (!current.equals(newSelection)) {
+ IStructuredSelection selection = (IStructuredSelection) event
+ .getSelection();
+ Object o = selection.getFirstElement();
+ if (o instanceof IndexedRegion) {
+ start = ((IndexedRegion) o).getStartOffset();
+ length = ((IndexedRegion) o).getEndOffset() - start;
+ } else if (o instanceof ITextRegion) {
+ start = ((ITextRegion) o).getStart();
+ length = ((ITextRegion) o).getEnd() - start;
+ } else if (o instanceof IRegion) {
+ start = ((ITextRegion) o).getStart();
+ length = ((ITextRegion) o).getLength();
+ }
+ }
+ }
+ } else if (event.getSelection() instanceof ITextSelection) {
+ start = ((ITextSelection) event.getSelection()).getOffset();
+ length = ((ITextSelection) event.getSelection()).getLength();
+ }
+ if (start > -1) {
+ getSourceViewer().setRangeIndication(start, length, false);
+ selectAndReveal(start, length);
+ }
+ }
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (event.getSelection().isEmpty() || isFiringSelection())
+ return;
+
+ boolean ignoreSelection = false;
+ if (getSourceViewer() != null
+ && getSourceViewer() instanceof IIgnoreSelection) {
+ IIgnoreSelection is = ((IIgnoreSelection) getSourceViewer());
+ ignoreSelection = is.doesIgnore();
+ }
+ if (getSourceViewer() != null
+ && getSourceViewer().getTextWidget() != null
+ && !getSourceViewer().getTextWidget().isDisposed()
+ && !getSourceViewer().getTextWidget().isFocusControl()
+ && !ignoreSelection) {
+ int start = -1;
+ int length = 0;
+ if (event.getSelection() instanceof IStructuredSelection) {
+ ISelection current = getSelectionProvider().getSelection();
+ if (current instanceof IStructuredSelection) {
+ Object[] currentSelection = ((IStructuredSelection) current)
+ .toArray();
+ Object[] newSelection = ((IStructuredSelection) event
+ .getSelection()).toArray();
+ if (!Arrays.equals(currentSelection, newSelection)) {
+ if (newSelection.length > 0) {
+ /*
+ * No ordering is guaranteed for multiple
+ * selection
+ */
+ Object o = newSelection[0];
+ if (o instanceof IndexedRegion) {
+ start = ((IndexedRegion) o)
+ .getStartOffset();
+ int end = ((IndexedRegion) o)
+ .getEndOffset();
+ if (newSelection.length > 1) {
+ for (int i = 1; i < newSelection.length; i++) {
+ start = Math
+ .min(
+ start,
+ ((IndexedRegion) newSelection[i])
+ .getStartOffset());
+ end = Math
+ .max(
+ end,
+ ((IndexedRegion) newSelection[i])
+ .getEndOffset());
+ }
+ length = end - start;
+ }
+ } else if (o instanceof ITextRegion) {
+ start = ((ITextRegion) o).getStart();
+ int end = ((ITextRegion) o).getEnd();
+ if (newSelection.length > 1) {
+ for (int i = 1; i < newSelection.length; i++) {
+ start = Math
+ .min(
+ start,
+ ((ITextRegion) newSelection[i])
+ .getStart());
+ end = Math
+ .max(
+ end,
+ ((ITextRegion) newSelection[i])
+ .getEnd());
+ }
+ length = end - start;
+ }
+ } else if (o instanceof IRegion) {
+ start = ((IRegion) o).getOffset();
+ int end = start + ((IRegion) o).getLength();
+ if (newSelection.length > 1) {
+ for (int i = 1; i < newSelection.length; i++) {
+ start = Math.min(start,
+ ((IRegion) newSelection[i])
+ .getOffset());
+ end = Math
+ .max(
+ end,
+ ((IRegion) newSelection[i])
+ .getOffset()
+ + ((IRegion) newSelection[i])
+ .getLength());
+ }
+ length = end - start;
+ }
+ }
+ }
+ }
+ }
+ } else if (event.getSelection() instanceof ITextSelection) {
+ start = ((ITextSelection) event.getSelection()).getOffset();
+ }
+ if (start > -1) {
+ updateRangeIndication0(event.getSelection());
+ selectAndReveal(start, length);
+ }
+ }
+ }
+
+ Method m = null;
+
+ private boolean isFiringSelection() {
+ if (getSelectionProvider() == null)
+ return false;
+ if (firingSelectionFailedCount > 0)
+ return false;
+ try {
+ if (m == null) {
+ Class c = getSelectionProvider().getClass();
+ m = c.getDeclaredMethod("isFiringSelection", new Class[0]);
+ m.setAccessible(true);
+ }
+ Boolean b = (Boolean) m.invoke(getSelectionProvider(),
+ new Object[0]);
+ return b.booleanValue();
+ } catch (Exception e) {
+ firingSelectionFailedCount++;
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ return false;
+ }
+ }
+
+ private void updateRangeIndication0(ISelection selection) {
+ if (selection instanceof IStructuredSelection
+ && !((IStructuredSelection) selection).isEmpty()) {
+ Object[] objects = ((IStructuredSelection) selection).toArray();
+ if (objects.length > 0) {
+ int start = ((IndexedRegion) objects[0]).getStartOffset();
+ int end = ((IndexedRegion) objects[objects.length - 1])
+ .getEndOffset();
+ getSourceViewer().setRangeIndication(start, end - start, false);
+ } else {
+ getSourceViewer().removeRangeIndication();
+ }
+ } else {
+ if (selection instanceof ITextSelection) {
+ getSourceViewer().setRangeIndication(
+ ((ITextSelection) selection).getOffset(),
+ ((ITextSelection) selection).getLength(), false);
+ } else {
+ getSourceViewer().removeRangeIndication();
+ }
+ }
+ }
+
+ protected IExtendedAction createExtendedAction(String actionID) {
+ if (StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_DOCUMENT
+ .equals(actionID)
+ || ITextEditorActionConstants.UNDO.equals(actionID)
+ || ITextEditorActionConstants.REDO.equals(actionID)) {
+ return new ExtendedFormatAction(this, actionID);
+ }
+ return null;
+ }
+
+ protected void initializeEditor() {
+ super.initializeEditor();
+ getPreferenceStore();
+ }
+
+ public void dispose() {
+ // some things in the configuration need to clean
+ // up after themselves
+ getSourceViewer().removeTextListener(this);
+ if (fOutlinePage != null) {
+ if (fOutlinePage instanceof ConfigurableContentOutlinePage &&
fOutlinePageListener != null) {
+ ((ConfigurableContentOutlinePage)
fOutlinePage).removeDoubleClickListener(fOutlinePageListener);
+ }
+ if (fOutlinePageListener != null) {
+ fOutlinePage.removeSelectionChangedListener(fOutlinePageListener);
+ }
+ }
+ fOutlinePage=null;
+ fOutlinePageListener=null;
+ if (fOccurrenceModelUpdater != null) {
+ fOccurrenceModelUpdater.uninstall();
+ fOccurrenceModelUpdater = null;
+ }
+ super.dispose();
+ if (wtpTextJspKbConnector != null) {
+ wtpTextJspKbConnector.setTaglibManagerProvider(null);
+ wtpTextJspKbConnector = null;
+ }
+ if (listener != null)
+ listener.dispose();
+ listener = null;
+ }
+
+ BodyListenerImpl listener = null;
+
+ class BodyListenerImpl implements FileAnyImpl.BodyListener {
+ FileAnyImpl file;
+
+ BodyListenerImpl(FileAnyImpl file) {
+ this.file = file;
+ file.addListener(this);
+ }
+
+ public void bodyChanged(String body) {
+ setText(body);
+ }
+
+ public void dispose() {
+ file.removeListener(this);
+ }
+ }
+
+ public void setText(String text) {
+ if (getSourceViewer() == null
+ || getSourceViewer().getDocument() == null)
+ return;
+ String txt = getSourceViewer().getDocument().get();
+ if (txt != null && txt.length() > 0) {
+ if (!TextMerge.replace(getSourceViewer().getDocument(), text)) {
+ getSourceViewer().getDocument().set(text);
+ }
+ } else {
+ getSourceViewer().getDocument().set(text);
+ }
+ }
+
+ boolean isInsideResponseRedirect(Text textNode, int off) {
+ if (off < 0)
+ return false;
+ String START = "response.sendRedirect(\"";
+ String END = "\")";
+ String text = textNode.getNodeValue();
+ int i = 0;
+ while (i < text.length() && i < off) {
+ int i1 = text.indexOf(START, i);
+ if (i1 < 0 || i1 + START.length() > off)
+ return false;
+ int i2 = text.indexOf(END, i1 + START.length());
+ if (i2 < 0 || i2 >= off)
+ return true;
+ i = i2 + END.length();
+ }
+ return false;
+ }
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditorPageContext.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditorPageContext.java 2008-02-07
06:15:54 UTC (rev 6142)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditorPageContext.java 2008-02-07
09:57:05 UTC (rev 6143)
@@ -1,298 +1,299 @@
-/*******************************************************************************
-
-* Copyright (c) 2007 Red Hat, Inc.
-* Distributed under license by Red Hat, Inc. All rights reserved.
-* This program is made available under the terms of the
-* Eclipse Public License v1.0 which accompanies this distribution,
-* and is available at
http://www.eclipse.org/legal/epl-v10.html
-*
-* Contributors:
-* Red Hat, Inc. - initial API and implementation
-******************************************************************************/
-package org.jboss.tools.jst.jsp.jspeditor;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.jboss.tools.common.kb.KbConnectorFactory;
-import org.jboss.tools.common.kb.KbConnectorType;
-import org.jboss.tools.common.kb.wtp.WtpKbConnector;
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.jboss.tools.jst.jsp.editor.IVisualContext;
-import org.jboss.tools.jst.web.tld.TaglibData;
-import org.jboss.tools.jst.web.tld.VpeTaglibListener;
-import org.w3c.dom.Attr;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * @author Vitali (vyemialyanchyk(a)exadel.com)
- *
- * Class responsible to register TagLib data suitable for the current context
- */
-public class JSPTextEditorPageContext implements IVisualContext {
-
- protected ArrayList<TaglibData> taglibs = new ArrayList<TaglibData>();
- protected Map<String, String> taglibMap = new HashMap<String, String>();
- // this is just reference to VpeTemplateManager.templateTaglibs
- private Map<String,String> templateTaglibs = null;
- protected WtpKbConnector connector = null;
- //protected IDocument document = null;
- protected IDOMDocument document = null;
- protected Node referenceNode = null;
- protected int freeID = 0;
- protected ArrayList<VpeTaglibListener> taglibListeners = new
ArrayList<VpeTaglibListener>();
-
- public JSPTextEditorPageContext() {
- // simple tests
- //addTaglib(123, "vitaliNewUri", "vitaliNewPrefix", true);
- //addTaglib(123, "http://java.sun.com/jsf/facelets", "1xmlns:ui11",
true);
- //addTaglib(234, "http://java.sun.com/jsf/html", "2xmlns:ui22",
true);
- //addTaglib(345, "http://richfaces.org/rich", "3xmlns:ui33",
true);
- }
-
- public void clearAll() {
- taglibs.clear();
- taglibMap.clear();
- templateTaglibs = null;
- }
-
- public void dispose() {
- clearAll();
- connector = null;
- document = null;
- referenceNode = null;
- taglibListeners = null;
- }
-
- public void setReferenceNode(Node refNode) {
- if (referenceNode == refNode) {
- return;
- }
- referenceNode = refNode;
- updateTagLibs();
- }
-
- //public void setDocument(IDocument doc) {
- public void setDocument(IDOMDocument doc) {
- if (document == doc) {
- return;
- }
- document = doc;
- setReferenceNode(document);
- try {
- connector =
(WtpKbConnector)KbConnectorFactory.getIntstance().createConnector(KbConnectorType.JSP_WTP_KB_CONNECTOR,
document);
- } catch (InstantiationException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- } catch (IllegalAccessException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- } catch (ClassNotFoundException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- updateTagLibs();
- }
-
- public boolean processAttribute(Attr attr, boolean bScopePrefix) {
- if (null == attr) {
- return false;
- }
- String startStr = "xmlns:";
- String name = attr.getName();
- if (!name.startsWith(startStr)) {
- return false;
- }
- name = name.substring(startStr.length());
- addTaglib(freeID++, attr.getValue(), name, true, bScopePrefix);
- return true;
- }
-
- public boolean processNode(Node node) {
- if (null == node) {
- return false;
- }
- String nodeName = node.getNodeName();
- // example: add some filter here
- //if (!"ui:composition".equalsIgnoreCase(nodeName)) {
- // return false;
- //}
- boolean bTestRes = false;
- NamedNodeMap attribList = node.getAttributes();
- if (null != attribList) {
- for (int i = 0; i < attribList.getLength(); i++) {
- Node tmp = attribList.item(i);
- bTestRes = processAttribute((Attr)tmp, false);
- }
- }
- NodeList nodeList = node.getChildNodes();
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node tmp = nodeList.item(i);
- bTestRes = processNode(tmp);
- }
- return true;
- }
-
- public void collectDocumentTagLibs() {
- if (null == document) {
- return;
- }
- NodeList nodeList = document.getChildNodes();
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node node = nodeList.item(i);
- processNode(node);
- }
- }
-
- public boolean processNodeUp(Node node) {
- if (null == node) {
- return false;
- }
- boolean bTestRes = false;
- NamedNodeMap attribList = node.getAttributes();
- if (null != attribList) {
- for (int i = 0; i < attribList.getLength(); i++) {
- Node tmp = attribList.item(i);
- bTestRes = processAttribute((Attr)tmp, true);
- }
- }
- bTestRes = processNodeUp(node.getParentNode());
- return true;
- }
-
- public void collectRefNodeTagLibs() {
- processNodeUp(referenceNode);
- }
-
- public void updateTagLibs() {
- taglibs.clear();
- freeID = 0;
- // collect all taglibs for the document - from top tree node to leafs
- //collectDocumentTagLibs();
- // collect all taglibs starting from reference node through its parents to the top
node
- // parent's taglibs has lower priority then child taglibs
- collectRefNodeTagLibs();
- //
- for (Iterator<VpeTaglibListener> it = taglibListeners.iterator(); it.hasNext(); )
{
- it.next().taglibPrefixChanged(null);
- }
- rebuildTaglibMap();
- }
-
- private boolean rebuildTaglibMap() {
- taglibMap.clear();
- if (null == templateTaglibs) {
- return false;
- }
- Set<String> prefixSet = new HashSet<String>();
- for (int i = 0; i < taglibs.size(); i++) {
- TaglibData taglib = (TaglibData)taglibs.get(i);
- String prefix = taglib.getPrefix();
- if (!prefixSet.contains(prefix)) {
- String templatePrefix = templateTaglibs.get(taglib.getUri());
- if (templatePrefix != null) {
- taglibMap.put(prefix, templatePrefix);
- }
- prefixSet.add(prefix);
- }
- }
- return true;
- }
-
- /**
- * This is a way to use templateTaglibs from
- * org.jboss.tools.vpe.editor.template.VpeTemplateManager;
- * this is just reference to VpeTemplateManager.templateTaglibs
- * getter is prohibited here
- **/
- public void setTemplateTaglibs(Map<String,String> templateTaglibs) {
- this.templateTaglibs = templateTaglibs;
- rebuildTaglibMap();
- }
-
- /**
- * Return template taglib prefix using prefix as a key.
- * @return
- */
- public String getTemplateTaglibPrefix(String sourceTaglibPrefix) {
- return taglibMap.get(sourceTaglibPrefix);
- }
-
- // adds new tag library
- // removes tag library with id - if newUri or newPrefix is null
- public void addTaglib(int id, String newUri, String newPrefix, boolean ns, boolean
bScopePrefix) {
- if (newUri == null || newPrefix == null) {
- for (int i = 0; i < taglibs.size(); i++) {
- TaglibData taglib = (TaglibData)taglibs.get(i);
- if (taglib.getId() == id) {
- taglibs.remove(i);
- break;
- }
- }
- return;
- }
- boolean bHasSame = false;
- for (int i = 0; i < taglibs.size(); i++) {
- TaglibData taglib = (TaglibData)taglibs.get(i);
- if (taglib.getId() == id) {
- if (!newUri.equals(taglib.getUri()) || !newPrefix.equals(taglib.getPrefix())) {
- taglibs.set(i, new TaglibData(id, newUri, newPrefix, ns));
- }
- return;
- }
- if (bScopePrefix && newPrefix.equals(taglib.getPrefix())) {
- return;
- }
- if (newUri.equals(taglib.getUri()) && newPrefix.equals(taglib.getPrefix())
&& ns == taglib.isNs()) {
- bHasSame = true;
- break;
- }
- }
- if (!bHasSame) {
- taglibs.add(new TaglibData(id, newUri, newPrefix, ns));
- }
- }
-
- // implements IVisualContext
- public WtpKbConnector getConnector() {
- return connector;
- }
-
- // implements IVisualContext
- public void refreshBundleValues() {
- updateTagLibs();
- }
-
- // implements IVisualContext
- public List<TaglibData> getTagLibs() {
- List<TaglibData> clone = new ArrayList<TaglibData>();
- Iterator<TaglibData> iter = taglibs.iterator();
- while (iter.hasNext()) {
- TaglibData taglib = (TaglibData)iter.next();
- if (!taglib.inList(clone)) {
- clone.add(taglib);
- }
- }
- return clone;
- }
-
- // implements IVisualContext
- public void addTaglibListener(VpeTaglibListener listener) {
- if (taglibListeners.contains(listener)) {
- return;
- }
- taglibListeners.add(listener);
- }
-
- // implements IVisualContext
- public void removeTaglibListener(VpeTaglibListener listener) {
- taglibListeners.remove(listener);
- }
-
-}
+/*******************************************************************************
+
+* Copyright (c) 2007 Red Hat, Inc.
+* Distributed under license by Red Hat, Inc. All rights reserved.
+* This program is made available under the terms of the
+* Eclipse Public License v1.0 which accompanies this distribution,
+* and is available at
http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* Red Hat, Inc. - initial API and implementation
+******************************************************************************/
+package org.jboss.tools.jst.jsp.jspeditor;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.jboss.tools.common.kb.KbConnectorFactory;
+import org.jboss.tools.common.kb.KbConnectorType;
+import org.jboss.tools.common.kb.wtp.WtpKbConnector;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.editor.IVisualContext;
+import org.jboss.tools.jst.web.tld.TaglibData;
+import org.jboss.tools.jst.web.tld.VpeTaglibListener;
+import org.w3c.dom.Attr;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author Vitali (vyemialyanchyk(a)exadel.com)
+ *
+ * Class responsible to register TagLib data suitable for the current context
+ */
+public class JSPTextEditorPageContext implements IVisualContext {
+
+ protected ArrayList<TaglibData> taglibs = new ArrayList<TaglibData>();
+ protected Map<String, String> taglibMap = new HashMap<String, String>();
+ // this is just reference to VpeTemplateManager.templateTaglibs
+ private Map<String,String> templateTaglibs = null;
+ protected WtpKbConnector connector = null;
+ //protected IDocument document = null;
+ protected IDOMDocument document = null;
+ protected Node referenceNode = null;
+ protected int freeID = 0;
+ protected ArrayList<VpeTaglibListener> taglibListeners = new
ArrayList<VpeTaglibListener>();
+
+ public JSPTextEditorPageContext() {
+ // simple tests
+ //addTaglib(123, "vitaliNewUri", "vitaliNewPrefix", true);
+ //addTaglib(123, "http://java.sun.com/jsf/facelets", "1xmlns:ui11",
true);
+ //addTaglib(234, "http://java.sun.com/jsf/html", "2xmlns:ui22",
true);
+ //addTaglib(345, "http://richfaces.org/rich", "3xmlns:ui33",
true);
+ }
+
+ public void clearAll() {
+ taglibs.clear();
+ taglibMap.clear();
+ templateTaglibs = null;
+ }
+
+ public void dispose() {
+ clearAll();
+ connector = null;
+ document = null;
+ referenceNode = null;
+ taglibListeners = null;
+ }
+
+ public void setReferenceNode(Node refNode) {
+ if (referenceNode == refNode) {
+ return;
+ }
+ referenceNode = refNode;
+ updateTagLibs();
+ }
+
+ //public void setDocument(IDocument doc) {
+ public void setDocument(IDOMDocument doc) {
+ if (document == doc) {
+ return;
+ }
+ document = doc;
+ setReferenceNode(document);
+ try {
+ connector =
(WtpKbConnector)KbConnectorFactory.getIntstance().createConnector(KbConnectorType.JSP_WTP_KB_CONNECTOR,
document);
+ } catch (InstantiationException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ } catch (IllegalAccessException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ } catch (ClassNotFoundException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ updateTagLibs();
+ }
+
+ public boolean processAttribute(Attr attr, boolean bScopePrefix) {
+ if (null == attr) {
+ return false;
+ }
+ String startStr = "xmlns:";
+ String name = attr.getName();
+ if (!name.startsWith(startStr)) {
+ return false;
+ }
+ name = name.substring(startStr.length());
+ addTaglib(freeID++, attr.getValue(), name, true, bScopePrefix);
+ return true;
+ }
+
+ public boolean processNode(Node node) {
+ if (null == node) {
+ return false;
+ }
+ String nodeName = node.getNodeName();
+ // example: add some filter here
+ //if (!"ui:composition".equalsIgnoreCase(nodeName)) {
+ // return false;
+ //}
+ boolean bTestRes = false;
+ NamedNodeMap attribList = node.getAttributes();
+ if (null != attribList) {
+ for (int i = 0; i < attribList.getLength(); i++) {
+ Node tmp = attribList.item(i);
+ bTestRes = processAttribute((Attr)tmp, false);
+ }
+ }
+ NodeList nodeList = node.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node tmp = nodeList.item(i);
+ bTestRes = processNode(tmp);
+ }
+ return true;
+ }
+
+ public void collectDocumentTagLibs() {
+ if (null == document) {
+ return;
+ }
+ NodeList nodeList = document.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ processNode(node);
+ }
+ }
+
+ public boolean processNodeUp(Node node) {
+ if (null == node) {
+ return false;
+ }
+ boolean bTestRes = false;
+ NamedNodeMap attribList = node.getAttributes();
+ if (null != attribList) {
+ for (int i = 0; i < attribList.getLength(); i++) {
+ Node tmp = attribList.item(i);
+ bTestRes = processAttribute((Attr)tmp, true);
+ }
+ }
+ bTestRes = processNodeUp(node.getParentNode());
+ return true;
+ }
+
+ public void collectRefNodeTagLibs() {
+ processNodeUp(referenceNode);
+ }
+
+ public void updateTagLibs() {
+ taglibs.clear();
+ freeID = 0;
+ // collect all taglibs for the document - from top tree node to leafs
+ //collectDocumentTagLibs();
+ // collect all taglibs starting from reference node through its parents to the top
node
+ // parent's taglibs has lower priority then child taglibs
+ collectRefNodeTagLibs();
+ //
+ for (Iterator<VpeTaglibListener> it = taglibListeners.iterator(); it.hasNext(); )
{
+ it.next().taglibPrefixChanged(null);
+ }
+ rebuildTaglibMap();
+ }
+
+ private boolean rebuildTaglibMap() {
+ taglibMap.clear();
+ if (null == templateTaglibs) {
+ return false;
+ }
+ Set<String> prefixSet = new HashSet<String>();
+ for (int i = 0; i < taglibs.size(); i++) {
+ TaglibData taglib = (TaglibData)taglibs.get(i);
+ String prefix = taglib.getPrefix();
+ if (!prefixSet.contains(prefix)) {
+ String templatePrefix = templateTaglibs.get(taglib.getUri());
+ if (templatePrefix != null) {
+ taglibMap.put(prefix, templatePrefix);
+ }
+ prefixSet.add(prefix);
+ }
+ }
+ return true;
+ }
+
+ /**
+ * This is a way to use templateTaglibs from
+ * org.jboss.tools.vpe.editor.template.VpeTemplateManager;
+ * this is just reference to VpeTemplateManager.templateTaglibs
+ * getter is prohibited here
+ **/
+ public void setTemplateTaglibs(Map<String,String> templateTaglibs) {
+ this.templateTaglibs = templateTaglibs;
+ rebuildTaglibMap();
+ }
+
+ /**
+ * Return template taglib prefix using prefix as a key.
+ * @return
+ */
+ public String getTemplateTaglibPrefix(String sourceTaglibPrefix) {
+ return taglibMap.get(sourceTaglibPrefix);
+ }
+
+ // adds new tag library
+ // removes tag library with id - if newUri or newPrefix is null
+ public void addTaglib(int id, String newUri, String newPrefix, boolean ns, boolean
bScopePrefix) {
+ if (newUri == null || newPrefix == null) {
+ for (int i = 0; i < taglibs.size(); i++) {
+ TaglibData taglib = (TaglibData)taglibs.get(i);
+ if (taglib.getId() == id) {
+ taglibs.remove(i);
+ break;
+ }
+ }
+ return;
+ }
+ boolean bHasSame = false;
+ for (int i = 0; i < taglibs.size(); i++) {
+ TaglibData taglib = (TaglibData)taglibs.get(i);
+ if (taglib.getId() == id) {
+ if (!newUri.equals(taglib.getUri()) || !newPrefix.equals(taglib.getPrefix())) {
+ taglibs.set(i, new TaglibData(id, newUri, newPrefix, ns));
+ }
+ return;
+ }
+ if (bScopePrefix && newPrefix.equals(taglib.getPrefix())) {
+ return;
+ }
+ if (newUri.equals(taglib.getUri()) && newPrefix.equals(taglib.getPrefix())
&& ns == taglib.isNs()) {
+ bHasSame = true;
+ break;
+ }
+ }
+ if (!bHasSame) {
+ taglibs.add(new TaglibData(id, newUri, newPrefix, ns));
+ }
+ }
+
+ // implements IVisualContext
+ public WtpKbConnector getConnector() {
+ return connector;
+ }
+
+ // implements IVisualContext
+ public void refreshBundleValues() {
+ updateTagLibs();
+ }
+
+ // implements IVisualContext
+ public List<TaglibData> getTagLibs() {
+ List<TaglibData> clone = new ArrayList<TaglibData>();
+ Iterator<TaglibData> iter = taglibs.iterator();
+ while (iter.hasNext()) {
+ TaglibData taglib = (TaglibData)iter.next();
+ //if (!taglib.inList(clone)) {
+ if (!clone.contains(taglib)) {
+ clone.add(taglib);
+ }
+ }
+ return clone;
+ }
+
+ // implements IVisualContext
+ public void addTaglibListener(VpeTaglibListener listener) {
+ if (taglibListeners.contains(listener)) {
+ return;
+ }
+ taglibListeners.add(listener);
+ }
+
+ // implements IVisualContext
+ public void removeTaglibListener(VpeTaglibListener listener) {
+ taglibListeners.remove(listener);
+ }
+
+}