summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Trimble2012-10-10 14:28:25 (EDT)
committerIan Trimble2012-10-10 14:28:25 (EDT)
commit20c39d07f3e4ed4d4f37495038c66de3df613ead (patch)
tree8f06c65b5b7c75015042a3e55d5f0fe9c2dbca7a
parent3cf878b66e6d60d5bbfadb0bcb1214d6f7bcbc53 (diff)
downloadwebtools.jsf-20c39d07f3e4ed4d4f37495038c66de3df613ead.zip
webtools.jsf-20c39d07f3e4ed4d4f37495038c66de3df613ead.tar.gz
webtools.jsf-20c39d07f3e4ed4d4f37495038c66de3df613ead.tar.bz2
Bug 390468 - [WPE] HTMLEditor provides many instances of a structured
model for edit that is often not released
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/model/templates/Header.javajetinc20
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/HTMLEditor.java45
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/SimpleGraphicalEditor.java33
3 files changed, 60 insertions, 38 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/model/templates/Header.javajetinc b/jsf/plugins/org.eclipse.jst.jsf.core/model/templates/Header.javajetinc
index aadfb40..006aec0 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/model/templates/Header.javajetinc
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/model/templates/Header.javajetinc
@@ -1,10 +1,10 @@
-/*******************************************************************************
- * Copyright (c) 2005 Oracle Corporation.
- * All rights reserved. This program and the accompanying materials
- * are 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:
- * Ian Trimble - initial API and implementation
- *******************************************************************************/
+/*******************************************************************************
+ * Copyright (c) 2005 Oracle Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Ian Trimble - initial API and implementation
+ *******************************************************************************/
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/HTMLEditor.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/HTMLEditor.java
index 56306c8..720470f 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/HTMLEditor.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/HTMLEditor.java
@@ -160,6 +160,8 @@ public final class HTMLEditor extends MultiPageEditorPart implements
private DesignPageActionContributor _designPageActionContributor;
+ private IStructuredModel _model;
+
// TODO:This class is never used locally
// private class TextInputListener implements ITextInputListener {
// public void inputDocumentAboutToBeChanged(IDocument oldInput,
@@ -516,7 +518,12 @@ public final class HTMLEditor extends MultiPageEditorPart implements
_log = null;
_selChangedListener = null;
_textEditor = null;
-
+
+ if (_model != null) {
+ _model.releaseFromEdit();
+ _model = null;
+ }
+
super.dispose();
}
@@ -647,10 +654,8 @@ public final class HTMLEditor extends MultiPageEditorPart implements
result = _textEditor.getAdapter(key);
}
} else if (key == IPageVariablesProvider.class) {
- IStructuredModel model = getModel();
- Object obj = ((IDOMModel)model).getDocument().getAdapterFor(
+ Object obj = ((IDOMModel)getModel()).getDocument().getAdapterFor(
IDocumentPageVariableAdapter.class);
- model.releaseFromEdit();
if (obj instanceof IPageVariablesProvider) {
return obj;
}
@@ -710,26 +715,28 @@ public final class HTMLEditor extends MultiPageEditorPart implements
}
/**
+ * Caller MUST NOT release this model, it will be released in {@link #dispose()}.
* @return the structured model
*/
public IStructuredModel getModel() {
- IStructuredModel model = null;
- if (_textEditor != null) {
- IDocumentProvider documentProvider = _textEditor.getDocumentProvider();
- if (documentProvider != null) {
- IDocument document = documentProvider.getDocument(_textEditor.getEditorInput());
- if (document instanceof IStructuredDocument) {
- IModelManager modelManager = StructuredModelManager.getModelManager();
- if (modelManager != null) {
- model = modelManager.getExistingModelForEdit(document);
- if (model == null) {
- model = modelManager.getModelForEdit((IStructuredDocument)document);
+ if (_model == null) {
+ if (_textEditor != null) {
+ IDocumentProvider documentProvider = _textEditor.getDocumentProvider();
+ if (documentProvider != null) {
+ IDocument document = documentProvider.getDocument(_textEditor.getEditorInput());
+ if (document instanceof IStructuredDocument) {
+ IModelManager modelManager = StructuredModelManager.getModelManager();
+ if (modelManager != null) {
+ _model = modelManager.getExistingModelForEdit(document);
+ if (_model == null) {
+ _model = modelManager.getModelForEdit((IStructuredDocument)document);
+ }
}
}
}
}
}
- return model;
+ return _model;
}
@@ -1052,9 +1059,7 @@ public final class HTMLEditor extends MultiPageEditorPart implements
}
} catch (Exception ex) {
result = new StringBuffer();
- IStructuredModel model = getModel();
- result.append(model.getStructuredDocument().getText());
- model.releaseFromEdit();
+ result.append(getModel().getStructuredDocument().getText());
// Error in page changing
_log.info("Error.HTMLEditor.6", ex); //$NON-NLS-1$
}
@@ -1079,7 +1084,7 @@ public final class HTMLEditor extends MultiPageEditorPart implements
* @param mode
*/
public void setDesignerMode(int mode) {
- boolean modeWasSourceOnly = (_mode == MODE_SOURCE);
+ boolean modeWasSourceOnly = (_mode == MODE_SOURCE && _mode != mode);
if (_sashEditorPart != null && _mode != mode) {
switch (mode) {
case MODE_SASH_HORIZONTAL:
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/SimpleGraphicalEditor.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/SimpleGraphicalEditor.java
index a013094..3813c8e 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/SimpleGraphicalEditor.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/SimpleGraphicalEditor.java
@@ -39,6 +39,7 @@ import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.commands.ActionHandler;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -82,9 +83,11 @@ import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionContext;
+import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.wst.sse.core.internal.PropagatingAdapter;
import org.eclipse.wst.sse.core.internal.provisional.IModelStateListener;
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
@@ -184,7 +187,6 @@ public class SimpleGraphicalEditor extends GraphicalEditorWithFlyoutPalette impl
public void dispose() {
if (_model != null) {
_model.getUndoManager().disconnect(this);
- _model.releaseFromEdit();
}
_paletteViewerPage = null;
@@ -262,6 +264,22 @@ public class SimpleGraphicalEditor extends GraphicalEditorWithFlyoutPalette impl
((UpdateAction) action).update();
}
+ private void activateActionHandler(final IAction action) {
+ if (action != null) {
+ final IWorkbenchPartSite site = getSite();
+ if (site != null) {
+ final IHandlerService service =
+ (IHandlerService) site.getService(IHandlerService.class);
+ if (service != null) {
+ final String commandId = action.getId();
+ if (commandId != null) {
+ service.activateHandler(commandId, new ActionHandler(action));
+ }
+ }
+ }
+ }
+ }
+
/*
* (non-Javadoc)
*
@@ -282,7 +300,7 @@ public class SimpleGraphicalEditor extends GraphicalEditorWithFlyoutPalette impl
.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO_DISABLED));
action.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_UNDO);
action.setId(IWorkbenchCommandConstants.EDIT_UNDO);
- getSite().getKeyBindingService().registerAction(action);
+ activateActionHandler(action);
registry.registerAction(action);
action = new DesignerUndoRedoAction(false, this);
@@ -292,7 +310,7 @@ public class SimpleGraphicalEditor extends GraphicalEditorWithFlyoutPalette impl
.getImageDescriptor(ISharedImages.IMG_TOOL_REDO_DISABLED));
action.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_REDO);
action.setId(IWorkbenchCommandConstants.EDIT_REDO);
- getSite().getKeyBindingService().registerAction(action);
+ activateActionHandler(action);
registry.registerAction(action);
action = new DeleteAction(this);
@@ -302,7 +320,7 @@ public class SimpleGraphicalEditor extends GraphicalEditorWithFlyoutPalette impl
.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
action.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_DELETE);
action.setId(IWorkbenchCommandConstants.EDIT_DELETE);
- getSite().getKeyBindingService().registerAction(action);
+ activateActionHandler(action);
this.getSelectionActions().add(action.getId());
registry.registerAction(action);
@@ -313,7 +331,7 @@ public class SimpleGraphicalEditor extends GraphicalEditorWithFlyoutPalette impl
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
action.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_COPY);
action.setId(IWorkbenchCommandConstants.EDIT_COPY);
- getSite().getKeyBindingService().registerAction(action);
+ activateActionHandler(action);
this.getSelectionActions().add(action.getId());
registry.registerAction(action);
@@ -324,7 +342,7 @@ public class SimpleGraphicalEditor extends GraphicalEditorWithFlyoutPalette impl
.getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED));
action.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_CUT);
action.setId(IWorkbenchCommandConstants.EDIT_CUT);
- getSite().getKeyBindingService().registerAction(action);
+ activateActionHandler(action);
this.getSelectionActions().add(action.getId());
registry.registerAction(action);
@@ -335,7 +353,7 @@ public class SimpleGraphicalEditor extends GraphicalEditorWithFlyoutPalette impl
.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
action.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_PASTE);
action.setId(IWorkbenchCommandConstants.EDIT_PASTE);
- getSite().getKeyBindingService().registerAction(action);
+ activateActionHandler(action);
this.getSelectionActions().add(action.getId());
registry.registerAction(action);
}
@@ -404,7 +422,6 @@ public class SimpleGraphicalEditor extends GraphicalEditorWithFlyoutPalette impl
if (_model.getUndoManager() != null)
_model.getUndoManager().disconnect(this);
_model.removeModelStateListener(_internalModelListener);
- _model.releaseFromEdit();
}
this._model = model;