Index: E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java =================================================================== --- E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java (revision 5464) +++ E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java (working copy) @@ -68,7 +68,8 @@ public class VpePageContext implements VpeTaglibManager, IVisualContext { private VpeTemplateManager templateManager; - private ArrayList taglibs = new ArrayList(); + private List taglibs = new ArrayList(); + private Set connectorDocuments = new HashSet(); private Map taglibMap = new HashMap(); private VpeTaglibListener[] taglibListeners = new VpeTaglibListener[0]; private BundleMap bundle; @@ -104,7 +105,10 @@ public void refreshConnector() { try { IDocument document = sourceBuilder.getStructuredTextViewer().getDocument(); - connector = (WtpKbConnector)KbConnectorFactory.getIntstance().createConnector(KbConnectorType.JSP_WTP_KB_CONNECTOR, document); + if (document!= null) { + connectorDocuments.add(document); + connector = (WtpKbConnector)KbConnectorFactory.getIntstance().createConnector(KbConnectorType.JSP_WTP_KB_CONNECTOR, document); + } } catch (Exception e) { VpePlugin.getPluginLog().logError(e); } @@ -130,8 +134,19 @@ } public void dispose() { + for (Iterator iterator = connectorDocuments.iterator(); iterator.hasNext();) { + IDocument document = (IDocument) iterator.next(); + KbConnectorFactory.getIntstance().removeConnector(KbConnectorType.JSP_WTP_KB_CONNECTOR, document); + } + connectorDocuments.clear(); + connectorDocuments = null; bundle.dispose(); clearAll(); + taglibListeners=null; + editPart=null; + connector=null; + sourceBuilder=null; + visualBuilder=null; } public void setTaglib(int id, String newUri, String newPrefix, boolean ns) { Index: E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java =================================================================== --- E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java (revision 5464) +++ E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java (working copy) @@ -157,7 +157,7 @@ } // The Left standalone Vertical Tool Bar - final ToolBar verBar = new ToolBar(cmpVerticalToolbar, SWT.VERTICAL|SWT.FLAT); + ToolBar verBar = new ToolBar(cmpVerticalToolbar, SWT.VERTICAL|SWT.FLAT); verBar.setLayoutData(new GridData(GridData.FILL_VERTICAL)); ToolItem item = null; @@ -231,6 +231,10 @@ editorDomEventListener.onHideTooltip(); } } + public void onDispose() { + removeDomEventListeners(); + super.onDispose(); + } }; xulRunnerEditor.setURL(INIT_URL); @@ -300,7 +304,12 @@ } public void dispose() { - removeDomEventListeners(); + if (vpeToolBarManager != null) { + vpeToolBarManager.dispose(); + vpeToolBarManager = null; + } + + //removeDomEventListeners(); if(getController()!=null) { controller.dispose(); controller=null; @@ -310,6 +319,9 @@ xulRunnerEditor = null; } + this.controller = null; + formatControllerManager.setVpeController(null); + formatControllerManager=null; super.dispose(); } @@ -488,7 +500,7 @@ } } - private void removeDomEventListeners() { + protected void removeDomEventListeners() { if (contentAreaEventTarget != null && contentAreaEventListener != null) { contentAreaEventTarget.removeEventListener(MozillaDomEventListener.CLICKEVENTTYPE, contentAreaEventListener, false); //$NON-NLS-1$ contentAreaEventTarget.removeEventListener(MozillaDomEventListener.MOUSEDOWNEVENTTYPE, contentAreaEventListener, false); //$NON-NLS-1$ @@ -502,9 +514,13 @@ contentAreaEventTarget.removeEventListener(MozillaDomEventListener.DRAGOVEREVENT, contentAreaEventListener, false);//$NON-NLS-1$ contentAreaEventTarget.removeEventListener(MozillaDomEventListener.DBLCLICK, contentAreaEventListener, false);//$NON-NLS-1$ - } - if (domDocument != null && documentEventTarget != null) { - documentEventTarget.removeEventListener(MozillaDomEventListener.KEYPRESS, contentAreaEventListener, false); //$NON-NLS-1$ + if (domDocument != null && documentEventTarget != null) { + documentEventTarget.removeEventListener(MozillaDomEventListener.KEYPRESS, contentAreaEventListener, false); //$NON-NLS-1$ + } + contentAreaEventListener.setVisualEditor(null); + contentAreaEventTarget = null; + contentAreaEventListener = null; + documentEventTarget = null; } } @@ -511,9 +527,7 @@ private void addSelectionListener() { if (contentAreaEventListener != null&&xulRunnerEditor!=null) { - nsISelection selection = xulRunnerEditor.getSelection(); - nsISelectionPrivate selectionPrivate = (nsISelectionPrivate) selection.queryInterface(nsISelectionPrivate.NS_ISELECTIONPRIVATE_IID); - selectionPrivate.addSelectionListener(contentAreaEventListener); + xulRunnerEditor.addSelectionListener(contentAreaEventListener); } } @@ -518,7 +532,7 @@ } } - private void removeSelectionListener() { + /*private void removeSelectionListener() { if (contentAreaEventListener != null&&xulRunnerEditor!=null) { nsISelection selection = xulRunnerEditor.getSelection(); @@ -525,7 +539,7 @@ nsISelectionPrivate selectionPrivate = (nsISelectionPrivate) selection.queryInterface(nsISelectionPrivate.NS_ISELECTIONPRIVATE_IID); selectionPrivate.removeSelectionListener(contentAreaEventListener); } - } + }*/ public void setSelectionRectangle(nsIDOMElement element, int resizerConstrains, boolean scroll) { if (contentAreaEventListener != null) { Index: E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaPreview.java =================================================================== --- E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaPreview.java (revision 5464) +++ E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaPreview.java (working copy) @@ -83,6 +83,10 @@ editorDomEventListener.onHideTooltip(); } } + public void onDispose() { + removeDomEventListeners(); + super.onDispose(); + } }); getXulRunnerEditor().setURL(INIT_URL); getXulRunnerEditor().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); @@ -264,4 +268,21 @@ this.sourceEditor = sourceEditor; } + public void dispose() { + setEditorDomEventListener(null); + setEditorLoadWindowListener(null); + if (pageContext != null) { + pageContext.dispose(); + pageContext=null; + } + if (getXulRunnerEditor() != null) { + getXulRunnerEditor().dispose(); + setXulRunnerEditor(null); + } + sourceDocument=null; + sourceEditor=null; + editPart=null; + //super.dispose(); + } + } \ No newline at end of file Index: E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/IVpeToolBarManager.java =================================================================== --- E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/IVpeToolBarManager.java (revision 5464) +++ E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/IVpeToolBarManager.java (working copy) @@ -41,4 +41,6 @@ * @return */ public Composite createMenuComposite(Composite parent); + + public void dispose(); } \ No newline at end of file Index: E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java =================================================================== --- E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java (revision 5464) +++ E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java (working copy) @@ -220,4 +220,19 @@ this.menuItem = menuItem; } } + + public void dispose() { + if (splitter != null) { + splitter.dispose(); + splitter=null; + } + hideMenuItem.dispose(); + + for(int i=0; i 1) return; @@ -457,12 +458,20 @@ int[] weights = loadSplitterPosition(); if (weights != null) container.setWeights(weights); - container.addWeightsChangeListener(new PropertyChangeListener() { + final PropertyChangeListener weightsChangeListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { saveSplitterPosition(container.getWeights()); } + }; + container.addWeightsChangeListener(weightsChangeListener); + container.addDisposeListener(new DisposeListener() { + + public void widgetDisposed(DisposeEvent e) { + container.removeWeightsChangeListener(weightsChangeListener); + } + }); - parent.addControlListener(new ControlListener() { + final ControlListener controlListener = new ControlListener() { public void controlMoved(ControlEvent event) { } @@ -470,20 +479,18 @@ public void controlResized(ControlEvent event) { container.layout(); } + }; + parent.addControlListener(controlListener); + parent.addDisposeListener(new DisposeListener() { + + public void widgetDisposed(DisposeEvent e) { + parent.removeControlListener(controlListener); + } + }); - visualEditor = new MozillaEditor(); - try { - visualEditor.init(getEditorSite(), getEditorInput()); - } catch (Exception e) { - VpePlugin.reportProblem(e); - } + //createVisualEditor(); - previewWebBrowser = new MozillaPreview(this, sourceEditor); - try { - previewWebBrowser.init(getEditorSite(), getEditorInput()); - } catch (Exception e) { - VpePlugin.reportProblem(e); - } + //createPreviewBrowser(); try { sourceEditor.addPropertyListener(new IPropertyListener() { @@ -499,26 +506,9 @@ if (sourceContent != null) { sourceEditor.createPartControl(sourceContent); } - if (visualEditor != null) { - visualEditor - .setEditorLoadWindowListener(new EditorLoadWindowListener() { - public void load() { - visualEditor.setEditorLoadWindowListener(null); - visualEditor.setController(new VpeController( - VpeEditorPart.this)); - selectionBar.setVpeController(visualEditor.getController()); - visualEditor.getController().setSelectionBarController(selectionBar); - try { - visualEditor.getController().init(sourceEditor, visualEditor); - } catch (Exception e) { - VpePlugin.reportProblem(e); - } - } - }); - visualEditor.createPartControl(visualContent); - } + - if (previewWebBrowser != null) { + /*if (previewWebBrowser != null) { previewWebBrowser .setEditorLoadWindowListener(new EditorLoadWindowListener() { public void load() { @@ -529,7 +519,7 @@ }); previewWebBrowser.createPartControl(previewContent); } - +*/ activeEditor = sourceEditor; sourceContent.addListener(SWT.Activate, new Listener() { @@ -596,6 +586,50 @@ cmpEd.layout(); } + public void createVisualEditor() { + visualEditor = new MozillaEditor(); + try { + visualEditor.init(getEditorSite(), getEditorInput()); + } catch (Exception e) { + VpePlugin.reportProblem(e); + } + if (visualEditor != null) { + visualEditor + .setEditorLoadWindowListener(new EditorLoadWindowListener() { + public void load() { + visualEditor.setEditorLoadWindowListener(null); + visualEditor.setController(new VpeController( + VpeEditorPart.this)); + selectionBar.setVpeController(visualEditor.getController()); + visualEditor.getController().setSelectionBarController(selectionBar); + try { + visualEditor.getController().init(sourceEditor, visualEditor); + } catch (Exception e) { + VpePlugin.reportProblem(e); + } + } + }); + visualEditor.createPartControl(visualContent); + } + } + + public void createPreviewBrowser() { + previewWebBrowser = new MozillaPreview(this, sourceEditor); + try { + previewWebBrowser.init(getEditorSite(), getEditorInput()); + previewWebBrowser + .setEditorLoadWindowListener(new EditorLoadWindowListener() { + public void load() { + previewWebBrowser.setEditorLoadWindowListener(null); + previewWebBrowser.buildDom(); + } + }); + previewWebBrowser.createPartControl(previewContent); + } catch (Exception e) { + VpePlugin.reportProblem(e); + } + } + public void setFocus() { if (activeEditor != null) { activeEditor.setFocus(); @@ -603,9 +637,9 @@ } public void dispose() { - super.dispose(); if (optionsObject != null) { optionsObject.getModel().removeModelTreeListener(listener); + listener=null; } if (activationListener != null) { IWorkbenchWindow window = getSite().getWorkbenchWindow(); @@ -626,6 +660,10 @@ visualEditor = null; } + if (previewWebBrowser != null) { + previewWebBrowser.dispose(); + previewWebBrowser=null; + } if (previewContent != null) { previewContent.dispose(); previewContent = null; @@ -635,6 +673,8 @@ selectionBar.dispose(); selectionBar = null; } + activeEditor = null; + super.dispose(); } public Object getAdapter(Class adapter) { @@ -684,6 +724,7 @@ fIsHandlingActivation = true; try { if (sourceEditor != null) { + if (visualEditor != null) if (visualEditor.getController() != null) { visualEditor.getController().refreshTemplates(); } @@ -697,7 +738,17 @@ } public VpeController getController() { + if (visualEditor == null) + return null; return visualEditor.getController(); } + public MozillaPreview getPreviewWebBrowser() { + return previewWebBrowser; + } + + public MozillaEditor getVisualEditor() { + return visualEditor; + } + } Index: E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java =================================================================== --- E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java (revision 5464) +++ E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java (working copy) @@ -27,6 +27,7 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.Path; +import org.eclipse.jface.text.IDocument; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Point; @@ -181,33 +182,38 @@ } public void buildDom(Document sourceDocument) { - includeStack = new ArrayList(); - IEditorInput input = pageContext.getEditPart().getEditorInput(); - if (input instanceof IFileEditorInput) { - IFile file = ((IFileEditorInput) input).getFile(); - if (file != null) { - includeStack.add(new VpeIncludeInfo(null, file, pageContext - .getSourceBuilder().getSourceDocument())); - } + VpeSourceDomBuilder sourceBuilder = pageContext.getSourceBuilder(); + IDocument document = sourceBuilder.getStructuredTextViewer() + .getDocument(); + if (document == null) + return; + includeStack = new ArrayList(); + IEditorInput input = pageContext.getEditPart().getEditorInput(); + if (input instanceof IFileEditorInput) { + IFile file = ((IFileEditorInput) input).getFile(); + if (file != null) { + includeStack.add(new VpeIncludeInfo(null, file, pageContext + .getSourceBuilder().getSourceDocument())); + } + } + pageContext.refreshConnector(); + pageContext.installIncludeElements(); + addChildren(null, sourceDocument, visualContentArea); + registerNodes(new VpeNodeMapping(sourceDocument, visualContentArea)); } - pageContext.refreshConnector(); - pageContext.installIncludeElements(); - addChildren(null, sourceDocument, visualContentArea); - registerNodes(new VpeNodeMapping(sourceDocument, visualContentArea)); - } public void rebuildDom(Document sourceDocument) { - cleanHead(); - domMapping.clear(visualContentArea); - pageContext.clearAll(); - refreshExternalLinks(); - pageContext.getBundle().refreshRegisteredBundles(); + cleanHead(); + domMapping.clear(visualContentArea); + pageContext.clearAll(); + refreshExternalLinks(); + pageContext.getBundle().refreshRegisteredBundles(); - nsIDOMNodeList children = visualContentArea.getChildNodes(); - long len = children.getLength(); - for (long i = len - 1; i >= 0; i--) { - visualContentArea.removeChild(children.item(i)); - } + nsIDOMNodeList children = visualContentArea.getChildNodes(); + long len = children.getLength(); + for (long i = len - 1; i >= 0; i--) { + visualContentArea.removeChild(children.item(i)); + } if (sourceDocument != null) { buildDom(sourceDocument); @@ -1866,11 +1872,12 @@ return (VpeIncludeInfo) includeStack.get(1); } - void dispose() { - cleanHead(); - domMapping.clear(visualContentArea); - pageContext.dispose(); - } + public void dispose() { + cleanHead(); + domMapping.clear(visualContentArea); + pageContext.dispose(); + super.dispose(); + } protected Map createXmlns(Element sourceNode) { NamedNodeMap attrs = ((Element) sourceNode).getAttributes(); Index: E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/SelectionBar.java =================================================================== --- E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/SelectionBar.java (revision 5464) +++ E:/workspace-3.3.1.1/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/SelectionBar.java (working copy) @@ -61,7 +61,7 @@ private Composite cmpBar = null; private Composite closeBar = null; - Listener selbarListener = null; + //Listener selbarListener = null; final static String PREFERENCE_STATUS_BAR_ENABLE = "yes"; final static String PREFERENCE_STATUS_BAR_DISABLE = "no"; @@ -266,6 +266,8 @@ selBar.getItem(i).removeSelectionListener(this); } } + selBar.dispose(); + selBar = null; } if (!closeSelectionBar.isDisposed()) { for (int i = 0; i < closeSelectionBar.getItemCount(); i++) { @@ -273,6 +275,12 @@ closeSelectionBar.getItem(i).removeSelectionListener(this); } } + closeSelectionBar.dispose(); + closeSelectionBar = null; + } + if (splitter != null) { + splitter.dispose(); + splitter = null; } }