JBoss Tools SVN: r14271 - in trunk: common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: yradtsevich
Date: 2009-03-19 15:05:23 -0400 (Thu, 19 Mar 2009)
New Revision: 14271
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropData.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropUtils.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
Log:
RESOLVED - issue JBIDE-3985: java.lang.NullPointerException when DND external image file into Visual Pane
https://jira.jboss.org/jira/browse/JBIDE-3985
Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropData.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropData.java 2009-03-19 18:54:39 UTC (rev 14270)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropData.java 2009-03-19 19:05:23 UTC (rev 14271)
@@ -27,7 +27,7 @@
private ISourceViewer fViewer;
private ISelectionProvider fProvider;
private String fMimeType;
- private String fData;
+ private String fMimeData;
private IDropCommand fDropCommand = null;
private Node container = null;
private String attributeName = null;
@@ -56,7 +56,7 @@
/**
*
* @param mimeType
- * @param data
+ * @param mimeData
* @param pageContext
* @param input
* @param viewer
@@ -64,13 +64,13 @@
*/
public DropData(
String mimeType,
- String data,
+ String mimeData,
IEditorInput input,
ISourceViewer viewer,
ISelectionProvider provider
) {
fMimeType = mimeType;
- fData = data;
+ fMimeData = mimeData;
fInput = input;
fViewer = viewer;
fProvider = provider;
@@ -89,14 +89,14 @@
*
*/
public String getMimeData() {
- return fData;
+ return fMimeData;
}
/**
*
*/
- public void setMimeData(String data) {
- fData = data;
+ public void setMimeData(String mimeData) {
+ fMimeData = mimeData;
}
/**
Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropUtils.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropUtils.java 2009-03-19 18:54:39 UTC (rev 14270)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropUtils.java 2009-03-19 19:05:23 UTC (rev 14271)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.common.model.ui.editors.dnd;
+import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -204,4 +205,17 @@
}
return container;
}
+
+ /**
+ * If it is possible, then converts given {@code path} into URL,
+ * otherwise returns {@code path} unchanged
+ * @return
+ */
+ public static String convertPathToUrl(String path) {
+ try {
+ return new File(path).toURL().toString();
+ } catch (MalformedURLException e) {
+ return path;
+ }
+ }
}
\ No newline at end of file
Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java 2009-03-19 18:54:39 UTC (rev 14270)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java 2009-03-19 19:05:23 UTC (rev 14271)
@@ -34,6 +34,7 @@
import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
import org.jboss.tools.common.model.ui.dnd.VpeDnDEvent;
import org.jboss.tools.common.model.ui.dnd.VpeTextDropAction;
+import org.jboss.tools.common.model.ui.editors.dnd.DropUtils;
import org.jboss.tools.common.model.ui.editors.dnd.FileTagProposalLoader;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.jst.web.tld.TLDUtil;
@@ -119,12 +120,10 @@
private String getURL(TypedEvent event) {
String[] s = (String[])event.data;
- if(s == null || s.length == 0) return null;
- File f = new File(s[0]);
- try {
- return f.toURL().toString();
- } catch (MalformedURLException e) {
- return s[0];
+ if(s == null || s.length == 0) {
+ return null;
+ } else {
+ return DropUtils.convertPathToUrl(s[0]);
}
}
private File getFile(TypedEvent event) {
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2009-03-19 18:54:39 UTC (rev 14270)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2009-03-19 19:05:23 UTC (rev 14271)
@@ -1,2758 +1,2764 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.vpe.editor;
-
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.bindings.Binding;
-import org.eclipse.jface.bindings.keys.KeySequence;
-import org.eclipse.jface.bindings.keys.KeyStroke;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.source.ISourceViewer;
-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.SWT;
-import org.eclipse.swt.custom.LineStyleEvent;
-import org.eclipse.swt.custom.LineStyleListener;
-import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.dnd.Clipboard;
-import org.eclipse.swt.events.MenuEvent;
-import org.eclipse.swt.events.MenuListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.internal.keys.WorkbenchKeyboard;
-import org.eclipse.ui.keys.IBindingService;
-import org.eclipse.ui.progress.UIJob;
-import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
-import org.eclipse.wst.sse.core.internal.model.ModelLifecycleEvent;
-import org.eclipse.wst.sse.core.internal.provisional.IModelLifecycleListener;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.sse.ui.StructuredTextEditor;
-import org.eclipse.wst.sse.ui.internal.view.events.INodeSelectionListener;
-import org.eclipse.wst.sse.ui.internal.view.events.ITextSelectionListener;
-import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
-import org.eclipse.wst.sse.ui.internal.view.events.TextSelectionChangedEvent;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.jboss.tools.common.el.core.ELReferenceList;
-import org.jboss.tools.common.model.XModel;
-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.options.PreferenceModelUtilities;
-import org.jboss.tools.common.model.project.IModelNature;
-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.IDNDTextEditor;
-import org.jboss.tools.common.model.ui.editors.dnd.context.InnerDragBuffer;
-import org.jboss.tools.common.model.ui.util.ModelUtilities;
-import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
-import org.jboss.tools.common.model.util.EclipseResourceUtil;
-import org.jboss.tools.common.model.util.XModelTreeListenerSWTSync;
-import org.jboss.tools.common.resref.core.ResourceReferenceListListener;
-import org.jboss.tools.jst.jsp.editor.IJSPTextEditor;
-import org.jboss.tools.jst.jsp.editor.IVisualController;
-import org.jboss.tools.jst.jsp.preferences.VpePreference;
-import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
-import org.jboss.tools.jst.web.project.WebProject;
-import org.jboss.tools.jst.web.tld.TLDUtil;
-import org.jboss.tools.jst.web.tld.URIConstants;
-import org.jboss.tools.vpe.VpeDebug;
-import org.jboss.tools.vpe.VpePlugin;
-import org.jboss.tools.vpe.dnd.DndUtil;
-import org.jboss.tools.vpe.editor.bundle.BundleMap;
-import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
-import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
-import org.jboss.tools.vpe.editor.menu.MenuCreationHelper;
-import org.jboss.tools.vpe.editor.mozilla.EditorDomEventListener;
-import org.jboss.tools.vpe.editor.mozilla.MozillaDropInfo;
-import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
-import org.jboss.tools.vpe.editor.selection.VpeSelectionController;
-import org.jboss.tools.vpe.editor.selection.VpeSelectionHelper;
-import org.jboss.tools.vpe.editor.template.IKeyEventHandler;
-import org.jboss.tools.vpe.editor.template.ISelectionManager;
-import org.jboss.tools.vpe.editor.template.KeyEventManager;
-import org.jboss.tools.vpe.editor.template.SelectionManager;
-import org.jboss.tools.vpe.editor.template.VpeIncludeList;
-import org.jboss.tools.vpe.editor.template.VpeTemplateListener;
-import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
-import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
-import org.jboss.tools.vpe.editor.util.Constants;
-import org.jboss.tools.vpe.editor.util.DocTypeUtil;
-import org.jboss.tools.vpe.editor.util.SelectionUtil;
-import org.jboss.tools.vpe.editor.util.VisualDomUtil;
-import org.jboss.tools.vpe.editor.util.VpeDndUtil;
-import org.jboss.tools.vpe.messages.VpeUIMessages;
-import org.jboss.tools.vpe.resref.core.AbsoluteFolderReferenceList;
-import org.jboss.tools.vpe.resref.core.CSSReferenceList;
-import org.jboss.tools.vpe.resref.core.RelativeFolderReferenceList;
-import org.jboss.tools.vpe.resref.core.TaglibReferenceList;
-import org.jboss.tools.vpe.selbar.SelectionBar;
-import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
-import org.mozilla.interfaces.nsIDOMDocument;
-import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMEvent;
-import org.mozilla.interfaces.nsIDOMKeyEvent;
-import org.mozilla.interfaces.nsIDOMMouseEvent;
-import org.mozilla.interfaces.nsIDOMMutationEvent;
-import org.mozilla.interfaces.nsIDOMNode;
-import org.mozilla.interfaces.nsIFile;
-import org.mozilla.interfaces.nsISelection;
-import org.mozilla.interfaces.nsISelectionListener;
-import org.mozilla.interfaces.nsISupports;
-import org.mozilla.interfaces.nsISupportsCString;
-import org.mozilla.interfaces.nsISupportsString;
-import org.mozilla.xpcom.Mozilla;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-public class VpeController implements INodeAdapter, IModelLifecycleListener,
- INodeSelectionListener, ITextSelectionListener, SelectionListener,
- EditorDomEventListener, VpeTemplateListener, XModelTreeListener,
- ResourceReferenceListListener, ISelectionChangedListener,
- IVisualController {
-
- private boolean visualEditorVisible = true;
- private boolean synced = true;
- StructuredTextEditor sourceEditor;
- private MozillaEditor visualEditor;
- // MozillaBrowser browser;
- XulRunnerEditor xulRunnerEditor;
- // TODO Sergey Vasilyev figure out with nsIPressShell
- // private nsIPresShell presShell;
- private VpeSelectionController visualSelectionController;
- VpeDomMapping domMapping;
- private VpeSourceDomBuilder sourceBuilder;
- private VpeVisualDomBuilder visualBuilder;
- /** @deprecated */
- private VpeSelectionBuilder selectionBuilder;
- // private VpeVisualKeyHandler visualKeyHandler;
- private ActiveEditorSwitcher switcher = new ActiveEditorSwitcher();
- private Attr lastRemovedAttr;
- private String lastRemovedAttrName;
- private boolean mouseUpSelectionReasonFlag;
- private boolean mouseDownSelectionFlag;
- private boolean sourceChangeFlag;
- private VpePageContext pageContext;
- private BundleMap bundle;
- private VpeEditorPart editPart;
- private static final int LEFT_BUTTON = 0;
-
- private CSSReferenceList cssReferenceListListener;
- private TaglibReferenceList taglibReferenceListListener;
- private ELReferenceList elReferenceListListener;
- private AbsoluteFolderReferenceList absoluteFolderReferenceListListener;
- private RelativeFolderReferenceList relativeFolderReferenceListListener;
- private VpeIncludeList includeList = new VpeIncludeList();
- private VpeVisualInnerDragInfo innerDragInfo = null;
- private FormatControllerManager toolbarFormatControllerManager = null;
- private SelectionBar selectionBar = null;
- private XModelTreeListenerSWTSync optionsListener;
- // Added by Max Areshkau Fix for JBIDE-1479
- private UIJob job = null;
- private UIJob uiJob;
- // JBIDE-675, visual refresh job
- private UIJob visualRefreshJob;
- private UIJob reinitJob;
-
- /**
- * Added by Max Areshkau JBIDE-675, stores information about modification
- * events
- */
- private LinkedList<VpeEventBean> changeEvents;
-
- Shell tip;
-
- /**
- * selectionManager is used for management of selection
- */
- private ISelectionManager selectionManager;
-
- /**
- * keyEventHandler is used for management of key events
- */
- private IKeyEventHandler keyEventHandler;
-
- public final static String MODEL_FLAVOR = ModelTransfer.MODEL;
- //contains vpe update delau time in miliseconds
- private int vpeUpdateDelayTime;
-
- public VpeController(VpeEditorPart editPart) {
-
- this.editPart = editPart;
- dropWindow = new VpeDropWindow(editPart.getSite().getShell());
- }
-
- void init(StructuredTextEditor sourceEditor, MozillaEditor visualEditor) {
- this.sourceEditor = sourceEditor;
- if (sourceEditor instanceof IJSPTextEditor) {
- ((IJSPTextEditor) sourceEditor).setVPEController(this);
- dropWindow.setEditor((IJSPTextEditor) sourceEditor);
- }
- this.visualEditor = visualEditor;
- visualEditor.setController(this);
- bundle = new BundleMap();
- bundle.init(sourceEditor);
- pageContext = new VpePageContext(bundle, editPart);
- domMapping = new VpeDomMapping(pageContext);
- sourceBuilder = new VpeSourceDomBuilder(domMapping, this,
- VpeTemplateManager.getInstance(), sourceEditor, pageContext);
- visualBuilder = new VpeVisualDomBuilder(domMapping, this, visualEditor, pageContext);
- pageContext.setSourceDomBuilder(sourceBuilder);
- pageContext.setVisualDomBuilder(visualBuilder);
- IDOMModel sourceModel = (IDOMModel) getModel();
- if (sourceModel == null) {
- return;
- }
- sourceModel.addModelLifecycleListener(this);
-
- IEditorInput editorInput = pageContext.getEditPart().getEditorInput();
- if(editorInput instanceof IFileEditorInput) {
- XModel xm = null;
- IProject project = ((IFileEditorInput) editorInput).getFile()
- .getProject();
- IModelNature mn = EclipseResourceUtil.getModelNature(project);
- if (mn != null) {
- xm = mn.getModel();
- }
- if (xm != null) {
- WebProject.getInstance(xm).getTaglibMapping().revalidate(
- WebAppHelper.getWebApp(xm));
- }
- }
-
- IDOMDocument sourceDocument = sourceModel.getDocument();
- // FIXED FOR JBIDE-3799 by sdzmitrovich, moved calling of this method to buid dom
- // visualBuilder.refreshExternalLinks();
- visualBuilder.buildDom(sourceDocument);
-
- VpeTemplateManager.getInstance().addTemplateListener(this);
-
- xulRunnerEditor = visualEditor.getXulRunnerEditor();
- // TODO Sergey Vasilyev figure out with nsIPressShell
- // presShell = browser.getPresShell();
-
- //initialization visual selection controller
- visualSelectionController = new VpeSelectionController(visualEditor.getEditor().getSelectionController());
-
- selectionBuilder = new VpeSelectionBuilder(domMapping, sourceBuilder,
- visualBuilder, visualSelectionController);
-
- selectionManager = new SelectionManager(pageContext,
- sourceEditor, visualSelectionController);
-
- keyEventHandler = new KeyEventManager(sourceEditor, domMapping,
- pageContext);
-
- // glory
- ISelectionProvider provider = sourceEditor.getSelectionProvider();
- // Max Areshkau JBIDE-1105 If selection event received after selection
- // in
- // visual part we lost focus of selection, so we should process
- // selection event
- // in time of selection
- // if (provider instanceof IPostSelectionProvider)
- // ((IPostSelectionProvider)
- // provider).addPostSelectionChangedListener(this);
- // else
- provider.addSelectionChangedListener(this);
-
- // ViewerSelectionManager selectionManager =
- // sourceEditor.getViewerSelectionManager();
- // selectionManager.addNodeSelectionListener(this);
- // selectionManager.addTextSelectionListener(this);
- StyledText textWidget = VpeSelectionHelper
- .getSourceTextWidget(sourceEditor);
- if (textWidget != null) {
- textWidget.addSelectionListener(this);
- }
-
- visualEditor.setEditorDomEventListener(this);
- switcher.initActiveEditor();
-
- if (optionsListener == null) {
- XModelObject optionsObject = ModelUtilities.getPreferenceModel()
- .getByPath(VpePreference.EDITOR_PATH);
- optionsListener = new XModelTreeListenerSWTSync(this);
- optionsObject.getModel().addModelTreeListener(optionsListener);
- }
-
- cssReferenceListListener = CSSReferenceList.getInstance();
- cssReferenceListListener.addChangeListener(this);
-
- taglibReferenceListListener = TaglibReferenceList.getInstance();
- taglibReferenceListListener.addChangeListener(this);
-
- absoluteFolderReferenceListListener = AbsoluteFolderReferenceList
- .getInstance();
- absoluteFolderReferenceListListener.addChangeListener(this);
-
- relativeFolderReferenceListListener = RelativeFolderReferenceList
- .getInstance();
- relativeFolderReferenceListListener.addChangeListener(this);
-
- elReferenceListListener = ELReferenceList.getInstance();
- elReferenceListListener.addChangeListener(this);
-
- //initialization of vpe update delay time
- vpeUpdateDelayTime = 400;
- // pageContext.fireTaglibsChanged();
- }
-
- public void dispose() {
- if (job != null) {
- job.cancel();
- job = null;
- }
-
- if (uiJob != null) {
- uiJob.cancel();
- getChangeEvents().clear();
- uiJob = null;
- }
-
- if (visualRefreshJob != null) {
- visualRefreshJob.cancel();
- visualRefreshJob = null;
- }
-
- if (optionsListener != null) {
- XModelObject optionsObject = ModelUtilities.getPreferenceModel().getByPath(VpePreference.EDITOR_PATH);
- optionsObject.getModel().removeModelTreeListener(optionsListener);
- optionsListener.dispose();
- optionsListener = null;
- }
- IDOMModel sourceModel = (IDOMModel) getModel();
- if (sourceModel != null) {
- sourceModel.removeModelLifecycleListener(this);
- }
- switcher.destroyActiveEditor();
- switcher = null;
-
- VpeTemplateManager.getInstance().removeTemplateListener(this);
-
- if (visualBuilder != null) {
- visualBuilder.dispose();
- visualBuilder = null;
- }
- sourceBuilder = null;
- if (sourceEditor != null) {
- // glory
- ISelectionProvider provider = sourceEditor.getSelectionProvider();
- provider.removeSelectionChangedListener(this);
- // ViewerSelectionManager selectionManager =
- // sourceEditor.getViewerSelectionManager();
- // selectionManager.removeNodeSelectionListener(this);
- // selectionManager.removeTextSelectionListener(this);
- StyledText textWidget = VpeSelectionHelper
- .getSourceTextWidget(sourceEditor);
- if (textWidget != null) {
- textWidget.removeSelectionListener(this);
- }
- ((IJSPTextEditor) sourceEditor).setVPEController(null);
-
- }
- if (dropWindow != null) {
- dropWindow.setEditor(null);
- }
- if (visualEditor != null) {
- visualEditor.setEditorDomEventListener(null);
- if (visualSelectionController != null) {
-// visualSelectionController.Release();
- visualSelectionController = null;
- }
- // TODO Sergey Vasilyev figure out with Press Shell
- // if (presShell != null) {
- // presShell.Release();
- // presShell = null;
- // }
- visualEditor = null;
- }
-
- if (cssReferenceListListener != null) {
- cssReferenceListListener.removeChangeListener(this);
- }
- if (taglibReferenceListListener != null) {
- taglibReferenceListListener.removeChangeListener(this);
- }
- if (absoluteFolderReferenceListListener != null) {
- absoluteFolderReferenceListListener.removeChangeListener(this);
- }
- if(elReferenceListListener!=null){
- elReferenceListListener.removeChangeListener(this);
- }
- if (relativeFolderReferenceListListener != null) {
- relativeFolderReferenceListListener.removeChangeListener(this);
- }
- toolbarFormatControllerManager = null;
- }
-
- // INodeAdapter implementation
- public boolean isAdapterForType(Object type) {
- return type == this;
- }
-
- // FIX Fox JBIDE-1479 added by Max Areshkau
- public void notifyChanged(final INodeNotifier notifier,
- final int eventType, final Object feature, final Object oldValue,
- final Object newValue, final int pos) {
- if (!isVisualEditorVisible()) {
- setSynced(false);
- return;
- }
- // start job when we modify file in ui thread, without this code
- // changes will be applied with 1 second delay
- Display display = null;
- if (PlatformUI.isWorkbenchRunning())
- display = PlatformUI.getWorkbench().getDisplay();
-
- if (display != null && (Thread.currentThread() == display.getThread())) {
- getChangeEvents().addLast(
- new VpeEventBean(notifier, eventType, feature, oldValue,
- newValue, pos));
- if (uiJob == null) {
- uiJob = new UIJob(VpeUIMessages.VPE_UPDATE_JOB_TITLE) {
- @Override
- public IStatus runInUIThread(IProgressMonitor monitor) {
- monitor.beginTask(VpeUIMessages.VPE_UPDATE_JOB_TITLE, 100);
- while (getChangeEvents().size() > 0) {
- monitor.worked((int) (100 / getChangeEvents().size()));
- VpeEventBean eventBean = getChangeEvents().getFirst();
- if (monitor.isCanceled()) {
- /*
- * Yahor Radtsevich: the following line is commented
- * as fix of JBIDE-3758: VPE autorefresh is broken in some cases.
- * Now if the change events queue should be cleared, the user have to do it explicitly.
- */
- // getChangeEvents().clear();
-
- return Status.CANCEL_STATUS;
- }
- try {
- notifyChangedInUiThread(
- eventBean.getNotifier(), eventBean
- .getEventType(), eventBean
- .getFeature(), eventBean
- .getOldValue(), eventBean
- .getNewValue(), eventBean
- .getPos());
- } catch (VpeDisposeException ex) {
- // JBIDE-675 we will get this exception if user
- // close editor,
- // when update visual editor job is running, we
- // shoud ignore this
- // exception
- break;
- } catch (NullPointerException ex) {
- if (switcher != null) {
- throw ex;
- } else {
- // class was disposed and exception result
- // of that we can't stop
- // refresh job in time, so we just ignore
- // this exception
- }
- }
- getChangeEvents().remove(eventBean);
- }
- // cause is to lock calls others events
- if (switcher != null &&
- switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE))
- try {
- sourceSelectionChanged();
- /*
- * https://jira.jboss.org/jira/browse/JBIDE-3619
- * VpeViewUpdateJob takes place after toolbar selection have been updated.
- * New nodes haven't been put into dom mapping
- * thus toolbar becomes desabled.
- * Updating toolbar state here takes into account updated vpe nodes.
- */
- if (toolbarFormatControllerManager != null) {
- toolbarFormatControllerManager.selectionChanged();
- }
- } finally {
- switcher.stopActiveEditor();
- }
- monitor.done();
- return Status.OK_STATUS;
- }
- };
- }
-
- if (uiJob.getState() != Job.RUNNING) {
- uiJob.setPriority(Job.LONG);
- // Fix of JBIDE-1900
- uiJob.schedule(getVpeUpdateDelayTime());
- } else {
- uiJob.cancel();
- uiJob.schedule(getVpeUpdateDelayTime());
- setVpeUpdateDelayTime(400);
- }
-
- return;
- }
- // start job when we modify file in non ui thread
- if (job != null) {
- job.cancel();
- }
-
- job = new UIJob("NotifyChangedJob") {
- @Override
- public IStatus runInUIThread(IProgressMonitor monitor) {
- // we checks is job was canceled and if is it true we cancel job
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- } else {
- notifyChangedInUiThread(notifier, eventType, feature, oldValue, newValue, pos);
- }
- return Status.OK_STATUS;
- }
- };
- job.setPriority(Job.LONG);
- job.schedule(1000L);
- }
-
- public void notifyChangedInUiThread(INodeNotifier notifier, int eventType,
- Object feature, Object oldValue, Object newValue, int pos) {
- if (switcher == null ||
- !switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- try {
- if (VpeDebug.PRINT_SOURCE_MUTATION_EVENT) {
- printSourceEvent(notifier, eventType, feature, oldValue, newValue, pos);
- }
- if (visualBuilder == null) {
- return;
- }
- // visualBuilder.rebuildFlag = false;
- switch (eventType) {
- case INodeNotifier.CHANGE:
- sourceChangeFlag = true;
- int type = ((Node) notifier).getNodeType();
- visualEditor.hideResizer();
- visualBuilder.setSelectionRectangle(null);
- if (type == Node.TEXT_NODE) {
- boolean update = visualBuilder.setText((Node) notifier);
- visualEditor.showResizer();
- // Added by Max Areshkau JBIDE-1554
- if (!update)
- visualBuilder.updateNode((Node) notifier);
- } else if (type == Node.COMMENT_NODE) {
- if ("yes".equals(VpePreference.SHOW_COMMENTS.getValue())) { //$NON-NLS-1$
- visualBuilder.setSelectionRectangle(null);
- visualBuilder.updateNode((Node) notifier);
- }
- } else if (feature != null
- && ((Node) feature).getNodeType() == Node.ATTRIBUTE_NODE) {
- if (newValue != null) {
- String attrName = ((Attr) feature).getName();
- if ((Attr) feature == lastRemovedAttr
- && !attrName.equals(lastRemovedAttrName)) {
- lastRemovedAttr = null;
- visualBuilder.removeAttribute((Element) notifier, lastRemovedAttrName);
- }
- visualBuilder.setAttribute((Element) notifier,
- ((Attr) feature).getName(), (String) newValue);
- } else {
- lastRemovedAttr = (Attr) feature;
- lastRemovedAttrName = ((Attr) feature).getName();
- visualBuilder.removeAttribute((Element) notifier, lastRemovedAttrName);
- }
- }
- visualEditor.showResizer();
- break;
-
- case INodeNotifier.ADD:
- // we should remove all parent nodes from vpe cash
- visualBuilder.removeNode((Node) newValue);
- break;
-
- case INodeNotifier.REMOVE:
- visualBuilder.stopToggle((Node) feature);
- visualBuilder.removeNode((Node) feature);
- break;
-
- case INodeNotifier.STRUCTURE_CHANGED:
- visualEditor.hideResizer();
- visualBuilder.setSelectionRectangle(null);
- visualBuilder.updateNode((Node) notifier);
- break;
- case INodeNotifier.CONTENT_CHANGED:
- if (!sourceChangeFlag) {
- if (feature != null
- && ((Node) feature).getNodeType() == Node.TEXT_NODE) {
- // if
- // (((Node)notifier).getNodeName().equalsIgnoreCase(
- // "style"))
- // {
- visualEditor.hideResizer();
- visualBuilder.setSelectionRectangle(null);
- visualBuilder.setText((Node) feature);
- visualEditor.showResizer();
- // }
- }
- } else {
- sourceChangeFlag = false;
- }
- break;
- }
- } finally {
- // fix for jbide-675, swithcer is null when vpecontroller is
- // disposed
- if (switcher != null) {
- switcher.stopActiveEditor();
- } else {
- throw new VpeDisposeException("VpeController already disposed");
- }
- }
- }
-
- // INodeSelectionListener implementation
- public void nodeSelectionChanged(NodeSelectionChangedEvent event) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- try {
- List<?> nodes = event.getSelectedNodes();
- if (nodes != null && nodes.size() > 0) {
- Node sourceNode = (Node) nodes.get(0);
- if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>> nodeSelectionChanged sourceNode: " + //$NON-NLS-1$
- sourceNode.getNodeName() + Constants.WHITE_SPACE + event.getCaretPosition());
- }
- if (event.getSource() instanceof IContentOutlinePage) {
- sourceSelectionChanged();
- }
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- // ITextSelectionListener implementation
- // TODO Max Areshau looks like this method don't used
- public void textSelectionChanged(TextSelectionChangedEvent event) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- try {
- if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>> textSelectionChanged " + event.getSource()); //$NON-NLS-1$
- }
- // if (event.getSource() instanceof StyledText) {
- sourceSelectionChanged();
- // }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- // SelectionListener implementation
- public void widgetSelected(SelectionEvent event) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- try {
- if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>> widgetSelected"); //$NON-NLS-1$
- }
- if (event.getSource() instanceof StyledText) {
- sourceSelectionChanged();
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- public void widgetDefaultSelected(SelectionEvent event) {
- if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>> widgetDefaultSelected"); //$NON-NLS-1$
- }
- }
-
- public void sourceSelectionChanged() {
- sourceSelectionChanged(false);
- }
-
- public void sourceSelectionChanged(boolean showCaret) {
- // we should processed if we have correct view in visual editor,
- // otherwise we shouldn't process this event
- if (getChangeEvents().size() > 0) {
- return;
- }
-
-// Point range = sourceEditor.getTextViewer().getSelectedRange();
-// int anchorPosition = range.x;
-// int focusPosition = range.x + range.y;
-//
-// boolean extendFlag = range.y != 0;
-// boolean reversionFlag = extendFlag
-// && anchorPosition == VpeSelectionHelper
-// .getCaretOffset(sourceEditor);
-// if (reversionFlag) {
-// anchorPosition = focusPosition;
-// focusPosition = range.x;
-// }
-
- if (selectionManager != null)
- selectionManager.refreshVisualSelection();
-
- // VpeTemplate template = TemplateManagingUtil
- // .getTemplateBySourceSelection(pageContext, focusPosition,
- // anchorPosition);
- //
- // if (template instanceof ITemplateSelectionManager) {
- // ((ITemplateSelectionManager) template).setSelectionBySource(
- // pageContext, visualSelectionController, focusPosition,
- // anchorPosition);
- // return;
- // }
- //
- // Node focusNode = getSourceNodeAt(focusPosition);
- // if (focusNode == null) {
- // return;
- // }
- // int focusOffset = getSourceNodeOffset(focusNode, focusPosition,
- // extendFlag && !reversionFlag);
- // Node anchorNode = null;
- // int anchorOffset = 0;
- // if (extendFlag) {
- // anchorNode = getSourceNodeAt(anchorPosition);
- // anchorOffset = getSourceNodeOffset(anchorNode, anchorPosition,
- // reversionFlag);
- // } else {
- // anchorNode = focusNode;
- // anchorOffset = focusOffset;
- // }
- //
- // if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- // System.out.println("sourceSelectionChanged"); //$NON-NLS-1$
- // System.out
- // .println(" anchorNode: " + anchorNode.getNodeName() + " anchorOffset: " + anchorOffset); //$NON-NLS-1$ //$NON-NLS-2$
- // System.out
- // .println(" focusNode: " + focusNode.getNodeName() + " focusOffset: " + focusOffset + " focusPosition: " + focusPosition); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- // }
- // try {
- // if (anchorNode.getNodeType() == Node.TEXT_NODE
- // || anchorNode.getNodeType() == Node.ATTRIBUTE_NODE) {
- // String text;
- // if (anchorNode.getNodeType() == Node.TEXT_NODE) {
- // IndexedRegion region = (IndexedRegion) anchorNode;
- // text = sourceEditor.getTextViewer().getDocument().get(
- // region.getStartOffset(),
- // region.getEndOffset() - region.getStartOffset());
- // } else {
- // text = ((AttrImpl) anchorNode).getValueRegionText();
- // }
- // anchorOffset = TextUtil.visualPosition(text, anchorOffset);
- // }
- // if (focusNode.getNodeType() == Node.TEXT_NODE
- // || focusNode.getNodeType() == Node.ATTRIBUTE_NODE) {
- // IndexedRegion region = (IndexedRegion) focusNode;
- // String text;
- // if (focusNode.getNodeType() == Node.TEXT_NODE) {
- // text = sourceEditor.getTextViewer().getDocument().get(
- // region.getStartOffset(),
- // region.getEndOffset() - region.getStartOffset());
- // } else {
- // text = ((AttrImpl) focusNode).getValueRegionText();
- // }
- // focusOffset = TextUtil.visualPosition(text, focusOffset);
- // }
- // } catch (Exception ex) {
- // VpePlugin.reportProblem(ex);
- // }
- //
- // selectionBuilder.setVisualSelection(anchorNode, anchorOffset,
- // focusNode, focusOffset, reversionFlag, showCaret);
- }
-
- public void sourceSelectionToVisualSelection(boolean showCaret) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- try {
- sourceSelectionChanged(showCaret);
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- // IModelLifecycleListener implementation
- public void processPreModelEvent(ModelLifecycleEvent event) {
- }
-
- public void processPostModelEvent(ModelLifecycleEvent event) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- try {
- /*
- * Added by Max Areshkau JBIDE-1457
- * ModelLifecycleEvent.MODEL_RELEASED is generated when model in model
- * calls methods releaseFromRead() or releaseFromEdit(). When editor
- * is open he has only when href on model, so nothing can generated
- * this event.When editor closes generation of this event depends
- * from containing any service href on model or not. It's can be a
- * reason of problems on reopen file.
- *
- * We shouldn't call here rebuild dom.
- */
- if (event.getType() == ModelLifecycleEvent.MODEL_RELEASED) {
- if (VpeDebug.PRINT_SOURCE_MODEL_LIFECYCLE_EVENT) {
- System.out.println(">>> processPostModelEvent: " + event.toString()); //$NON-NLS-1$
- }
- // commented to fix org.mozilla.xpcom.XPCOMException: The function "repaint" returned an error condition (0x8000ffff)
- //visualBuilder.setSelectionRectangle(null);
- IStructuredModel model = event.getModel();
- model.removeModelLifecycleListener(this);
- IDOMModel sourceModel = (IDOMModel) getModel();
- sourceModel.addModelLifecycleListener(this);
- bundle.clearAll();
- bundle.refresh();
- //visualBuilder.setSelectionRectangle(null);
- IDOMDocument sourceDocument = sourceModel.getDocument();
- // JBIDE-1457
- // visualBuilder.rebuildDom(sourceDocument);
- // pageContext.fireTaglibsChanged();
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- // EditorDomEventListener implementation
- public void subtreeModified(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- public void nodeInserted(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- nsIDOMNode targetNode = mutationEvent.getRelatedNode();
- if (!VpeVisualDomBuilder.isAnonElement(targetNode)) {
- sourceBuilder.addNode(targetNode);
- visualBuilder.resetPseudoElement(targetNode);
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- public void nodeRemoved(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
- if (!VpeVisualDomBuilder.isAnonElement(targetNode)) {
- visualBuilder.setSelectionRectangle(null);
- sourceBuilder.removeNode(targetNode);
- visualBuilder.resetPseudoElement(targetNode);
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- public void nodeRemovedFromDocument(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- public void nodeInsertedIntoDocument(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- public void attrModified(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- public void characterDataModified(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
- printVisualEvent(mutationEvent);
- }
- nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
- sourceBuilder.setText(targetNode);
- visualBuilder.resetPseudoElement(targetNode);
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- public void notifySelectionChanged(nsIDOMDocument doc, nsISelection selection, short reason) {
- if (switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- try {
- mouseUpSelectionReasonFlag = (reason & nsISelectionListener.MOUSEUP_REASON) > 0;
- if (mouseUpSelectionReasonFlag
- // commited by Dzmitrovich - experimental
- // TODO check selection and if are appear errors then
- // uncommented next code
- // || reason == nsISelectionListener.NO_REASON
- || reason == nsISelectionListener.KEYPRESS_REASON
- || reason == nsISelectionListener.SELECTALL_REASON
- || (reason & nsISelectionListener.MOUSEDOWN_REASON) > 0) {
- if (VpeDebug.PRINT_VISUAL_SELECTION_EVENT) {
- System.out.println("<<< notifySelectionChanged: " + reason); //$NON-NLS-1$
- }
- nsIDOMNode node = SelectionUtil.getSelectedNode(selection);
- /*
- * Fixes https://jira.jboss.org/jira/browse/JBIDE-2571
- * Checking if the node is of text type was removed
- * to allow <select> node to be selected on the first click.
- */
- if (node != null) {
- selectionManager.setSelection(selection);
- }
- }
- //enables cursor on selection event
- visualSelectionController.setCaretEnabled(true);
- } finally {
- switcher.stopActiveEditor();
- }
- }
- }
-
- public void mouseDown(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- // mouseDownSelectionFlag = false;
- // VpeTemplate template = TemplateManagingUtil
- // .getTemplateByVisualSelection(pageContext, VisualDomUtil
- // .getTargetNode(mouseEvent));
- // if (template instanceof ITemplateSelectionManager) {
- // ((ITemplateSelectionManager) template).setSelectionByMouse(
- // pageContext, visualSelectionController, mouseEvent);
- // mouseDownSelectionFlag = true;
- // } else {
- // nsIDOMElement visualDragElement = selectionBuilder
- // .getDragElement(mouseEvent);
- if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
- System.out.println("<<< mouseDown targetNode: " /* //$NON-NLS-1$
- * +visualNode.
- * getNodeName()
- * + " (" +
- * visualNode +
- * ") selectedElement: "
- * +(
- * visualDragElement
- * != null ?
- * visualDragElement
- * .
- * getNodeName()
- * + " (" +
- * visualDragElement
- * + ")" : null)
- */);
- }
- //
- // if (visualDragElement != null) {
- //
- // // we shouldn't change selection when we click on <input
- // // type="text" /> element,
- // // because if we change after resizing the input element
- // // lost
- // // selection
- // // if(!(HTML.TAG_INPUT.equalsIgnoreCase(visualDragElement.
- // // getNodeName())&&
- // // HTML.ATTR_TEXT.equalsIgnoreCase(visualDragElement.
- // // getAttribute(HTML.ATTR_TYPE))
- // // &&visualDragElement.getAttribute(HTML.ATTR_TYPE)!=null))
- // // {
- //
- // selectionBuilder
- // .setVisualElementSelection(visualDragElement);
- // mouseDownSelectionFlag = true;
- // // }
- // } else {
- // selectionBuilder.setCaretAtMouse(mouseEvent);
- // }
- // }
-
- // selection will be set only if press left button
- if (mouseEvent.getButton() == LEFT_BUTTON)
- selectionManager.setSelection(mouseEvent);
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- public void mouseUp(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
-
- if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- System.out.println("<<< mouseUp"); //$NON-NLS-1$
- }
- if (mouseDownSelectionFlag) {
- mouseEvent.preventDefault();
- mouseEvent.stopPropagation();
- mouseDownSelectionFlag = false;
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- public void mouseClick(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
- if (visualNode != null) {
- if (!mouseUpSelectionReasonFlag) {
- if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- System.out.println("<<< mouseClick visualNode: " + visualNode.getNodeName() + //$NON-NLS-1$
- " (" + visualNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- if (visualBuilder.isContentArea(visualNode)) {
- // selectionBuilder.setClickContentAreaSelection();
- }
- } else {
- mouseUpSelectionReasonFlag = false;
- }
-
- if (visualBuilder.doToggle(VisualDomUtil.getTargetNode(mouseEvent))) {
- // selectionBuilder.setClickContentAreaSelection();
- }
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- public void mouseDblClick(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
- if (visualNode != null) {
- if (!sourceBuilder.openBundleEditors(visualNode)) {
- sourceBuilder.openIncludeEditor(visualNode);
- }
- if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- System.out.println("<<< mouseDblClick visualNode: " + visualNode.getNodeName() + //$NON-NLS-1$
- " (" + visualNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- public void mouseMove(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
- if (visualNode != null) {
- // if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- // System.out.println("<<< mouseMove visualNode: "
- // + visualNode.getNodeName() + " (" + visualNode
- // + ")");
- // }
- visualBuilder.setMoveCursor(mouseEvent);
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- public void keyPress(nsIDOMKeyEvent keyEvent) {
- if (VpeDebug.PRINT_VISUAL_KEY_EVENT) {
- System.out.println("<<< keyPress type: " + keyEvent.getType() + //$NON-NLS-1$
- " Ctrl: " + keyEvent.getCtrlKey() + " Shift: " + keyEvent.getShiftKey() + //$NON-NLS-1$ //$NON-NLS-2$
- " CharCode: " + keyEvent.getCharCode() + " KeyCode: " + keyEvent.getKeyCode()); //$NON-NLS-1$ //$NON-NLS-2$
- }
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- switcher.stopActiveEditor();
- return;
- }
- try {
- visualEditor.hideResizer();
- } finally {
- switcher.stopActiveEditor();
- }
- setVpeUpdateDelayTime(0);
- /*
- * adding calls of core event handlers, for example' CTR+H' or
- * 'CTRL+M' event handler dialog
- */
- boolean keyBindingPressed = false;
- Event keyboardEvent = new Event();
- /*
- * widget where event occur
- */
- keyboardEvent.widget = xulRunnerEditor.getBrowser();
-
- keyboardEvent.stateMask = (keyEvent.getAltKey() ? SWT.ALT : 0)
- | (keyEvent.getCtrlKey() ? SWT.CTRL : 0)
- | (keyEvent.getShiftKey() ? SWT.SHIFT : 0)
- | (keyEvent.getMetaKey() ? SWT.MOD1 : 0);
- keyboardEvent.x = 0;
- keyboardEvent.y = 0;
- keyboardEvent.type = SWT.KeyDown;
-
- if (keyEvent.getKeyCode() == 0) {
- keyboardEvent.keyCode = (int) keyEvent.getCharCode();
- } else {
- keyboardEvent.keyCode = (int) keyEvent.getKeyCode();
- }
- /*
- * JBIDE-1627
- */
- List<KeyStroke> possibleKeyStrokes = WorkbenchKeyboard
- .generatePossibleKeyStrokes(keyboardEvent);
- IWorkbench iWorkbench = VpePlugin.getDefault().getWorkbench();
- if (iWorkbench.hasService(IBindingService.class)) {
- IBindingService iBindingService = (IBindingService) iWorkbench
- .getService(IBindingService.class);
-
- KeySequence sequenceBeforeKeyStroke = KeySequence.getInstance();
-
- for (Iterator<KeyStroke> iterator = possibleKeyStrokes.iterator(); iterator.hasNext();) {
- KeySequence sequenceAfterKeyStroke =
- KeySequence.getInstance(sequenceBeforeKeyStroke, iterator.next());
- if (iBindingService.isPerfectMatch(sequenceAfterKeyStroke)) {
- final Binding binding = iBindingService.getPerfectMatch(sequenceAfterKeyStroke);
- if ((binding != null)
- && (binding.getParameterizedCommand() != null)
- && (binding.getParameterizedCommand().getCommand() != null)) {
- keyBindingPressed = true;
- }
- }
- }
- }
- /*
- * Sends xulrunner event to eclipse environment.
- * dmaliarevich: while fixing JBIDE-2562 I found that
- * eclipse handles key shortcuts without this notification.
- */
- // getXulRunnerEditor().getBrowser().notifyListeners(
- // keyboardEvent.type, keyboardEvent);
-
- /*
- * Fixes https://jira.jboss.org/jira/browse/JBIDE-2562
- * author: dmaliarevich
- *
- * When shortcut key is pressed do not handle this event in the
- * handler.
- */
- if (!keyBindingPressed) {
- if (keyEventHandler.handleKeyPress(keyEvent)) {
- /*
- * JBIDE-2670
- */
- keyEvent.preventDefault();
-// switcher
-// .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL);
-// try {
- /*
- * Edward
- */
- // commented by sdzmitrovich because cursor disappear after
- // trying to edit of read-only elements
- // TODO check editing and if are appear errors then
- // uncommented next code
-// sourceSelectionChanged(true);
-// visualSelectionController.setCaretEnabled(true);
-
-// } finally {
-// switcher.stopActiveEditor();
-// }
- }
- }
- }
-
- public void elementResized(nsIDOMElement element, int resizerConstrains,
- int top, int left, int width, int height) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- visualEditor.hideResizer();
- } finally {
- switcher.stopActiveEditor();
- }
- visualBuilder.resize(element, resizerConstrains, top, left, width, height);
- sourceSelectionChanged();
- }
-
- public void dragGesture(nsIDOMEvent domEvent) {
- nsIDOMMouseEvent mouseEvent =
- (nsIDOMMouseEvent) domEvent.queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID);
- boolean canDragFlag = canInnerDrag(mouseEvent);
- // start drag sessionvpe-element
- if (canDragFlag) {
- startDragSession(domEvent);
- }
- }
-
- /**
- * Calls when on when browser receive context menu event.
- *
- * @param contextFlags
- * -not used in this function, just for because this parameter
- * exist in nsIContextMenuListener
- * @param event
- * event from browser used here
- * @param node
- * where this event are occur
- */
- public void onShowContextMenu(long contextFlags, nsIDOMEvent event, nsIDOMNode node) {
- //FIXED FOR JBIDE-3072 by sdzmitrovich
-
-// nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
-// if (visualNode != null) {
- Node selectedSourceNode = null;
-
- VpeNodeMapping nodeMapping = SelectionUtil.getNodeMappingBySourceSelection(sourceEditor, domMapping);
- if (nodeMapping != null) {
- selectedSourceNode = nodeMapping.getSourceNode();
- }
-
- MenuManager menuManager = new MenuManager("#popup"); //$NON-NLS-1$
- final Menu contextMenu = menuManager.createContextMenu(visualEditor.getControl());
- contextMenu.addMenuListener(new MenuListener() {
- Menu menu = contextMenu;
- public void menuHidden(MenuEvent e) {
- Display.getCurrent().asyncExec(new Runnable() {
- public void run() {
- menu.dispose();
- }
- });
- }
- public void menuShown(MenuEvent e) {
- }
- });
-
- // create context menu
- MenuCreationHelper menuCreationHelper =
- new MenuCreationHelper(domMapping, pageContext, sourceEditor, visualEditor);
- menuCreationHelper.createMenuForNode(selectedSourceNode, menuManager, true);
-
- contextMenu.setVisible(true);
-// }
- }
-
- // VpeTemplateListener implementation
- public void templateReloaded() {
- visualRefresh();
- }
-
- public void visualRefresh() {
- if (!isVisualEditorVisible()) {
- setSynced(false);
- return;
- }
- if (uiJob != null && uiJob.getState() != Job.NONE) {
- return;
- }
- if (visualRefreshJob == null || visualRefreshJob.getState() == Job.NONE) {
- visualRefreshJob = new UIJob(VpeUIMessages.VPE_VISUAL_REFRESH_JOB) {
- @Override
- public IStatus runInUIThread(IProgressMonitor monitor) {
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- }
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return Status.CANCEL_STATUS;
- }
- try {
- monitor.beginTask(VpeUIMessages.VPE_VISUAL_REFRESH_JOB, IProgressMonitor.UNKNOWN);
- visualRefreshImpl();
- monitor.done();
- setSynced(true);
- } catch (VpeDisposeException exc) {
- // just ignore this exception
- } catch (NullPointerException ex) {
- if (switcher != null) {
- throw ex;
- } else {
- // class was disposed and exception result of
- // that we can't stop
- // refresh job in time, so we just ignore this
- // exception
- }
- } finally {
- if (switcher != null) {
- switcher.stopActiveEditor();
- }
- }
- return Status.OK_STATUS;
- }
- };
-
- visualRefreshJob.setPriority(Job.SHORT);
- visualRefreshJob.schedule();
- }
- }
-
- void visualRefreshImpl() {
- visualEditor.hideResizer();
-
- String currentDoctype = DocTypeUtil.getDoctype(visualEditor.getEditorInput());
- /*
- * https://jira.jboss.org/jira/browse/JBIDE-3591
- * Avoid using missing resource.
- */
- String visualEditorDoctype = visualEditor.getDoctype();
- if ((null != currentDoctype) && (null != visualEditorDoctype)
- && (!visualEditorDoctype.equals(currentDoctype))) {
- visualEditor.reload();
- } else {
- //Fix bugs JBIDE-2750
- visualBuilder.setSelectionRectangle(null);
- visualEditor.reload();
-// IDOMModel sourceModel = (IDOMModel) getModel();
-// if (sourceModel != null) {
-// IDOMDocument sourceDocument = sourceModel.getDocument();
-// visualBuilder.rebuildDom(sourceDocument);
-// } else {
-// visualBuilder.rebuildDom(null);
-// }
- }
- }
-
- public void preLongOperation() {
- switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL);
- }
-
- public void postLongOperation() {
- switcher.stopActiveEditor();
- visualRefresh();
- }
-
- // for debug
- private void printSourceEvent(INodeNotifier notifier, int eventType,
- Object feature, Object oldValue, Object newValue, int pos) {
- System.out.println(">>> eventType: " + INodeNotifier.EVENT_TYPE_STRINGS[eventType] + //$NON-NLS-1$
- " pos: " + pos + " notifier: " + ((Node) notifier).getNodeName() + //$NON-NLS-1$ //$NON-NLS-2$
- " hashCode: " + notifier.hashCode()); //$NON-NLS-1$
- if (feature != null) {
- if (feature instanceof Node) {
- System.out.println(" feature: " + ((Node) feature).getNodeType() + //$NON-NLS-1$
- Constants.WHITE_SPACE + ((Node) feature).getNodeName() +
- " hashCode: " + feature.hashCode()); //$NON-NLS-1$
- } else {
- System.out.println(" feature: " + feature); //$NON-NLS-1$
- }
- }
- if (oldValue != null) {
- if (oldValue instanceof Node) {
- System.out.println(" oldValue: " + ((Node) oldValue).getNodeName() + //$NON-NLS-1$
- " hashCode: " + oldValue.hashCode()); //$NON-NLS-1$
- } else {
- System.out.println(" oldValue: " + oldValue); //$NON-NLS-1$
- }
- }
- if (newValue != null) {
- if (newValue instanceof Node) {
- System.out.println(" newValue: " + ((Node) newValue).getNodeName() + //$NON-NLS-1$
- " hashCode: " + newValue.hashCode() + Constants.WHITE_SPACE + ((Node) newValue).getNodeType()); //$NON-NLS-1$
- } else {
- System.out.println(" newValue: " + newValue); //$NON-NLS-1$
- }
- }
- }
-
- private void printVisualEvent(nsIDOMEvent event) {
- System.out.print("<<< " + event.getType()); //$NON-NLS-1$
-
- if (event instanceof nsIDOMMutationEvent) {
- nsIDOMMutationEvent mutationEvent = (nsIDOMMutationEvent) event;
-
- System.out.print(" EventPhase: " + mutationEvent.getEventPhase()); //$NON-NLS-1$
-
- nsIDOMNode relatedNode = mutationEvent.getRelatedNode();
- System.out.print(" RelatedNode: " + (relatedNode == null ? null : relatedNode.getNodeName())); //$NON-NLS-1$
-
- nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
- String name = targetNode != null ? targetNode.getNodeName() : null;
- System.out.print(" TargetNode: " + name + " (" + targetNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- System.out.print(" PrevValue: " + mutationEvent.getPrevValue().trim()); //$NON-NLS-1$
- System.out.print(" NewValue: " + mutationEvent.getNewValue().trim()); //$NON-NLS-1$
- }
- System.out.println();
- }
-
- private class ActiveEditorSwitcher {
- private static final int ACTIVE_EDITOR_CANNOT = 0;
- private static final int ACTIVE_EDITOR_NONE = 1;
- private static final int ACTIVE_EDITOR_SOURCE = 2;
- private static final int ACTIVE_EDITOR_VISUAL = 3;
-
- private int type = ACTIVE_EDITOR_CANNOT;
-
- private void initActiveEditor() {
- type = ACTIVE_EDITOR_NONE;
- }
-
- private void destroyActiveEditor() {
- type = ACTIVE_EDITOR_CANNOT;
- }
-
- private boolean startActiveEditor(int newType) {
- if (type == ACTIVE_EDITOR_NONE) {
- if (newType == ACTIVE_EDITOR_SOURCE
- && editPart.getVisualMode() == VpeEditorPart.SOURCE_MODE) {
- return false;
- }
- type = newType;
- return true;
- } else {
- return false;
- }
- }
-
- private void stopActiveEditor() {
- onRefresh();
- type = ACTIVE_EDITOR_NONE;
- }
- }
-
-// void refreshBundleValues() {
-// if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
-// return;
-// }
-// try {
-// if (bundle != null) {
-// bundle.refresh();
-// if (pageContext != null) {
-// pageContext.refreshBundleValues();
-// }
-// }
-// } finally {
-// switcher.stopActiveEditor();
-// }
-// }
-//
- void refreshTemplates() {
- if (includeList.includesRefresh()) {
- visualRefresh();
- }
-
- VpeTemplateManager.getInstance().reload();
-
- if (bundle != null) {
- bundle.refresh();
- if (pageContext != null) {
- if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- try {
- pageContext.refreshBundleValues();
- } finally {
- switcher.stopActiveEditor();
- }
- }
- }
- }
-
- // implements XModelTreeListener
- public void nodeChanged(XModelTreeEvent event) {
- visualRefresh();
- }
-
- public void structureChanged(XModelTreeEvent event) {
- }
-
-// private Node getSourceNodeAt(int offset) {
-// if (sourceEditor != null && getModel() != null) {
-// IndexedRegion node = getModel().getIndexedRegion(offset);
-// if (node instanceof IDOMNode) {
-// VpeElementMapping elementMapping = domMapping
-// .getNearElementMapping((IDOMNode) node);
-// if (elementMapping != null) {
-// if (node instanceof IDOMElement) {
-// IDOMElement element = (IDOMElement) node;
-//
-// if (offset < element.getEndStartOffset()) {
-// NamedNodeMap attrs = element.getAttributes();
-// if (attrs != null) {
-// for (int i = 0; i < attrs.getLength(); i++) {
-// if (attrs.item(i) instanceof AttrImpl) {
-// AttrImpl attr = (AttrImpl) attrs.item(i);
-// if (getSourceAttributeOffset(attr, offset) != -1) {
-// String[] atributeNames = elementMapping.getTemplate().getOutputAtributeNames();
-// if (atributeNames != null
-// && atributeNames.length > 0
-// && attr.getName().equalsIgnoreCase(atributeNames[0])) {
-// return attr;
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// if (node == null) {
-// node = getModel().getIndexedRegion(offset - 1);
-// }
-// if (node instanceof Node) {
-// return (Node) node;
-// }
-// }
-// return null;
-// }
-//
-// private int getSourceNodeOffset(Node node, int pos, boolean endFlag) {
-// if (node == null)
-// return 0;
-// int start = ((IndexedRegion) node).getStartOffset();
-// int end = ((IndexedRegion) node).getEndOffset();
-//
-// switch (node.getNodeType()) {
-// case Node.ATTRIBUTE_NODE:
-// if (node instanceof AttrImpl) {
-// return getSourceAttributeOffset((AttrImpl) node, pos);
-// }
-// case Node.TEXT_NODE:
-// if (pos < start) {
-// return 0;
-// } else if (pos > end) {
-// return end - start;
-// } else {
-// return pos - start;
-// }
-// case Node.COMMENT_NODE:
-// if (pos > end) {
-// pos = end;
-// }
-// int offset = pos - start - 4;
-// return offset < 0 ? 0 : offset;
-// case Node.ELEMENT_NODE:
-// ElementImpl element = (ElementImpl) node;
-// if (element.isContainer()) {
-// if (pos < element.getStartEndOffset()) {
-// return 0;
-// } else {
-// return 1;
-// }
-// } else {
-// return endFlag ? 1 : 0;
-// }
-// default:
-// return endFlag ? 1 : 0;
-// }
-// }
-//
-// private int getSourceAttributeOffset(AttrImpl attr, int pos) {
-// if (attr.getValueRegion() != null) {
-// int start = attr.getValueRegionStartOffset();
-// String value = attr.getValueRegionText();
-// int len = value.length();
-// if (pos >= start && pos <= start + len) {
-// int offset = pos - start;
-// if (len > 1 && value.charAt(0) == '"'
-// && value.charAt(len - 1) == '"') {
-// if (offset <= 0 || offset >= len) {
-// return -1;
-// }
-// offset--;
-// }
-// return offset;
-// }
-// }
-// return -1;
-// }
-//
-// private int getSourceNodeOffset1(Node node, int pos, boolean endFlag) {
-// if (node == null)
-// return 0;
-// int start = ((IndexedRegion) node).getStartOffset();
-// int end = ((IndexedRegion) node).getEndOffset();
-//
-// switch (node.getNodeType()) {
-// case Node.ATTRIBUTE_NODE:
-// if (node instanceof AttrImpl) {
-// AttrImpl attr = (AttrImpl) node;
-// start = attr.getValueRegionStartOffset();
-// end = start + attr.getValueRegion().getLength();
-// int ret = 0;
-// if (pos > end) {
-// ret = end - start;
-// } else {
-// ret = pos - start;
-// }
-// if (ret > 0 && attr.getValueRegionText().charAt(0) == '"') {
-// ret--;
-// }
-// return ret;
-// }
-// case Node.TEXT_NODE:
-// if (pos < start) {
-// return 0;
-// } else if (pos > end) {
-// return end - start;
-// } else {
-// return pos - start;
-// }
-// case Node.COMMENT_NODE:
-// if (pos > end) {
-// pos = end;
-// }
-// int offset = pos - start - 4;
-// return offset < 0 ? 0 : offset;
-// case Node.ELEMENT_NODE:
-// ElementImpl element = (ElementImpl) node;
-// if (element.isContainer()) {
-// if (pos < element.getStartEndOffset()) {
-// return 0;
-// } else if (pos < element.getStartEndOffset()) {
-// return 1;
-// } else if (pos == element.getStartEndOffset()) {
-// return 2;
-// }
-// } else {
-// return endFlag ? 1 : 0;
-// }
-// default:
-// return endFlag ? 1 : 0;
-// }
-// }
-
- class VpeSelectionProvider implements ISelectionProvider {
- VpeSelection selection;
-
- public VpeSelectionProvider(IndexedRegion region) {
- selection = new VpeSelection(region);
- }
-
- public VpeSelectionProvider(int position) {
- selection = new VpeSelection(position);
- }
-
- public VpeSelectionProvider(int offset, int length) {
- selection = new VpeSelection(offset, length);
- }
-
- public void addSelectionChangedListener(ISelectionChangedListener listener) {
- }
-
- public void removeSelectionChangedListener(ISelectionChangedListener listener) {
- }
-
- public ISelection getSelection() {
- return selection;
- }
-
- public void setSelection(ISelection selection) {
- }
- }
-
- class VpeSelection implements ITextSelection {
- String text = ""; //$NON-NLS-1$
- int offset, length;
-
- public VpeSelection(int position) {
- offset = position;
- length = 0;
- }
-
- public VpeSelection(int offset, int length) {
- this.offset = offset;
- this.length = length;
- if (length > 0) {
-
- try {
- text = sourceEditor.getTextViewer().getDocument().get(
- offset, length);
- } catch (BadLocationException e) {
- VpePlugin.getPluginLog().logError(e);
- }
-
- }
- }
-
- public VpeSelection(IndexedRegion region) {
- offset = region.getStartOffset();
- length = region.getEndOffset() - offset;
- try {
- text = sourceEditor.getTextViewer().getDocument().get(offset,
- length);
- } catch (BadLocationException ex) {
- VpePlugin.reportProblem(ex);
- }
- }
-
- public int getEndLine() {
- return 0;
- }
-
- public int getLength() {
- return length;
- }
-
- public int getOffset() {
- return offset;
- }
-
- public int getStartLine() {
- return 0;
- }
-
- public String getText() {
- return text;
- }
-
- public boolean isEmpty() {
- return false;
- }
- }
-
- public void refreshExternalLinks() {
- pageContext.getVisualBuilder().refreshExternalLinks();
- }
-
- public IPath getPath() {
- if (editPart != null) {
- IEditorInput input = editPart.getEditorInput();
- if (input != null && input instanceof IFileEditorInput) {
- return ((IFileEditorInput) input).getFile().getFullPath();
- }
- }
- return null;
- }
-
- public void changed(Object source) {
- if (cssReferenceListListener == source) {
- pageContext.getVisualBuilder().refreshExternalLinks();
- } else if (absoluteFolderReferenceListListener == source
- || relativeFolderReferenceListListener == source
- || taglibReferenceListListener == source
- || elReferenceListListener == source) {
- visualRefresh();
- }
- }
-
- public void dragEnter(nsIDOMEvent event) {
- if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
- System.out.println("<<<<<<<<<<<<<<<<<<<< DragEnter"); //$NON-NLS-1$
- }
- }
-
- public void dragExit(nsIDOMEvent event) {
- if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
- System.out.println("<<<<<<<<<<<<<<<<<<<< dragExit"); //$NON-NLS-1$
- }
- // TODO Sergey Vasilyev figure out with drag caret
- // xulRunnerEditor.hideDragCaret();
- }
-
- public void dragOver(nsIDOMEvent event) {
- visualBuilder.getDnd().dragOver(event, this);
- }
-
- public void _dragOver(nsIDOMEvent event) {
- if (!switcher
- .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
- return;
- }
- try {
- if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
- System.out.println("<<<<<<<<<<<<<<<<<<<< dragOver"); //$NON-NLS-1$
- }
- // browser.computeDropPosition(event);
- boolean canDrop = !xulRunnerEditor.isMozillaDragFlavor();
- if (canDrop) {
- Clipboard clipboard = new Clipboard(Display.getCurrent());
- canDrop = clipboard.getContents(ModelTransfer.getInstance()) != null;
- }
- if (canDrop) {
- canDrop = VpeDndUtil
- .isDropEnabled((IModelObjectEditorInput) sourceEditor
- .getEditorInput());
- }
- if (canDrop) {
- VpeVisualCaretInfo caretInfo = selectionBuilder
- .getVisualCaretInfo(event);
- canDrop = caretInfo.exist();
- if (canDrop) {
- caretInfo.showCaret();
- } else {
- caretInfo.hideCaret();
- }
- }
- if (!canDrop) {
- event.stopPropagation();
- event.preventDefault();
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- public void drop(nsIDOMEvent event) {
- if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
- System.out.println("<<< outerDrop"); //$NON-NLS-1$
- }
- event.preventDefault();
- }
-
- public boolean canInnerDrag(nsIDOMMouseEvent event) {
- onHideTooltip();
-
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print("<<<<<< canInnerDrag"); //$NON-NLS-1$
- }
- if (innerDragInfo != null) {
- innerDragInfo.Release();
- innerDragInfo = null;
- }
- boolean canDrag = false;
- VpeVisualInnerDragInfo dragInfo = selectionBuilder
- .getInnerDragInfo(event);
- if (dragInfo != null) {
- nsIDOMNode dragNode = dragInfo.getNode();
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out
- .print(" dragNode: " + dragNode.getNodeName() + "(" + dragNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- switch (dragNode.getNodeType()) {
- case nsIDOMNode.ELEMENT_NODE:
- canDrag = visualBuilder.canInnerDrag((nsIDOMElement) dragNode);
- case nsIDOMNode.TEXT_NODE:
- canDrag = visualBuilder.isTextEditable(dragNode);
- }
- if (canDrag) {
- VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder
- .getSourceInnerDragInfo(dragInfo);
- if (sourceInnerDragInfo.getNode() != null) {
- innerDragInfo = dragInfo;
- InnerDragBuffer.object = sourceInnerDragInfo.getNode();
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- InnerDragBuffer.object = null;
- }
- });
- } else {
- canDrag = false;
- }
- }
- if (!canDrag) {
- dragInfo.Release();
- }
- }
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" canDrag: " + canDrag); //$NON-NLS-1$
- }
- return canDrag;
- }
-
- VpeDropWindow dropWindow = null;
-
- public MozillaDropInfo canInnerDrop(nsIDOMMouseEvent event) {
- onHideTooltip();
-
- if (dropWindow.active) {
- if (!event.getAltKey()) {
- dropWindow.close();
- } else {
- return null;
- }
- }
- if (event.getAltKey()) {
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
- Node sourceNode = domMapping.getNearSourceNode(visualNode);
- if (sourceNode != null) {
- dropWindow.active = true;
- dropWindow.setEventPosition(event.getScreenX(), event
- .getScreenY());
- dropWindow.setInitialTargetNode(sourceNode);
- dropWindow.open();
- event.stopPropagation();
- event.preventDefault();
- return null;
- }
- }
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print("<<<<<< canInnerDrop"); //$NON-NLS-1$
- }
- boolean canDrop = false;
- ;
- nsIDOMNode caretParent = null;
- long caretOffset = 0;
- if (innerDragInfo != null) {
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
- .getInnerDropInfo(event);
- if (visualDropInfo.getDropContainer() != null) {
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out
- .print(" x: " + visualDropInfo.getMouseX() + " y: " + visualDropInfo.getMouseY() + //$NON-NLS-1$ //$NON-NLS-2$
- " container: "
- + visualDropInfo.getDropContainer()
- .getNodeName()
- + //$NON-NLS-1$
- "("
- + visualDropInfo.getDropContainer()
- + ")" + //$NON-NLS-1$ //$NON-NLS-2$
- " parent: "
- + visualDropInfo.getDropContainer()
- .getParentNode().getNodeName()
- + //$NON-NLS-1$
- "("
- + visualDropInfo.getDropContainer()
- .getParentNode() + ")" + //$NON-NLS-1$ //$NON-NLS-2$
- " offset: "
- + visualDropInfo.getDropOffset()); //$NON-NLS-1$
- }
- VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder
- .getSourceInnerDragInfo(innerDragInfo);
- VpeSourceInnerDropInfo sourceDropInfo = visualBuilder
- .getSourceInnerDropInfo(sourceInnerDragInfo.getNode(),
- visualDropInfo, true);
- canDrop = sourceDropInfo.canDrop();
- if (canDrop) {
- VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder
- .getInnerDropInfo(sourceDropInfo.getContainer(),
- sourceDropInfo.getOffset());
- if (newVisualDropInfo != null) {
- visualBuilder.correctVisualDropPosition(
- newVisualDropInfo, visualDropInfo);
- caretParent = newVisualDropInfo.getDropContainer();
- caretOffset = newVisualDropInfo.getDropOffset();
- }
- }
- }
- visualDropInfo.Release();
- }
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" canDrop: " + canDrop); //$NON-NLS-1$
- }
- return new MozillaDropInfo(canDrop, caretParent, caretOffset);
- }
-
- public void innerDrop(nsIDOMMouseEvent event) {
- onHideTooltip();
-
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print("<<<<<< innerDrop"); //$NON-NLS-1$
- }
- if (innerDragInfo != null) {
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
- .getInnerDropInfo(event);
- if (visualDropInfo.getDropContainer() != null) {
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out
- .print(" container: " + visualDropInfo.getDropContainer().getNodeName() + //$NON-NLS-1$
- "(" + visualDropInfo.getDropContainer()
- + ")" + //$NON-NLS-1$ //$NON-NLS-2$
- " offset: "
- + visualDropInfo.getDropOffset()); //$NON-NLS-1$
- }
-
- VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder
- .getSourceInnerDragInfo(innerDragInfo);
- VpeSourceInnerDropInfo sourceDropInfo = visualBuilder
- .getSourceInnerDropInfo(sourceInnerDragInfo.getNode(),
- visualDropInfo, true);
- if (sourceDropInfo.canDrop()) {
- VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder
- .getInnerDropInfo(sourceDropInfo.getContainer(),
- sourceDropInfo.getOffset());
- if (newVisualDropInfo != null) {
- visualBuilder.correctVisualDropPosition(
- newVisualDropInfo, visualDropInfo);
- sourceDropInfo.setTop(visualDropInfo.getMouseY());
- sourceDropInfo.setLeft(visualDropInfo.getMouseX());
- visualBuilder.innerDrop(sourceInnerDragInfo,
- sourceDropInfo);
- if (innerDragInfo != null) {
- innerDragInfo.Release();
- innerDragInfo = null;
- }
- }
- }
- }
- }
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println();
- }
- }
-
- public MozillaDropInfo canExternalDrop(nsIDOMMouseEvent mouseEvent,
- String flavor, String data) {
- InnerDragBuffer.object = null;
- onHideTooltip();
-
- if (dropWindow.active) {
- if (!mouseEvent.getAltKey()) {
- dropWindow.close();
- } else {
- return new MozillaDropInfo(false, null, 0);
- }
- }
- if (mouseEvent.getAltKey()) {
- nsIDOMEvent event = (nsIDOMEvent) mouseEvent
- .queryInterface(nsIDOMEvent.NS_IDOMEVENT_IID);
- nsIDOMNode visualNode = (nsIDOMNode) event.getTarget()
- .queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
- Node sourceNode = domMapping.getNearSourceNode(visualNode);
- if (sourceNode != null) {
- if (ModelTransfer.MODEL.equals(flavor)) { //$NON-NLS-1$
- // XModelObject object =
- // PreferenceModelUtilities.getPreferenceModel().
- // getModelBuffer().source();
- // InnerDragBuffer.object = object;
- } else {
- dropWindow.flavor = flavor;
- }
- dropWindow.active = true;
- dropWindow.setEventPosition(mouseEvent.getScreenX(), mouseEvent
- .getScreenY());
- dropWindow.setInitialTargetNode(sourceNode);
- dropWindow.open();
- mouseEvent.stopPropagation();
- mouseEvent.preventDefault();
- return new MozillaDropInfo(false, null, 0);
- }
- }
- boolean canDrop = false;
- nsIDOMNode caretParent = null;
- long caretOffset = 0;
-
- if (MODEL_FLAVOR.equals(flavor)) {
- XModelObject object = PreferenceModelUtilities.getPreferenceModel()
- .getModelBuffer().source();
- if (object.getFileType() == XModelObject.FILE
- && !TLDUtil.isTaglib(object)) {
- IFile f = (IFile) EclipseResourceUtil.getResource(object);
- canDrop = f != null;
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
- .getInnerDropInfo(mouseEvent);
- caretParent = visualDropInfo.getDropContainer();
- caretOffset = visualDropInfo.getDropOffset();
- } else {
- String tagname = getTagName(object);
- if (tagname.indexOf("taglib") >= 0)tagname = "taglib"; //$NON-NLS-1$ //$NON-NLS-2$
- Node sourceDragNode = ((Document) getModel().getAdapter(
- Document.class)).createElement(tagname);
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
- .getInnerDropInfo(mouseEvent);
- if (visualDropInfo.getDropContainer() != null) {
- VpeSourceInnerDropInfo sourceDropInfo = visualBuilder
- .getSourceInnerDropInfo(sourceDragNode,
- visualDropInfo, true);
- canDrop = sourceDropInfo.canDrop();
- if (canDrop) {
- VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder
- .getInnerDropInfo(
- sourceDropInfo.getContainer(),
- sourceDropInfo.getOffset());
- if (newVisualDropInfo != null) {
- visualBuilder.correctVisualDropPosition(
- newVisualDropInfo, visualDropInfo);
- caretParent = newVisualDropInfo.getDropContainer();
- caretOffset = newVisualDropInfo.getDropOffset();
- }
- }
- }
- visualDropInfo.Release();
- }
- } else if (XulRunnerEditor.TRANS_FLAVOR_kFileMime.equals(flavor)
- || XulRunnerEditor.TRANS_FLAVOR_kURLMime.equals(flavor)) {
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
- .getInnerDropInfo(mouseEvent);
- caretParent = visualDropInfo.getDropContainer();
- caretOffset = visualDropInfo.getDropOffset();
- canDrop = true;
-
- }
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out
- .println(" canDrop: " + canDrop + (canDrop ? " container: " + caretParent.getNodeName() + " offset: " + caretOffset : "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- }
- return new MozillaDropInfo(canDrop, caretParent, caretOffset);
-
- }
-
- public VpeSourceInnerDropInfo canExternalDropMacro(XModelObject object,
- Node parentNode, int offset) {
- String tagname = getTagName(object);
- Node sourceDragNode = ((Document) getModel().getAdapter(Document.class))
- .createElement(tagname);
- return visualBuilder.getSourceInnerDropInfo(sourceDragNode, parentNode,
- offset, false);
- }
-
- public void externalDropAny(final String flavor, final String data,
- final Point range, Node container) {
- if (flavor == null || flavor.length() == 0)
- return;
- IDropCommand dropCommand = DropCommandFactory.getInstance()
- .getDropCommand(flavor, JSPTagProposalFactory.getInstance());
-
- boolean promptAttributes = "yes"
- .equals(VpePreference.ALWAYS_REQUEST_FOR_ATTRIBUTE.getValue());
- dropCommand.getDefaultModel().setPromptForTagAttributesRequired(
- promptAttributes);
-
- dropCommand.execute(new DropData(flavor, data, sourceEditor
- .getEditorInput(), (ISourceViewer) sourceEditor
- .getAdapter(ISourceViewer.class), new VpeSelectionProvider(
- range.x, range.y), container));
- }
-
- private String getTagName(XModelObject object) {
- String tagname = object.getAttributeValue("name"); //$NON-NLS-1$
-
- XModelObject parent = object.getParent();
- String uri = (parent == null) ? "" : parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
- String defaultPrefix = (parent == null) ? "" : parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
-
- String[] texts = new String[] { "<" + tagname + ">" }; //$NON-NLS-1$ //$NON-NLS-2$
- PaletteInsertHelper.applyPrefix(texts, sourceEditor, tagname, uri,
- defaultPrefix);
- tagname = texts[0].substring(1, texts[0].length() - 1);
-
- return tagname;
- }
-
- public void externalDrop(nsIDOMMouseEvent mouseEvent, String flavor, String data) {
- onHideTooltip();
-
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(mouseEvent);
- Point range = selectionBuilder.getSourceSelectionRangeAtVisualNode(visualDropInfo.getDropContainer(), (int) visualDropInfo
- .getDropOffset());
- VpeSourceInnerDropInfo sourceDropInfo = null;
-
- // if (MODEL_FLAVOR.equals(flavor)) {
- // XModelObject object = PreferenceModelUtilities.getPreferenceModel()
- // .getModelBuffer().source();
- // if(object == null)
-
- nsISupports aValue = DndUtil.getDnDValue(mouseEvent);
- String aFlavor = ""; //$NON-NLS-1$
- if (VpeDndUtil.isNsIFileInstance(aValue)) {
- nsIFile aFile = (nsIFile) aValue.queryInterface(nsIFile.NS_IFILE_IID);
-
- if (aValue != null) {
- data = aFile.getPath();
- aFlavor = DndUtil.kFileMime;
- }
-
- } else if (VpeDndUtil.isNsICStringInstance(aValue)) {
- nsISupportsCString aString = (nsISupportsCString) aValue.queryInterface(nsISupportsCString.NS_ISUPPORTSCSTRING_IID);
- data = aString.getData();
- aFlavor = DndUtil.kHTMLMime;
- } else if (VpeDndUtil.isNsIStringInstance(aValue)) {
- nsISupportsString aString = (nsISupportsString) aValue.queryInterface(nsISupportsString.NS_ISUPPORTSSTRING_IID);
- data = aString.getData();
- aFlavor = DndUtil.kURLMime;
- }
-
- // if (object.getFileType() == XModelObject.FILE
- // && !TLDUtil.isTaglib(object)) {
- // flavor = "application/x-moz-file"; //$NON-NLS-1$
- // IFile f = (IFile) EclipseResourceUtil.getResource(object);
- // try {
- // data = f.getLocation().toFile().toURL().toString();
- // } catch (Exception e) {
- // VpePlugin.getPluginLog().logError(e);
- // }
- // } else {
- // String tagname = getTagName(object);
- // if (tagname.indexOf("taglib") >= 0)tagname = "taglib"; //$NON-NLS-1$ //$NON-NLS-2$
- // Node sourceDragNode = ((Document) getModel().getAdapter(
- // Document.class)).createElement(tagname);
- // if (visualDropInfo.getDropContainer() != null) {
- // sourceDropInfo = visualBuilder.getSourceInnerDropInfo(
- // sourceDragNode, visualDropInfo, true);
- // range = selectionBuilder.getSourceSelectionRange(
- // sourceDropInfo.getContainer(), sourceDropInfo
- // .getOffset());
- // }
- // }
-
- if (visualDropInfo.getDropContainer() != null && data != null) {
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" drop! container: " + visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
- }
- externalDropAny(aFlavor, data, range, sourceDropInfo == null ? null : sourceDropInfo.getContainer());
-
- DropContext dropContext = new DropContext();
- IDNDTextEditor textEditor = (IDNDTextEditor) VpeController.this.editPart.getSourceEditor();
-
- // TypedEvent tEvent = new TypedEvent(mouseEvent);
- // tEvent.data = data;
- // dropContext.setFlavor(aFlavor);
- // dropContext.setMimeData(data);
- // DnDUtil.fireDnDEvent(dropContext, textEditor, tEvent);
- }
- }
-
- public void onShowTooltip(int x, int y, final String text) {
-
- if (tip != null && !tip.isDisposed())
- tip.dispose();
-
- Display display = visualEditor.getControl().getDisplay();
- Shell parent = visualEditor.getControl().getShell();
-
- tip = new Shell(parent, SWT.NO_FOCUS | SWT.ON_TOP);
- Color bckgColor = new Color(tip.getDisplay(), 255, 250, 236);
- tip.setBackground(bckgColor);
-
- Composite composite = tip;
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- layout.verticalSpacing = 0;
- layout.horizontalSpacing = 0;
- composite.setLayout(layout);
- GridData gd = new GridData(GridData.FILL_BOTH);
- composite.setLayoutData(gd);
-
- final StyledText tipControlHeaderText = new StyledText(composite,
- SWT.MULTI | SWT.READ_ONLY);
-
- tipControlHeaderText.setForeground(bckgColor);
- tipControlHeaderText.setBackground(bckgColor);
-
- String formatText = text.trim();
-
- /**
- * attributeString string containing the pairs attribute and it's value
- * as one string
- */
- String[] attributeString = formatText.split("\n"); //$NON-NLS-1$
- /**
- * buffer string containing the attribute and the value in the different
- * succeding string
- */
- String[] buffer = attributeString[0].split(" "); //$NON-NLS-1$
-
- tipControlHeaderText.setText(buffer[0].toString());
-
- tipControlHeaderText.addLineStyleListener(new LineStyleListener() {
- public void lineGetStyle(LineStyleEvent event) {
- Color color = new Color(tipControlHeaderText.getDisplay(), 201,
- 51, 40);
- if (event.lineOffset == 0) {
- StyleRange st = new StyleRange();
- st.fontStyle = SWT.BOLD;
- st.foreground = color;
- event.styles = new StyleRange[] { st };
- st.start = event.lineOffset;
- st.length = event.lineText.length();
- }
- }
- });
-
- GridData gridData = new GridData(GridData.BEGINNING
- | GridData.FILL_BOTH);
- gridData.horizontalAlignment = GridData.FILL;
- gridData.horizontalSpan = 2;
- tipControlHeaderText.setLayoutData(gridData);
-
- StringBuffer tempAttr = new StringBuffer();
- StringBuffer tempValue = new StringBuffer();
-
- if (attributeString.length >= 2) {
- for (int i = 1; i < attributeString.length; i++) {
- buffer = attributeString[i].split(" ", 2); //$NON-NLS-1$
- if (i == 1) {
- tempAttr.append(buffer[0] + " "); //$NON-NLS-1$
- tempValue
- .append((buffer.length >= 2 ? buffer[1] : "") + " "); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- tempAttr.append("\n" + buffer[0] + " "); //$NON-NLS-1$ //$NON-NLS-2$
- tempValue
- .append(" \n" + (buffer.length >= 2 ? buffer[1] : "") + " "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- }
-
- final StyledText tipControlAttributeText = new StyledText(
- composite, SWT.MULTI | SWT.READ_ONLY);
-
- tipControlAttributeText.setForeground(bckgColor);
- tipControlAttributeText.setBackground(bckgColor);
-
- tipControlAttributeText.setText(tempAttr.toString());
- tipControlAttributeText
- .addLineStyleListener(new LineStyleListener() {
- public void lineGetStyle(LineStyleEvent event) {
- Color color = new Color(tipControlHeaderText
- .getDisplay(), 42, 148, 0);
- StyleRange st = new StyleRange();
- st.start = event.lineOffset;
- st.length = event.lineText.length();
- st.foreground = color;
- st.fontStyle = SWT.NORMAL;
- event.styles = new StyleRange[] { st };
- }
- });
- GridData gridData1 = new GridData(GridData.BEGINNING
- | GridData.FILL_BOTH);
- gridData1.horizontalAlignment = GridData.FILL;
- tipControlAttributeText.setLayoutData(gridData1);
-
- final StyledText tipControlValueText = new StyledText(composite,
- SWT.MULTI | SWT.READ_ONLY);
-
- tipControlValueText.setBackground(bckgColor);
-
- tipControlValueText.setText(tempValue.toString());
-
- GridData gridData2 = new GridData(GridData.BEGINNING
- | GridData.FILL_BOTH);
- gridData2.horizontalAlignment = GridData.FILL;
- tipControlValueText.setLayoutData(gridData2);
- }
- /*
- * Bug in Mozilla embedded API. Tooltip coordinates are wrong for
- * elements inside an inline frame (IFrame tag). The workaround is to
- * position the tooltip based on the mouse cursor location.
- */
- Point point = display.getCursorLocation();
- /*
- * Assuming cursor is 21x21 because this is the size of the arrow cursor
- * on Windows
- */
- point.y += 21;
- tip.setLocation(point);
- tip.pack();
- tip.setVisible(true);
- }
-
- public void onHideTooltip() {
- if (tip != null && !tip.isDisposed())
- tip.dispose();
- tip = null;
- }
-
- public VpePageContext getPageContext() {
-
- return pageContext;
- }
-
- public StructuredTextEditor getSourceEditor() {
- return sourceEditor;
- }
-
- public FormatControllerManager getToolbarFormatControllerManager() {
- return toolbarFormatControllerManager;
- }
-
- public void setToolbarFormatControllerManager(
- FormatControllerManager formatControllerManager) {
- toolbarFormatControllerManager = formatControllerManager;
- }
-
- public void setSelectionBarController(SelectionBar selectionBar) {
- this.selectionBar = selectionBar;
- }
-
- public IStructuredModel getModel() {
- return sourceEditor.getModel();
- }
-
- public VpeDomMapping getDomMapping() {
- return domMapping;
- }
-
- public VpeIncludeList getIncludeList() {
-
- if (includeList == null)
- VpePlugin.getPluginLog().logError("includeList - NULL!!!");
-
- return includeList;
- }
-
- /**
- * Processed selection events from source editor,
- * if reason of selection is visial editor,
- * selection will be stopped processing by
- * this condition (!switcher.startActiveEditor)
- */
- public void selectionChanged(SelectionChangedEvent event) {
- if (selectionBar != null)
- selectionBar.selectionChanged();
- // FIX for JBIDE-2114
- if (!isVisualEditorVisible()) {
- // selection event doesn't changes a content
- // synced = false;
- return;
- }
-
- if (editPart.getVisualMode() != VpeEditorPart.SOURCE_MODE) {
- if (toolbarFormatControllerManager != null)
- toolbarFormatControllerManager.selectionChanged();
- }
-
- if (!switcher
- .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- try {
-
- if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out
- .println(">>>>>>>>>>>>>> selectionChanged " + event.getSource()); //$NON-NLS-1$
- }
- sourceSelectionChanged();
- } finally {
- switcher.stopActiveEditor();
- }
- }
-
- // nsIClipboardDragDropHooks implementation
- public void onPasteOrDrop(nsIDOMMouseEvent mouseEvent, String flavor,
- String data) {
- onHideTooltip();
-
- VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
- .getInnerDropInfo(mouseEvent);
- Point range = selectionBuilder.getSourceSelectionRangeAtVisualNode(
- visualDropInfo.getDropContainer(), (int) visualDropInfo
- .getDropOffset());
- VpeSourceInnerDropInfo sourceDropInfo = null;
-
- XModelObject object = PreferenceModelUtilities.getPreferenceModel()
- .getModelBuffer().source();
-
- String tagname = getTagName(object);
- if (tagname.indexOf("taglib") >= 0)tagname = "taglib"; //$NON-NLS-1$ //$NON-NLS-2$
- Node sourceDragNode = ((Document) getModel().getAdapter(Document.class))
- .createElement(tagname);
- if (visualDropInfo.getDropContainer() != null) {
- sourceDropInfo = visualBuilder.getSourceInnerDropInfo(
- sourceDragNode, visualDropInfo, true);
- range = selectionBuilder.getSourceSelectionRange(sourceDropInfo
- .getContainer(), sourceDropInfo.getOffset());
- }
-
- if (visualDropInfo.getDropContainer() != null) {
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out
- .println(" drop! container: " + visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
- }
- final String finalFlavor = flavor;
- final String finalData = data;
- final Point finalRange = range;
- final Node finalDropContainer = sourceDropInfo == null ? null
- : sourceDropInfo.getContainer();
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- externalDropAny(finalFlavor, finalData, finalRange,
- finalDropContainer);
- }
- });
- }
- }
-
- public void drop(Node node, Node parentNode, int offset) {
- visualBuilder.innerDrop(node, parentNode, offset);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.mozilla.interfaces.nsISupports#queryInterface(java.lang.String)
- */
- public nsISupports queryInterface(String arg0) {
- return Mozilla.getInstance().queryInterface(this, arg0);
- }
-
- /**
- * Calls when editor content should be refreshed
- */
- public void onRefresh() {
- // when we using separate thread to display selection rectangle
- // it's working better than without
- /*
- * HACK We need wait some time while standart event will be handled and
- * in process event handles some components are repainted(like buttons)
- * and flasher are not repainted, so we should paint flasher
- */
-
- Display.getDefault().asyncExec(new Thread() {
- public void run() {
- if (getXulRunnerEditor() != null)
- getXulRunnerEditor().showSelectionRectangle();
- }
- });
-
- }
-
- /**
- * @return the xulRunnerEditor
- */
- public XulRunnerEditor getXulRunnerEditor() {
- return xulRunnerEditor;
- }
-
- /**
- * @param xulRunnerEditor
- * the xulRunnerEditor to set
- */
- public void setXulRunnerEditor(XulRunnerEditor xulRunnerEditor) {
- this.xulRunnerEditor = xulRunnerEditor;
- }
-
- /**
- * Start drag session
- */
- public void startDragSession(nsIDOMEvent domEvent) {
-
- visualBuilder.getDnd().startDragSession(domEvent);
- }
-
- public void dragDrop(nsIDOMEvent domEvent) {
-
- visualBuilder.getDnd().dragDrop(domEvent, this);
- }
-
- /**
- * @return the selectionBuilder
- */
- public VpeSelectionBuilder getSelectionBuilder() {
- return selectionBuilder;
- }
-
- /**
- * @param selectionBuilder
- * the selectionBuilder to set
- */
- public void setSelectionBuilder(VpeSelectionBuilder selectionBuilder) {
- this.selectionBuilder = selectionBuilder;
- }
-
- public boolean isVisualEditorVisible() {
- return visualEditorVisible;
- }
-
- public void setVisualEditorVisible(boolean visualEditorVisible) {
- this.visualEditorVisible = visualEditorVisible;
- }
-
- public boolean isSynced() {
- return synced;
- }
-
- public void setSynced(boolean synced) {
- this.synced = synced;
- }
-
- /**
- * @return the changeEvents
- */
- public LinkedList<VpeEventBean> getChangeEvents() {
-
- if (changeEvents == null) {
-
- changeEvents = new LinkedList<VpeEventBean>();
- }
- return changeEvents;
- }
- public void reinit(){
- if(reinitJob!=null) {
- reinitJob.cancel();
- }
- reinitJob = new UIJob(VpeUIMessages.VPE_VISUAL_REFRESH_JOB) {
-
- @Override
- public IStatus runInUIThread(IProgressMonitor monitor) {
- if(monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- }
- reinitImpl();
- return Status.OK_STATUS;
- }
- };
- reinitJob.schedule();
- }
-
- private void reinitImpl() {
- try {
- if(switcher==null||!switcher
- .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- return;
- }
- visualBuilder.setSelectionRectangle(null);
- visualEditor.setEditorDomEventListener(this);
- IDOMModel sourceModel = (IDOMModel) getModel();
- if (sourceModel != null) {
- IDOMDocument sourceDocument = sourceModel.getDocument();
- visualBuilder.rebuildDom(sourceDocument);
- } else {
- visualBuilder.rebuildDom(null);
- }
- //reinits selection controller+ controller
- visualEditor.reinitDesignMode();
- visualSelectionController = new VpeSelectionController(visualEditor.getEditor().getSelectionController());
-
- selectionBuilder = new VpeSelectionBuilder(domMapping, sourceBuilder,
- visualBuilder, visualSelectionController);
-
- selectionManager = new SelectionManager(pageContext,
- sourceEditor, visualSelectionController);
-
- keyEventHandler = new KeyEventManager(sourceEditor, domMapping,
- pageContext);
- //restore selection in visula part
- sourceSelectionChanged();
- }catch(VpeDisposeException ex) {
- //vpe vas closed when refresh job is running, so just
- //ignore this exception
- }
- finally {
- if(switcher!=null) {
- switcher.stopActiveEditor();
- }
- }
-
- }
-
- /**
- * @return the visualSelectionController
- */
- public VpeSelectionController getVisualSelectionController() {
- return visualSelectionController;
- }
-
- /**
- *
- * @return sourceBuilder
- */
- public VpeSourceDomBuilder getSourceBuilder() {
- return sourceBuilder;
- }
-
- /**
- *
- * @return visualBuilder
- */
- public VpeVisualDomBuilder getVisualBuilder() {
- return visualBuilder;
- }
-
- /**
- * @return the vpeUpdateDelayTime
- */
- private int getVpeUpdateDelayTime() {
- return vpeUpdateDelayTime;
- }
-
- /**
- * @param vpeUpdateDelayTime the vpeUpdateDelayTime to set
- */
- private void setVpeUpdateDelayTime(int vpeUpdateDelayTime) {
- this.vpeUpdateDelayTime = vpeUpdateDelayTime;
- }
-
- /**
- * @return the selectionManager
- */
- public ISelectionManager getSelectionManager() {
- return selectionManager;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.editor;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.bindings.Binding;
+import org.eclipse.jface.bindings.keys.KeySequence;
+import org.eclipse.jface.bindings.keys.KeyStroke;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.source.ISourceViewer;
+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.SWT;
+import org.eclipse.swt.custom.LineStyleEvent;
+import org.eclipse.swt.custom.LineStyleListener;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.events.MenuEvent;
+import org.eclipse.swt.events.MenuListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.keys.WorkbenchKeyboard;
+import org.eclipse.ui.keys.IBindingService;
+import org.eclipse.ui.progress.UIJob;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.eclipse.wst.sse.core.internal.model.ModelLifecycleEvent;
+import org.eclipse.wst.sse.core.internal.provisional.IModelLifecycleListener;
+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
+import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.wst.sse.ui.internal.view.events.INodeSelectionListener;
+import org.eclipse.wst.sse.ui.internal.view.events.ITextSelectionListener;
+import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
+import org.eclipse.wst.sse.ui.internal.view.events.TextSelectionChangedEvent;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.jboss.tools.common.el.core.ELReferenceList;
+import org.jboss.tools.common.model.XModel;
+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.options.PreferenceModelUtilities;
+import org.jboss.tools.common.model.project.IModelNature;
+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.DropUtils;
+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.IDNDTextEditor;
+import org.jboss.tools.common.model.ui.editors.dnd.context.InnerDragBuffer;
+import org.jboss.tools.common.model.ui.util.ModelUtilities;
+import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.model.util.XModelTreeListenerSWTSync;
+import org.jboss.tools.common.resref.core.ResourceReferenceListListener;
+import org.jboss.tools.jst.jsp.editor.IJSPTextEditor;
+import org.jboss.tools.jst.jsp.editor.IVisualController;
+import org.jboss.tools.jst.jsp.preferences.VpePreference;
+import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
+import org.jboss.tools.jst.web.project.WebProject;
+import org.jboss.tools.jst.web.tld.TLDUtil;
+import org.jboss.tools.jst.web.tld.URIConstants;
+import org.jboss.tools.vpe.VpeDebug;
+import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.dnd.DndUtil;
+import org.jboss.tools.vpe.editor.bundle.BundleMap;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.jboss.tools.vpe.editor.menu.MenuCreationHelper;
+import org.jboss.tools.vpe.editor.mozilla.EditorDomEventListener;
+import org.jboss.tools.vpe.editor.mozilla.MozillaDropInfo;
+import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
+import org.jboss.tools.vpe.editor.selection.VpeSelectionController;
+import org.jboss.tools.vpe.editor.selection.VpeSelectionHelper;
+import org.jboss.tools.vpe.editor.template.IKeyEventHandler;
+import org.jboss.tools.vpe.editor.template.ISelectionManager;
+import org.jboss.tools.vpe.editor.template.KeyEventManager;
+import org.jboss.tools.vpe.editor.template.SelectionManager;
+import org.jboss.tools.vpe.editor.template.VpeIncludeList;
+import org.jboss.tools.vpe.editor.template.VpeTemplateListener;
+import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
+import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
+import org.jboss.tools.vpe.editor.util.Constants;
+import org.jboss.tools.vpe.editor.util.DocTypeUtil;
+import org.jboss.tools.vpe.editor.util.SelectionUtil;
+import org.jboss.tools.vpe.editor.util.VisualDomUtil;
+import org.jboss.tools.vpe.editor.util.VpeDndUtil;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
+import org.jboss.tools.vpe.resref.core.AbsoluteFolderReferenceList;
+import org.jboss.tools.vpe.resref.core.CSSReferenceList;
+import org.jboss.tools.vpe.resref.core.RelativeFolderReferenceList;
+import org.jboss.tools.vpe.resref.core.TaglibReferenceList;
+import org.jboss.tools.vpe.selbar.SelectionBar;
+import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMEvent;
+import org.mozilla.interfaces.nsIDOMKeyEvent;
+import org.mozilla.interfaces.nsIDOMMouseEvent;
+import org.mozilla.interfaces.nsIDOMMutationEvent;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsIFile;
+import org.mozilla.interfaces.nsISelection;
+import org.mozilla.interfaces.nsISelectionListener;
+import org.mozilla.interfaces.nsISupports;
+import org.mozilla.interfaces.nsISupportsCString;
+import org.mozilla.interfaces.nsISupportsString;
+import org.mozilla.xpcom.Mozilla;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class VpeController implements INodeAdapter, IModelLifecycleListener,
+ INodeSelectionListener, ITextSelectionListener, SelectionListener,
+ EditorDomEventListener, VpeTemplateListener, XModelTreeListener,
+ ResourceReferenceListListener, ISelectionChangedListener,
+ IVisualController {
+
+ private boolean visualEditorVisible = true;
+ private boolean synced = true;
+ StructuredTextEditor sourceEditor;
+ private MozillaEditor visualEditor;
+ // MozillaBrowser browser;
+ XulRunnerEditor xulRunnerEditor;
+ // TODO Sergey Vasilyev figure out with nsIPressShell
+ // private nsIPresShell presShell;
+ private VpeSelectionController visualSelectionController;
+ VpeDomMapping domMapping;
+ private VpeSourceDomBuilder sourceBuilder;
+ private VpeVisualDomBuilder visualBuilder;
+ /** @deprecated */
+ private VpeSelectionBuilder selectionBuilder;
+ // private VpeVisualKeyHandler visualKeyHandler;
+ private ActiveEditorSwitcher switcher = new ActiveEditorSwitcher();
+ private Attr lastRemovedAttr;
+ private String lastRemovedAttrName;
+ private boolean mouseUpSelectionReasonFlag;
+ private boolean mouseDownSelectionFlag;
+ private boolean sourceChangeFlag;
+ private VpePageContext pageContext;
+ private BundleMap bundle;
+ private VpeEditorPart editPart;
+ private static final int LEFT_BUTTON = 0;
+
+ private CSSReferenceList cssReferenceListListener;
+ private TaglibReferenceList taglibReferenceListListener;
+ private ELReferenceList elReferenceListListener;
+ private AbsoluteFolderReferenceList absoluteFolderReferenceListListener;
+ private RelativeFolderReferenceList relativeFolderReferenceListListener;
+ private VpeIncludeList includeList = new VpeIncludeList();
+ private VpeVisualInnerDragInfo innerDragInfo = null;
+ private FormatControllerManager toolbarFormatControllerManager = null;
+ private SelectionBar selectionBar = null;
+ private XModelTreeListenerSWTSync optionsListener;
+ // Added by Max Areshkau Fix for JBIDE-1479
+ private UIJob job = null;
+ private UIJob uiJob;
+ // JBIDE-675, visual refresh job
+ private UIJob visualRefreshJob;
+ private UIJob reinitJob;
+
+ /**
+ * Added by Max Areshkau JBIDE-675, stores information about modification
+ * events
+ */
+ private LinkedList<VpeEventBean> changeEvents;
+
+ Shell tip;
+
+ /**
+ * selectionManager is used for management of selection
+ */
+ private ISelectionManager selectionManager;
+
+ /**
+ * keyEventHandler is used for management of key events
+ */
+ private IKeyEventHandler keyEventHandler;
+
+ public final static String MODEL_FLAVOR = ModelTransfer.MODEL;
+ //contains vpe update delau time in miliseconds
+ private int vpeUpdateDelayTime;
+
+ public VpeController(VpeEditorPart editPart) {
+
+ this.editPart = editPart;
+ dropWindow = new VpeDropWindow(editPart.getSite().getShell());
+ }
+
+ void init(StructuredTextEditor sourceEditor, MozillaEditor visualEditor) {
+ this.sourceEditor = sourceEditor;
+ if (sourceEditor instanceof IJSPTextEditor) {
+ ((IJSPTextEditor) sourceEditor).setVPEController(this);
+ dropWindow.setEditor((IJSPTextEditor) sourceEditor);
+ }
+ this.visualEditor = visualEditor;
+ visualEditor.setController(this);
+ bundle = new BundleMap();
+ bundle.init(sourceEditor);
+ pageContext = new VpePageContext(bundle, editPart);
+ domMapping = new VpeDomMapping(pageContext);
+ sourceBuilder = new VpeSourceDomBuilder(domMapping, this,
+ VpeTemplateManager.getInstance(), sourceEditor, pageContext);
+ visualBuilder = new VpeVisualDomBuilder(domMapping, this, visualEditor, pageContext);
+ pageContext.setSourceDomBuilder(sourceBuilder);
+ pageContext.setVisualDomBuilder(visualBuilder);
+ IDOMModel sourceModel = (IDOMModel) getModel();
+ if (sourceModel == null) {
+ return;
+ }
+ sourceModel.addModelLifecycleListener(this);
+
+ IEditorInput editorInput = pageContext.getEditPart().getEditorInput();
+ if(editorInput instanceof IFileEditorInput) {
+ XModel xm = null;
+ IProject project = ((IFileEditorInput) editorInput).getFile()
+ .getProject();
+ IModelNature mn = EclipseResourceUtil.getModelNature(project);
+ if (mn != null) {
+ xm = mn.getModel();
+ }
+ if (xm != null) {
+ WebProject.getInstance(xm).getTaglibMapping().revalidate(
+ WebAppHelper.getWebApp(xm));
+ }
+ }
+
+ IDOMDocument sourceDocument = sourceModel.getDocument();
+ // FIXED FOR JBIDE-3799 by sdzmitrovich, moved calling of this method to buid dom
+ // visualBuilder.refreshExternalLinks();
+ visualBuilder.buildDom(sourceDocument);
+
+ VpeTemplateManager.getInstance().addTemplateListener(this);
+
+ xulRunnerEditor = visualEditor.getXulRunnerEditor();
+ // TODO Sergey Vasilyev figure out with nsIPressShell
+ // presShell = browser.getPresShell();
+
+ //initialization visual selection controller
+ visualSelectionController = new VpeSelectionController(visualEditor.getEditor().getSelectionController());
+
+ selectionBuilder = new VpeSelectionBuilder(domMapping, sourceBuilder,
+ visualBuilder, visualSelectionController);
+
+ selectionManager = new SelectionManager(pageContext,
+ sourceEditor, visualSelectionController);
+
+ keyEventHandler = new KeyEventManager(sourceEditor, domMapping,
+ pageContext);
+
+ // glory
+ ISelectionProvider provider = sourceEditor.getSelectionProvider();
+ // Max Areshkau JBIDE-1105 If selection event received after selection
+ // in
+ // visual part we lost focus of selection, so we should process
+ // selection event
+ // in time of selection
+ // if (provider instanceof IPostSelectionProvider)
+ // ((IPostSelectionProvider)
+ // provider).addPostSelectionChangedListener(this);
+ // else
+ provider.addSelectionChangedListener(this);
+
+ // ViewerSelectionManager selectionManager =
+ // sourceEditor.getViewerSelectionManager();
+ // selectionManager.addNodeSelectionListener(this);
+ // selectionManager.addTextSelectionListener(this);
+ StyledText textWidget = VpeSelectionHelper
+ .getSourceTextWidget(sourceEditor);
+ if (textWidget != null) {
+ textWidget.addSelectionListener(this);
+ }
+
+ visualEditor.setEditorDomEventListener(this);
+ switcher.initActiveEditor();
+
+ if (optionsListener == null) {
+ XModelObject optionsObject = ModelUtilities.getPreferenceModel()
+ .getByPath(VpePreference.EDITOR_PATH);
+ optionsListener = new XModelTreeListenerSWTSync(this);
+ optionsObject.getModel().addModelTreeListener(optionsListener);
+ }
+
+ cssReferenceListListener = CSSReferenceList.getInstance();
+ cssReferenceListListener.addChangeListener(this);
+
+ taglibReferenceListListener = TaglibReferenceList.getInstance();
+ taglibReferenceListListener.addChangeListener(this);
+
+ absoluteFolderReferenceListListener = AbsoluteFolderReferenceList
+ .getInstance();
+ absoluteFolderReferenceListListener.addChangeListener(this);
+
+ relativeFolderReferenceListListener = RelativeFolderReferenceList
+ .getInstance();
+ relativeFolderReferenceListListener.addChangeListener(this);
+
+ elReferenceListListener = ELReferenceList.getInstance();
+ elReferenceListListener.addChangeListener(this);
+
+ //initialization of vpe update delay time
+ vpeUpdateDelayTime = 400;
+ // pageContext.fireTaglibsChanged();
+ }
+
+ public void dispose() {
+ if (job != null) {
+ job.cancel();
+ job = null;
+ }
+
+ if (uiJob != null) {
+ uiJob.cancel();
+ getChangeEvents().clear();
+ uiJob = null;
+ }
+
+ if (visualRefreshJob != null) {
+ visualRefreshJob.cancel();
+ visualRefreshJob = null;
+ }
+
+ if (optionsListener != null) {
+ XModelObject optionsObject = ModelUtilities.getPreferenceModel().getByPath(VpePreference.EDITOR_PATH);
+ optionsObject.getModel().removeModelTreeListener(optionsListener);
+ optionsListener.dispose();
+ optionsListener = null;
+ }
+ IDOMModel sourceModel = (IDOMModel) getModel();
+ if (sourceModel != null) {
+ sourceModel.removeModelLifecycleListener(this);
+ }
+ switcher.destroyActiveEditor();
+ switcher = null;
+
+ VpeTemplateManager.getInstance().removeTemplateListener(this);
+
+ if (visualBuilder != null) {
+ visualBuilder.dispose();
+ visualBuilder = null;
+ }
+ sourceBuilder = null;
+ if (sourceEditor != null) {
+ // glory
+ ISelectionProvider provider = sourceEditor.getSelectionProvider();
+ provider.removeSelectionChangedListener(this);
+ // ViewerSelectionManager selectionManager =
+ // sourceEditor.getViewerSelectionManager();
+ // selectionManager.removeNodeSelectionListener(this);
+ // selectionManager.removeTextSelectionListener(this);
+ StyledText textWidget = VpeSelectionHelper
+ .getSourceTextWidget(sourceEditor);
+ if (textWidget != null) {
+ textWidget.removeSelectionListener(this);
+ }
+ ((IJSPTextEditor) sourceEditor).setVPEController(null);
+
+ }
+ if (dropWindow != null) {
+ dropWindow.setEditor(null);
+ }
+ if (visualEditor != null) {
+ visualEditor.setEditorDomEventListener(null);
+ if (visualSelectionController != null) {
+// visualSelectionController.Release();
+ visualSelectionController = null;
+ }
+ // TODO Sergey Vasilyev figure out with Press Shell
+ // if (presShell != null) {
+ // presShell.Release();
+ // presShell = null;
+ // }
+ visualEditor = null;
+ }
+
+ if (cssReferenceListListener != null) {
+ cssReferenceListListener.removeChangeListener(this);
+ }
+ if (taglibReferenceListListener != null) {
+ taglibReferenceListListener.removeChangeListener(this);
+ }
+ if (absoluteFolderReferenceListListener != null) {
+ absoluteFolderReferenceListListener.removeChangeListener(this);
+ }
+ if(elReferenceListListener!=null){
+ elReferenceListListener.removeChangeListener(this);
+ }
+ if (relativeFolderReferenceListListener != null) {
+ relativeFolderReferenceListListener.removeChangeListener(this);
+ }
+ toolbarFormatControllerManager = null;
+ }
+
+ // INodeAdapter implementation
+ public boolean isAdapterForType(Object type) {
+ return type == this;
+ }
+
+ // FIX Fox JBIDE-1479 added by Max Areshkau
+ public void notifyChanged(final INodeNotifier notifier,
+ final int eventType, final Object feature, final Object oldValue,
+ final Object newValue, final int pos) {
+ if (!isVisualEditorVisible()) {
+ setSynced(false);
+ return;
+ }
+ // start job when we modify file in ui thread, without this code
+ // changes will be applied with 1 second delay
+ Display display = null;
+ if (PlatformUI.isWorkbenchRunning())
+ display = PlatformUI.getWorkbench().getDisplay();
+
+ if (display != null && (Thread.currentThread() == display.getThread())) {
+ getChangeEvents().addLast(
+ new VpeEventBean(notifier, eventType, feature, oldValue,
+ newValue, pos));
+ if (uiJob == null) {
+ uiJob = new UIJob(VpeUIMessages.VPE_UPDATE_JOB_TITLE) {
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ monitor.beginTask(VpeUIMessages.VPE_UPDATE_JOB_TITLE, 100);
+ while (getChangeEvents().size() > 0) {
+ monitor.worked((int) (100 / getChangeEvents().size()));
+ VpeEventBean eventBean = getChangeEvents().getFirst();
+ if (monitor.isCanceled()) {
+ /*
+ * Yahor Radtsevich: the following line is commented
+ * as fix of JBIDE-3758: VPE autorefresh is broken in some cases.
+ * Now if the change events queue should be cleared, the user have to do it explicitly.
+ */
+ // getChangeEvents().clear();
+
+ return Status.CANCEL_STATUS;
+ }
+ try {
+ notifyChangedInUiThread(
+ eventBean.getNotifier(), eventBean
+ .getEventType(), eventBean
+ .getFeature(), eventBean
+ .getOldValue(), eventBean
+ .getNewValue(), eventBean
+ .getPos());
+ } catch (VpeDisposeException ex) {
+ // JBIDE-675 we will get this exception if user
+ // close editor,
+ // when update visual editor job is running, we
+ // shoud ignore this
+ // exception
+ break;
+ } catch (NullPointerException ex) {
+ if (switcher != null) {
+ throw ex;
+ } else {
+ // class was disposed and exception result
+ // of that we can't stop
+ // refresh job in time, so we just ignore
+ // this exception
+ }
+ }
+ getChangeEvents().remove(eventBean);
+ }
+ // cause is to lock calls others events
+ if (switcher != null &&
+ switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE))
+ try {
+ sourceSelectionChanged();
+ /*
+ * https://jira.jboss.org/jira/browse/JBIDE-3619
+ * VpeViewUpdateJob takes place after toolbar selection have been updated.
+ * New nodes haven't been put into dom mapping
+ * thus toolbar becomes desabled.
+ * Updating toolbar state here takes into account updated vpe nodes.
+ */
+ if (toolbarFormatControllerManager != null) {
+ toolbarFormatControllerManager.selectionChanged();
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ monitor.done();
+ return Status.OK_STATUS;
+ }
+ };
+ }
+
+ if (uiJob.getState() != Job.RUNNING) {
+ uiJob.setPriority(Job.LONG);
+ // Fix of JBIDE-1900
+ uiJob.schedule(getVpeUpdateDelayTime());
+ } else {
+ uiJob.cancel();
+ uiJob.schedule(getVpeUpdateDelayTime());
+ setVpeUpdateDelayTime(400);
+ }
+
+ return;
+ }
+ // start job when we modify file in non ui thread
+ if (job != null) {
+ job.cancel();
+ }
+
+ job = new UIJob("NotifyChangedJob") {
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ // we checks is job was canceled and if is it true we cancel job
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ } else {
+ notifyChangedInUiThread(notifier, eventType, feature, oldValue, newValue, pos);
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setPriority(Job.LONG);
+ job.schedule(1000L);
+ }
+
+ public void notifyChangedInUiThread(INodeNotifier notifier, int eventType,
+ Object feature, Object oldValue, Object newValue, int pos) {
+ if (switcher == null ||
+ !switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ try {
+ if (VpeDebug.PRINT_SOURCE_MUTATION_EVENT) {
+ printSourceEvent(notifier, eventType, feature, oldValue, newValue, pos);
+ }
+ if (visualBuilder == null) {
+ return;
+ }
+ // visualBuilder.rebuildFlag = false;
+ switch (eventType) {
+ case INodeNotifier.CHANGE:
+ sourceChangeFlag = true;
+ int type = ((Node) notifier).getNodeType();
+ visualEditor.hideResizer();
+ visualBuilder.setSelectionRectangle(null);
+ if (type == Node.TEXT_NODE) {
+ boolean update = visualBuilder.setText((Node) notifier);
+ visualEditor.showResizer();
+ // Added by Max Areshkau JBIDE-1554
+ if (!update)
+ visualBuilder.updateNode((Node) notifier);
+ } else if (type == Node.COMMENT_NODE) {
+ if ("yes".equals(VpePreference.SHOW_COMMENTS.getValue())) { //$NON-NLS-1$
+ visualBuilder.setSelectionRectangle(null);
+ visualBuilder.updateNode((Node) notifier);
+ }
+ } else if (feature != null
+ && ((Node) feature).getNodeType() == Node.ATTRIBUTE_NODE) {
+ if (newValue != null) {
+ String attrName = ((Attr) feature).getName();
+ if ((Attr) feature == lastRemovedAttr
+ && !attrName.equals(lastRemovedAttrName)) {
+ lastRemovedAttr = null;
+ visualBuilder.removeAttribute((Element) notifier, lastRemovedAttrName);
+ }
+ visualBuilder.setAttribute((Element) notifier,
+ ((Attr) feature).getName(), (String) newValue);
+ } else {
+ lastRemovedAttr = (Attr) feature;
+ lastRemovedAttrName = ((Attr) feature).getName();
+ visualBuilder.removeAttribute((Element) notifier, lastRemovedAttrName);
+ }
+ }
+ visualEditor.showResizer();
+ break;
+
+ case INodeNotifier.ADD:
+ // we should remove all parent nodes from vpe cash
+ visualBuilder.removeNode((Node) newValue);
+ break;
+
+ case INodeNotifier.REMOVE:
+ visualBuilder.stopToggle((Node) feature);
+ visualBuilder.removeNode((Node) feature);
+ break;
+
+ case INodeNotifier.STRUCTURE_CHANGED:
+ visualEditor.hideResizer();
+ visualBuilder.setSelectionRectangle(null);
+ visualBuilder.updateNode((Node) notifier);
+ break;
+ case INodeNotifier.CONTENT_CHANGED:
+ if (!sourceChangeFlag) {
+ if (feature != null
+ && ((Node) feature).getNodeType() == Node.TEXT_NODE) {
+ // if
+ // (((Node)notifier).getNodeName().equalsIgnoreCase(
+ // "style"))
+ // {
+ visualEditor.hideResizer();
+ visualBuilder.setSelectionRectangle(null);
+ visualBuilder.setText((Node) feature);
+ visualEditor.showResizer();
+ // }
+ }
+ } else {
+ sourceChangeFlag = false;
+ }
+ break;
+ }
+ } finally {
+ // fix for jbide-675, swithcer is null when vpecontroller is
+ // disposed
+ if (switcher != null) {
+ switcher.stopActiveEditor();
+ } else {
+ throw new VpeDisposeException("VpeController already disposed");
+ }
+ }
+ }
+
+ // INodeSelectionListener implementation
+ public void nodeSelectionChanged(NodeSelectionChangedEvent event) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ try {
+ List<?> nodes = event.getSelectedNodes();
+ if (nodes != null && nodes.size() > 0) {
+ Node sourceNode = (Node) nodes.get(0);
+ if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
+ System.out.println(">>>>>>>>>>>>>> nodeSelectionChanged sourceNode: " + //$NON-NLS-1$
+ sourceNode.getNodeName() + Constants.WHITE_SPACE + event.getCaretPosition());
+ }
+ if (event.getSource() instanceof IContentOutlinePage) {
+ sourceSelectionChanged();
+ }
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ // ITextSelectionListener implementation
+ // TODO Max Areshau looks like this method don't used
+ public void textSelectionChanged(TextSelectionChangedEvent event) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ try {
+ if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
+ System.out.println(">>>>>>>>>>>>>> textSelectionChanged " + event.getSource()); //$NON-NLS-1$
+ }
+ // if (event.getSource() instanceof StyledText) {
+ sourceSelectionChanged();
+ // }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ // SelectionListener implementation
+ public void widgetSelected(SelectionEvent event) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ try {
+ if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
+ System.out.println(">>>>>>>>>>>>>> widgetSelected"); //$NON-NLS-1$
+ }
+ if (event.getSource() instanceof StyledText) {
+ sourceSelectionChanged();
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent event) {
+ if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
+ System.out.println(">>>>>>>>>>>>>> widgetDefaultSelected"); //$NON-NLS-1$
+ }
+ }
+
+ public void sourceSelectionChanged() {
+ sourceSelectionChanged(false);
+ }
+
+ public void sourceSelectionChanged(boolean showCaret) {
+ // we should processed if we have correct view in visual editor,
+ // otherwise we shouldn't process this event
+ if (getChangeEvents().size() > 0) {
+ return;
+ }
+
+// Point range = sourceEditor.getTextViewer().getSelectedRange();
+// int anchorPosition = range.x;
+// int focusPosition = range.x + range.y;
+//
+// boolean extendFlag = range.y != 0;
+// boolean reversionFlag = extendFlag
+// && anchorPosition == VpeSelectionHelper
+// .getCaretOffset(sourceEditor);
+// if (reversionFlag) {
+// anchorPosition = focusPosition;
+// focusPosition = range.x;
+// }
+
+ if (selectionManager != null)
+ selectionManager.refreshVisualSelection();
+
+ // VpeTemplate template = TemplateManagingUtil
+ // .getTemplateBySourceSelection(pageContext, focusPosition,
+ // anchorPosition);
+ //
+ // if (template instanceof ITemplateSelectionManager) {
+ // ((ITemplateSelectionManager) template).setSelectionBySource(
+ // pageContext, visualSelectionController, focusPosition,
+ // anchorPosition);
+ // return;
+ // }
+ //
+ // Node focusNode = getSourceNodeAt(focusPosition);
+ // if (focusNode == null) {
+ // return;
+ // }
+ // int focusOffset = getSourceNodeOffset(focusNode, focusPosition,
+ // extendFlag && !reversionFlag);
+ // Node anchorNode = null;
+ // int anchorOffset = 0;
+ // if (extendFlag) {
+ // anchorNode = getSourceNodeAt(anchorPosition);
+ // anchorOffset = getSourceNodeOffset(anchorNode, anchorPosition,
+ // reversionFlag);
+ // } else {
+ // anchorNode = focusNode;
+ // anchorOffset = focusOffset;
+ // }
+ //
+ // if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
+ // System.out.println("sourceSelectionChanged"); //$NON-NLS-1$
+ // System.out
+ // .println(" anchorNode: " + anchorNode.getNodeName() + " anchorOffset: " + anchorOffset); //$NON-NLS-1$ //$NON-NLS-2$
+ // System.out
+ // .println(" focusNode: " + focusNode.getNodeName() + " focusOffset: " + focusOffset + " focusPosition: " + focusPosition); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ // }
+ // try {
+ // if (anchorNode.getNodeType() == Node.TEXT_NODE
+ // || anchorNode.getNodeType() == Node.ATTRIBUTE_NODE) {
+ // String text;
+ // if (anchorNode.getNodeType() == Node.TEXT_NODE) {
+ // IndexedRegion region = (IndexedRegion) anchorNode;
+ // text = sourceEditor.getTextViewer().getDocument().get(
+ // region.getStartOffset(),
+ // region.getEndOffset() - region.getStartOffset());
+ // } else {
+ // text = ((AttrImpl) anchorNode).getValueRegionText();
+ // }
+ // anchorOffset = TextUtil.visualPosition(text, anchorOffset);
+ // }
+ // if (focusNode.getNodeType() == Node.TEXT_NODE
+ // || focusNode.getNodeType() == Node.ATTRIBUTE_NODE) {
+ // IndexedRegion region = (IndexedRegion) focusNode;
+ // String text;
+ // if (focusNode.getNodeType() == Node.TEXT_NODE) {
+ // text = sourceEditor.getTextViewer().getDocument().get(
+ // region.getStartOffset(),
+ // region.getEndOffset() - region.getStartOffset());
+ // } else {
+ // text = ((AttrImpl) focusNode).getValueRegionText();
+ // }
+ // focusOffset = TextUtil.visualPosition(text, focusOffset);
+ // }
+ // } catch (Exception ex) {
+ // VpePlugin.reportProblem(ex);
+ // }
+ //
+ // selectionBuilder.setVisualSelection(anchorNode, anchorOffset,
+ // focusNode, focusOffset, reversionFlag, showCaret);
+ }
+
+ public void sourceSelectionToVisualSelection(boolean showCaret) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ try {
+ sourceSelectionChanged(showCaret);
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ // IModelLifecycleListener implementation
+ public void processPreModelEvent(ModelLifecycleEvent event) {
+ }
+
+ public void processPostModelEvent(ModelLifecycleEvent event) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ try {
+ /*
+ * Added by Max Areshkau JBIDE-1457
+ * ModelLifecycleEvent.MODEL_RELEASED is generated when model in model
+ * calls methods releaseFromRead() or releaseFromEdit(). When editor
+ * is open he has only when href on model, so nothing can generated
+ * this event.When editor closes generation of this event depends
+ * from containing any service href on model or not. It's can be a
+ * reason of problems on reopen file.
+ *
+ * We shouldn't call here rebuild dom.
+ */
+ if (event.getType() == ModelLifecycleEvent.MODEL_RELEASED) {
+ if (VpeDebug.PRINT_SOURCE_MODEL_LIFECYCLE_EVENT) {
+ System.out.println(">>> processPostModelEvent: " + event.toString()); //$NON-NLS-1$
+ }
+ // commented to fix org.mozilla.xpcom.XPCOMException: The function "repaint" returned an error condition (0x8000ffff)
+ //visualBuilder.setSelectionRectangle(null);
+ IStructuredModel model = event.getModel();
+ model.removeModelLifecycleListener(this);
+ IDOMModel sourceModel = (IDOMModel) getModel();
+ sourceModel.addModelLifecycleListener(this);
+ bundle.clearAll();
+ bundle.refresh();
+ //visualBuilder.setSelectionRectangle(null);
+ IDOMDocument sourceDocument = sourceModel.getDocument();
+ // JBIDE-1457
+ // visualBuilder.rebuildDom(sourceDocument);
+ // pageContext.fireTaglibsChanged();
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ // EditorDomEventListener implementation
+ public void subtreeModified(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ public void nodeInserted(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ nsIDOMNode targetNode = mutationEvent.getRelatedNode();
+ if (!VpeVisualDomBuilder.isAnonElement(targetNode)) {
+ sourceBuilder.addNode(targetNode);
+ visualBuilder.resetPseudoElement(targetNode);
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ public void nodeRemoved(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
+ if (!VpeVisualDomBuilder.isAnonElement(targetNode)) {
+ visualBuilder.setSelectionRectangle(null);
+ sourceBuilder.removeNode(targetNode);
+ visualBuilder.resetPseudoElement(targetNode);
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ public void nodeRemovedFromDocument(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ public void nodeInsertedIntoDocument(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ public void attrModified(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ public void characterDataModified(nsIDOMMutationEvent mutationEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ if (VpeDebug.PRINT_VISUAL_MUTATION_EVENT) {
+ printVisualEvent(mutationEvent);
+ }
+ nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
+ sourceBuilder.setText(targetNode);
+ visualBuilder.resetPseudoElement(targetNode);
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ public void notifySelectionChanged(nsIDOMDocument doc, nsISelection selection, short reason) {
+ if (switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ try {
+ mouseUpSelectionReasonFlag = (reason & nsISelectionListener.MOUSEUP_REASON) > 0;
+ if (mouseUpSelectionReasonFlag
+ // commited by Dzmitrovich - experimental
+ // TODO check selection and if are appear errors then
+ // uncommented next code
+ // || reason == nsISelectionListener.NO_REASON
+ || reason == nsISelectionListener.KEYPRESS_REASON
+ || reason == nsISelectionListener.SELECTALL_REASON
+ || (reason & nsISelectionListener.MOUSEDOWN_REASON) > 0) {
+ if (VpeDebug.PRINT_VISUAL_SELECTION_EVENT) {
+ System.out.println("<<< notifySelectionChanged: " + reason); //$NON-NLS-1$
+ }
+ nsIDOMNode node = SelectionUtil.getSelectedNode(selection);
+ /*
+ * Fixes https://jira.jboss.org/jira/browse/JBIDE-2571
+ * Checking if the node is of text type was removed
+ * to allow <select> node to be selected on the first click.
+ */
+ if (node != null) {
+ selectionManager.setSelection(selection);
+ }
+ }
+ //enables cursor on selection event
+ visualSelectionController.setCaretEnabled(true);
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+ }
+
+ public void mouseDown(nsIDOMMouseEvent mouseEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ // mouseDownSelectionFlag = false;
+ // VpeTemplate template = TemplateManagingUtil
+ // .getTemplateByVisualSelection(pageContext, VisualDomUtil
+ // .getTargetNode(mouseEvent));
+ // if (template instanceof ITemplateSelectionManager) {
+ // ((ITemplateSelectionManager) template).setSelectionByMouse(
+ // pageContext, visualSelectionController, mouseEvent);
+ // mouseDownSelectionFlag = true;
+ // } else {
+ // nsIDOMElement visualDragElement = selectionBuilder
+ // .getDragElement(mouseEvent);
+ if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
+ System.out.println("<<< mouseDown targetNode: " /* //$NON-NLS-1$
+ * +visualNode.
+ * getNodeName()
+ * + " (" +
+ * visualNode +
+ * ") selectedElement: "
+ * +(
+ * visualDragElement
+ * != null ?
+ * visualDragElement
+ * .
+ * getNodeName()
+ * + " (" +
+ * visualDragElement
+ * + ")" : null)
+ */);
+ }
+ //
+ // if (visualDragElement != null) {
+ //
+ // // we shouldn't change selection when we click on <input
+ // // type="text" /> element,
+ // // because if we change after resizing the input element
+ // // lost
+ // // selection
+ // // if(!(HTML.TAG_INPUT.equalsIgnoreCase(visualDragElement.
+ // // getNodeName())&&
+ // // HTML.ATTR_TEXT.equalsIgnoreCase(visualDragElement.
+ // // getAttribute(HTML.ATTR_TYPE))
+ // // &&visualDragElement.getAttribute(HTML.ATTR_TYPE)!=null))
+ // // {
+ //
+ // selectionBuilder
+ // .setVisualElementSelection(visualDragElement);
+ // mouseDownSelectionFlag = true;
+ // // }
+ // } else {
+ // selectionBuilder.setCaretAtMouse(mouseEvent);
+ // }
+ // }
+
+ // selection will be set only if press left button
+ if (mouseEvent.getButton() == LEFT_BUTTON)
+ selectionManager.setSelection(mouseEvent);
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ public void mouseUp(nsIDOMMouseEvent mouseEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+
+ if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
+ System.out.println("<<< mouseUp"); //$NON-NLS-1$
+ }
+ if (mouseDownSelectionFlag) {
+ mouseEvent.preventDefault();
+ mouseEvent.stopPropagation();
+ mouseDownSelectionFlag = false;
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ public void mouseClick(nsIDOMMouseEvent mouseEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
+ if (visualNode != null) {
+ if (!mouseUpSelectionReasonFlag) {
+ if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
+ System.out.println("<<< mouseClick visualNode: " + visualNode.getNodeName() + //$NON-NLS-1$
+ " (" + visualNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (visualBuilder.isContentArea(visualNode)) {
+ // selectionBuilder.setClickContentAreaSelection();
+ }
+ } else {
+ mouseUpSelectionReasonFlag = false;
+ }
+
+ if (visualBuilder.doToggle(VisualDomUtil.getTargetNode(mouseEvent))) {
+ // selectionBuilder.setClickContentAreaSelection();
+ }
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ public void mouseDblClick(nsIDOMMouseEvent mouseEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
+ if (visualNode != null) {
+ if (!sourceBuilder.openBundleEditors(visualNode)) {
+ sourceBuilder.openIncludeEditor(visualNode);
+ }
+ if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
+ System.out.println("<<< mouseDblClick visualNode: " + visualNode.getNodeName() + //$NON-NLS-1$
+ " (" + visualNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ public void mouseMove(nsIDOMMouseEvent mouseEvent) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
+ if (visualNode != null) {
+ // if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
+ // System.out.println("<<< mouseMove visualNode: "
+ // + visualNode.getNodeName() + " (" + visualNode
+ // + ")");
+ // }
+ visualBuilder.setMoveCursor(mouseEvent);
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ public void keyPress(nsIDOMKeyEvent keyEvent) {
+ if (VpeDebug.PRINT_VISUAL_KEY_EVENT) {
+ System.out.println("<<< keyPress type: " + keyEvent.getType() + //$NON-NLS-1$
+ " Ctrl: " + keyEvent.getCtrlKey() + " Shift: " + keyEvent.getShiftKey() + //$NON-NLS-1$ //$NON-NLS-2$
+ " CharCode: " + keyEvent.getCharCode() + " KeyCode: " + keyEvent.getKeyCode()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ switcher.stopActiveEditor();
+ return;
+ }
+ try {
+ visualEditor.hideResizer();
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ setVpeUpdateDelayTime(0);
+ /*
+ * adding calls of core event handlers, for example' CTR+H' or
+ * 'CTRL+M' event handler dialog
+ */
+ boolean keyBindingPressed = false;
+ Event keyboardEvent = new Event();
+ /*
+ * widget where event occur
+ */
+ keyboardEvent.widget = xulRunnerEditor.getBrowser();
+
+ keyboardEvent.stateMask = (keyEvent.getAltKey() ? SWT.ALT : 0)
+ | (keyEvent.getCtrlKey() ? SWT.CTRL : 0)
+ | (keyEvent.getShiftKey() ? SWT.SHIFT : 0)
+ | (keyEvent.getMetaKey() ? SWT.MOD1 : 0);
+ keyboardEvent.x = 0;
+ keyboardEvent.y = 0;
+ keyboardEvent.type = SWT.KeyDown;
+
+ if (keyEvent.getKeyCode() == 0) {
+ keyboardEvent.keyCode = (int) keyEvent.getCharCode();
+ } else {
+ keyboardEvent.keyCode = (int) keyEvent.getKeyCode();
+ }
+ /*
+ * JBIDE-1627
+ */
+ List<KeyStroke> possibleKeyStrokes = WorkbenchKeyboard
+ .generatePossibleKeyStrokes(keyboardEvent);
+ IWorkbench iWorkbench = VpePlugin.getDefault().getWorkbench();
+ if (iWorkbench.hasService(IBindingService.class)) {
+ IBindingService iBindingService = (IBindingService) iWorkbench
+ .getService(IBindingService.class);
+
+ KeySequence sequenceBeforeKeyStroke = KeySequence.getInstance();
+
+ for (Iterator<KeyStroke> iterator = possibleKeyStrokes.iterator(); iterator.hasNext();) {
+ KeySequence sequenceAfterKeyStroke =
+ KeySequence.getInstance(sequenceBeforeKeyStroke, iterator.next());
+ if (iBindingService.isPerfectMatch(sequenceAfterKeyStroke)) {
+ final Binding binding = iBindingService.getPerfectMatch(sequenceAfterKeyStroke);
+ if ((binding != null)
+ && (binding.getParameterizedCommand() != null)
+ && (binding.getParameterizedCommand().getCommand() != null)) {
+ keyBindingPressed = true;
+ }
+ }
+ }
+ }
+ /*
+ * Sends xulrunner event to eclipse environment.
+ * dmaliarevich: while fixing JBIDE-2562 I found that
+ * eclipse handles key shortcuts without this notification.
+ */
+ // getXulRunnerEditor().getBrowser().notifyListeners(
+ // keyboardEvent.type, keyboardEvent);
+
+ /*
+ * Fixes https://jira.jboss.org/jira/browse/JBIDE-2562
+ * author: dmaliarevich
+ *
+ * When shortcut key is pressed do not handle this event in the
+ * handler.
+ */
+ if (!keyBindingPressed) {
+ if (keyEventHandler.handleKeyPress(keyEvent)) {
+ /*
+ * JBIDE-2670
+ */
+ keyEvent.preventDefault();
+// switcher
+// .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL);
+// try {
+ /*
+ * Edward
+ */
+ // commented by sdzmitrovich because cursor disappear after
+ // trying to edit of read-only elements
+ // TODO check editing and if are appear errors then
+ // uncommented next code
+// sourceSelectionChanged(true);
+// visualSelectionController.setCaretEnabled(true);
+
+// } finally {
+// switcher.stopActiveEditor();
+// }
+ }
+ }
+ }
+
+ public void elementResized(nsIDOMElement element, int resizerConstrains,
+ int top, int left, int width, int height) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ visualEditor.hideResizer();
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ visualBuilder.resize(element, resizerConstrains, top, left, width, height);
+ sourceSelectionChanged();
+ }
+
+ public void dragGesture(nsIDOMEvent domEvent) {
+ nsIDOMMouseEvent mouseEvent =
+ (nsIDOMMouseEvent) domEvent.queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID);
+ boolean canDragFlag = canInnerDrag(mouseEvent);
+ // start drag sessionvpe-element
+ if (canDragFlag) {
+ startDragSession(domEvent);
+ }
+ }
+
+ /**
+ * Calls when on when browser receive context menu event.
+ *
+ * @param contextFlags
+ * -not used in this function, just for because this parameter
+ * exist in nsIContextMenuListener
+ * @param event
+ * event from browser used here
+ * @param node
+ * where this event are occur
+ */
+ public void onShowContextMenu(long contextFlags, nsIDOMEvent event, nsIDOMNode node) {
+ //FIXED FOR JBIDE-3072 by sdzmitrovich
+
+// nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
+// if (visualNode != null) {
+ Node selectedSourceNode = null;
+
+ VpeNodeMapping nodeMapping = SelectionUtil.getNodeMappingBySourceSelection(sourceEditor, domMapping);
+ if (nodeMapping != null) {
+ selectedSourceNode = nodeMapping.getSourceNode();
+ }
+
+ MenuManager menuManager = new MenuManager("#popup"); //$NON-NLS-1$
+ final Menu contextMenu = menuManager.createContextMenu(visualEditor.getControl());
+ contextMenu.addMenuListener(new MenuListener() {
+ Menu menu = contextMenu;
+ public void menuHidden(MenuEvent e) {
+ Display.getCurrent().asyncExec(new Runnable() {
+ public void run() {
+ menu.dispose();
+ }
+ });
+ }
+ public void menuShown(MenuEvent e) {
+ }
+ });
+
+ // create context menu
+ MenuCreationHelper menuCreationHelper =
+ new MenuCreationHelper(domMapping, pageContext, sourceEditor, visualEditor);
+ menuCreationHelper.createMenuForNode(selectedSourceNode, menuManager, true);
+
+ contextMenu.setVisible(true);
+// }
+ }
+
+ // VpeTemplateListener implementation
+ public void templateReloaded() {
+ visualRefresh();
+ }
+
+ public void visualRefresh() {
+ if (!isVisualEditorVisible()) {
+ setSynced(false);
+ return;
+ }
+ if (uiJob != null && uiJob.getState() != Job.NONE) {
+ return;
+ }
+ if (visualRefreshJob == null || visualRefreshJob.getState() == Job.NONE) {
+ visualRefreshJob = new UIJob(VpeUIMessages.VPE_VISUAL_REFRESH_JOB) {
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return Status.CANCEL_STATUS;
+ }
+ try {
+ monitor.beginTask(VpeUIMessages.VPE_VISUAL_REFRESH_JOB, IProgressMonitor.UNKNOWN);
+ visualRefreshImpl();
+ monitor.done();
+ setSynced(true);
+ } catch (VpeDisposeException exc) {
+ // just ignore this exception
+ } catch (NullPointerException ex) {
+ if (switcher != null) {
+ throw ex;
+ } else {
+ // class was disposed and exception result of
+ // that we can't stop
+ // refresh job in time, so we just ignore this
+ // exception
+ }
+ } finally {
+ if (switcher != null) {
+ switcher.stopActiveEditor();
+ }
+ }
+ return Status.OK_STATUS;
+ }
+ };
+
+ visualRefreshJob.setPriority(Job.SHORT);
+ visualRefreshJob.schedule();
+ }
+ }
+
+ void visualRefreshImpl() {
+ visualEditor.hideResizer();
+
+ String currentDoctype = DocTypeUtil.getDoctype(visualEditor.getEditorInput());
+ /*
+ * https://jira.jboss.org/jira/browse/JBIDE-3591
+ * Avoid using missing resource.
+ */
+ String visualEditorDoctype = visualEditor.getDoctype();
+ if ((null != currentDoctype) && (null != visualEditorDoctype)
+ && (!visualEditorDoctype.equals(currentDoctype))) {
+ visualEditor.reload();
+ } else {
+ //Fix bugs JBIDE-2750
+ visualBuilder.setSelectionRectangle(null);
+ visualEditor.reload();
+// IDOMModel sourceModel = (IDOMModel) getModel();
+// if (sourceModel != null) {
+// IDOMDocument sourceDocument = sourceModel.getDocument();
+// visualBuilder.rebuildDom(sourceDocument);
+// } else {
+// visualBuilder.rebuildDom(null);
+// }
+ }
+ }
+
+ public void preLongOperation() {
+ switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL);
+ }
+
+ public void postLongOperation() {
+ switcher.stopActiveEditor();
+ visualRefresh();
+ }
+
+ // for debug
+ private void printSourceEvent(INodeNotifier notifier, int eventType,
+ Object feature, Object oldValue, Object newValue, int pos) {
+ System.out.println(">>> eventType: " + INodeNotifier.EVENT_TYPE_STRINGS[eventType] + //$NON-NLS-1$
+ " pos: " + pos + " notifier: " + ((Node) notifier).getNodeName() + //$NON-NLS-1$ //$NON-NLS-2$
+ " hashCode: " + notifier.hashCode()); //$NON-NLS-1$
+ if (feature != null) {
+ if (feature instanceof Node) {
+ System.out.println(" feature: " + ((Node) feature).getNodeType() + //$NON-NLS-1$
+ Constants.WHITE_SPACE + ((Node) feature).getNodeName() +
+ " hashCode: " + feature.hashCode()); //$NON-NLS-1$
+ } else {
+ System.out.println(" feature: " + feature); //$NON-NLS-1$
+ }
+ }
+ if (oldValue != null) {
+ if (oldValue instanceof Node) {
+ System.out.println(" oldValue: " + ((Node) oldValue).getNodeName() + //$NON-NLS-1$
+ " hashCode: " + oldValue.hashCode()); //$NON-NLS-1$
+ } else {
+ System.out.println(" oldValue: " + oldValue); //$NON-NLS-1$
+ }
+ }
+ if (newValue != null) {
+ if (newValue instanceof Node) {
+ System.out.println(" newValue: " + ((Node) newValue).getNodeName() + //$NON-NLS-1$
+ " hashCode: " + newValue.hashCode() + Constants.WHITE_SPACE + ((Node) newValue).getNodeType()); //$NON-NLS-1$
+ } else {
+ System.out.println(" newValue: " + newValue); //$NON-NLS-1$
+ }
+ }
+ }
+
+ private void printVisualEvent(nsIDOMEvent event) {
+ System.out.print("<<< " + event.getType()); //$NON-NLS-1$
+
+ if (event instanceof nsIDOMMutationEvent) {
+ nsIDOMMutationEvent mutationEvent = (nsIDOMMutationEvent) event;
+
+ System.out.print(" EventPhase: " + mutationEvent.getEventPhase()); //$NON-NLS-1$
+
+ nsIDOMNode relatedNode = mutationEvent.getRelatedNode();
+ System.out.print(" RelatedNode: " + (relatedNode == null ? null : relatedNode.getNodeName())); //$NON-NLS-1$
+
+ nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
+ String name = targetNode != null ? targetNode.getNodeName() : null;
+ System.out.print(" TargetNode: " + name + " (" + targetNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ System.out.print(" PrevValue: " + mutationEvent.getPrevValue().trim()); //$NON-NLS-1$
+ System.out.print(" NewValue: " + mutationEvent.getNewValue().trim()); //$NON-NLS-1$
+ }
+ System.out.println();
+ }
+
+ private class ActiveEditorSwitcher {
+ private static final int ACTIVE_EDITOR_CANNOT = 0;
+ private static final int ACTIVE_EDITOR_NONE = 1;
+ private static final int ACTIVE_EDITOR_SOURCE = 2;
+ private static final int ACTIVE_EDITOR_VISUAL = 3;
+
+ private int type = ACTIVE_EDITOR_CANNOT;
+
+ private void initActiveEditor() {
+ type = ACTIVE_EDITOR_NONE;
+ }
+
+ private void destroyActiveEditor() {
+ type = ACTIVE_EDITOR_CANNOT;
+ }
+
+ private boolean startActiveEditor(int newType) {
+ if (type == ACTIVE_EDITOR_NONE) {
+ if (newType == ACTIVE_EDITOR_SOURCE
+ && editPart.getVisualMode() == VpeEditorPart.SOURCE_MODE) {
+ return false;
+ }
+ type = newType;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private void stopActiveEditor() {
+ onRefresh();
+ type = ACTIVE_EDITOR_NONE;
+ }
+ }
+
+// void refreshBundleValues() {
+// if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+// return;
+// }
+// try {
+// if (bundle != null) {
+// bundle.refresh();
+// if (pageContext != null) {
+// pageContext.refreshBundleValues();
+// }
+// }
+// } finally {
+// switcher.stopActiveEditor();
+// }
+// }
+//
+ void refreshTemplates() {
+ if (includeList.includesRefresh()) {
+ visualRefresh();
+ }
+
+ VpeTemplateManager.getInstance().reload();
+
+ if (bundle != null) {
+ bundle.refresh();
+ if (pageContext != null) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ try {
+ pageContext.refreshBundleValues();
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+ }
+ }
+
+ // implements XModelTreeListener
+ public void nodeChanged(XModelTreeEvent event) {
+ visualRefresh();
+ }
+
+ public void structureChanged(XModelTreeEvent event) {
+ }
+
+// private Node getSourceNodeAt(int offset) {
+// if (sourceEditor != null && getModel() != null) {
+// IndexedRegion node = getModel().getIndexedRegion(offset);
+// if (node instanceof IDOMNode) {
+// VpeElementMapping elementMapping = domMapping
+// .getNearElementMapping((IDOMNode) node);
+// if (elementMapping != null) {
+// if (node instanceof IDOMElement) {
+// IDOMElement element = (IDOMElement) node;
+//
+// if (offset < element.getEndStartOffset()) {
+// NamedNodeMap attrs = element.getAttributes();
+// if (attrs != null) {
+// for (int i = 0; i < attrs.getLength(); i++) {
+// if (attrs.item(i) instanceof AttrImpl) {
+// AttrImpl attr = (AttrImpl) attrs.item(i);
+// if (getSourceAttributeOffset(attr, offset) != -1) {
+// String[] atributeNames = elementMapping.getTemplate().getOutputAtributeNames();
+// if (atributeNames != null
+// && atributeNames.length > 0
+// && attr.getName().equalsIgnoreCase(atributeNames[0])) {
+// return attr;
+// }
+// }
+// }
+// }
+// }
+// }
+// }
+// }
+// }
+// if (node == null) {
+// node = getModel().getIndexedRegion(offset - 1);
+// }
+// if (node instanceof Node) {
+// return (Node) node;
+// }
+// }
+// return null;
+// }
+//
+// private int getSourceNodeOffset(Node node, int pos, boolean endFlag) {
+// if (node == null)
+// return 0;
+// int start = ((IndexedRegion) node).getStartOffset();
+// int end = ((IndexedRegion) node).getEndOffset();
+//
+// switch (node.getNodeType()) {
+// case Node.ATTRIBUTE_NODE:
+// if (node instanceof AttrImpl) {
+// return getSourceAttributeOffset((AttrImpl) node, pos);
+// }
+// case Node.TEXT_NODE:
+// if (pos < start) {
+// return 0;
+// } else if (pos > end) {
+// return end - start;
+// } else {
+// return pos - start;
+// }
+// case Node.COMMENT_NODE:
+// if (pos > end) {
+// pos = end;
+// }
+// int offset = pos - start - 4;
+// return offset < 0 ? 0 : offset;
+// case Node.ELEMENT_NODE:
+// ElementImpl element = (ElementImpl) node;
+// if (element.isContainer()) {
+// if (pos < element.getStartEndOffset()) {
+// return 0;
+// } else {
+// return 1;
+// }
+// } else {
+// return endFlag ? 1 : 0;
+// }
+// default:
+// return endFlag ? 1 : 0;
+// }
+// }
+//
+// private int getSourceAttributeOffset(AttrImpl attr, int pos) {
+// if (attr.getValueRegion() != null) {
+// int start = attr.getValueRegionStartOffset();
+// String value = attr.getValueRegionText();
+// int len = value.length();
+// if (pos >= start && pos <= start + len) {
+// int offset = pos - start;
+// if (len > 1 && value.charAt(0) == '"'
+// && value.charAt(len - 1) == '"') {
+// if (offset <= 0 || offset >= len) {
+// return -1;
+// }
+// offset--;
+// }
+// return offset;
+// }
+// }
+// return -1;
+// }
+//
+// private int getSourceNodeOffset1(Node node, int pos, boolean endFlag) {
+// if (node == null)
+// return 0;
+// int start = ((IndexedRegion) node).getStartOffset();
+// int end = ((IndexedRegion) node).getEndOffset();
+//
+// switch (node.getNodeType()) {
+// case Node.ATTRIBUTE_NODE:
+// if (node instanceof AttrImpl) {
+// AttrImpl attr = (AttrImpl) node;
+// start = attr.getValueRegionStartOffset();
+// end = start + attr.getValueRegion().getLength();
+// int ret = 0;
+// if (pos > end) {
+// ret = end - start;
+// } else {
+// ret = pos - start;
+// }
+// if (ret > 0 && attr.getValueRegionText().charAt(0) == '"') {
+// ret--;
+// }
+// return ret;
+// }
+// case Node.TEXT_NODE:
+// if (pos < start) {
+// return 0;
+// } else if (pos > end) {
+// return end - start;
+// } else {
+// return pos - start;
+// }
+// case Node.COMMENT_NODE:
+// if (pos > end) {
+// pos = end;
+// }
+// int offset = pos - start - 4;
+// return offset < 0 ? 0 : offset;
+// case Node.ELEMENT_NODE:
+// ElementImpl element = (ElementImpl) node;
+// if (element.isContainer()) {
+// if (pos < element.getStartEndOffset()) {
+// return 0;
+// } else if (pos < element.getStartEndOffset()) {
+// return 1;
+// } else if (pos == element.getStartEndOffset()) {
+// return 2;
+// }
+// } else {
+// return endFlag ? 1 : 0;
+// }
+// default:
+// return endFlag ? 1 : 0;
+// }
+// }
+
+ class VpeSelectionProvider implements ISelectionProvider {
+ VpeSelection selection;
+
+ public VpeSelectionProvider(IndexedRegion region) {
+ selection = new VpeSelection(region);
+ }
+
+ public VpeSelectionProvider(int position) {
+ selection = new VpeSelection(position);
+ }
+
+ public VpeSelectionProvider(int offset, int length) {
+ selection = new VpeSelection(offset, length);
+ }
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ }
+
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ }
+
+ public ISelection getSelection() {
+ return selection;
+ }
+
+ public void setSelection(ISelection selection) {
+ }
+ }
+
+ class VpeSelection implements ITextSelection {
+ String text = ""; //$NON-NLS-1$
+ int offset, length;
+
+ public VpeSelection(int position) {
+ offset = position;
+ length = 0;
+ }
+
+ public VpeSelection(int offset, int length) {
+ this.offset = offset;
+ this.length = length;
+ if (length > 0) {
+
+ try {
+ text = sourceEditor.getTextViewer().getDocument().get(
+ offset, length);
+ } catch (BadLocationException e) {
+ VpePlugin.getPluginLog().logError(e);
+ }
+
+ }
+ }
+
+ public VpeSelection(IndexedRegion region) {
+ offset = region.getStartOffset();
+ length = region.getEndOffset() - offset;
+ try {
+ text = sourceEditor.getTextViewer().getDocument().get(offset,
+ length);
+ } catch (BadLocationException ex) {
+ VpePlugin.reportProblem(ex);
+ }
+ }
+
+ public int getEndLine() {
+ return 0;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ public int getOffset() {
+ return offset;
+ }
+
+ public int getStartLine() {
+ return 0;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public boolean isEmpty() {
+ return false;
+ }
+ }
+
+ public void refreshExternalLinks() {
+ pageContext.getVisualBuilder().refreshExternalLinks();
+ }
+
+ public IPath getPath() {
+ if (editPart != null) {
+ IEditorInput input = editPart.getEditorInput();
+ if (input != null && input instanceof IFileEditorInput) {
+ return ((IFileEditorInput) input).getFile().getFullPath();
+ }
+ }
+ return null;
+ }
+
+ public void changed(Object source) {
+ if (cssReferenceListListener == source) {
+ pageContext.getVisualBuilder().refreshExternalLinks();
+ } else if (absoluteFolderReferenceListListener == source
+ || relativeFolderReferenceListListener == source
+ || taglibReferenceListListener == source
+ || elReferenceListListener == source) {
+ visualRefresh();
+ }
+ }
+
+ public void dragEnter(nsIDOMEvent event) {
+ if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
+ System.out.println("<<<<<<<<<<<<<<<<<<<< DragEnter"); //$NON-NLS-1$
+ }
+ }
+
+ public void dragExit(nsIDOMEvent event) {
+ if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
+ System.out.println("<<<<<<<<<<<<<<<<<<<< dragExit"); //$NON-NLS-1$
+ }
+ // TODO Sergey Vasilyev figure out with drag caret
+ // xulRunnerEditor.hideDragCaret();
+ }
+
+ public void dragOver(nsIDOMEvent event) {
+ visualBuilder.getDnd().dragOver(event, this);
+ }
+
+ public void _dragOver(nsIDOMEvent event) {
+ if (!switcher
+ .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ return;
+ }
+ try {
+ if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
+ System.out.println("<<<<<<<<<<<<<<<<<<<< dragOver"); //$NON-NLS-1$
+ }
+ // browser.computeDropPosition(event);
+ boolean canDrop = !xulRunnerEditor.isMozillaDragFlavor();
+ if (canDrop) {
+ Clipboard clipboard = new Clipboard(Display.getCurrent());
+ canDrop = clipboard.getContents(ModelTransfer.getInstance()) != null;
+ }
+ if (canDrop) {
+ canDrop = VpeDndUtil
+ .isDropEnabled((IModelObjectEditorInput) sourceEditor
+ .getEditorInput());
+ }
+ if (canDrop) {
+ VpeVisualCaretInfo caretInfo = selectionBuilder
+ .getVisualCaretInfo(event);
+ canDrop = caretInfo.exist();
+ if (canDrop) {
+ caretInfo.showCaret();
+ } else {
+ caretInfo.hideCaret();
+ }
+ }
+ if (!canDrop) {
+ event.stopPropagation();
+ event.preventDefault();
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ public void drop(nsIDOMEvent event) {
+ if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
+ System.out.println("<<< outerDrop"); //$NON-NLS-1$
+ }
+ event.preventDefault();
+ }
+
+ public boolean canInnerDrag(nsIDOMMouseEvent event) {
+ onHideTooltip();
+
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.print("<<<<<< canInnerDrag"); //$NON-NLS-1$
+ }
+ if (innerDragInfo != null) {
+ innerDragInfo.Release();
+ innerDragInfo = null;
+ }
+ boolean canDrag = false;
+ VpeVisualInnerDragInfo dragInfo = selectionBuilder
+ .getInnerDragInfo(event);
+ if (dragInfo != null) {
+ nsIDOMNode dragNode = dragInfo.getNode();
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out
+ .print(" dragNode: " + dragNode.getNodeName() + "(" + dragNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ switch (dragNode.getNodeType()) {
+ case nsIDOMNode.ELEMENT_NODE:
+ canDrag = visualBuilder.canInnerDrag((nsIDOMElement) dragNode);
+ case nsIDOMNode.TEXT_NODE:
+ canDrag = visualBuilder.isTextEditable(dragNode);
+ }
+ if (canDrag) {
+ VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder
+ .getSourceInnerDragInfo(dragInfo);
+ if (sourceInnerDragInfo.getNode() != null) {
+ innerDragInfo = dragInfo;
+ InnerDragBuffer.object = sourceInnerDragInfo.getNode();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ InnerDragBuffer.object = null;
+ }
+ });
+ } else {
+ canDrag = false;
+ }
+ }
+ if (!canDrag) {
+ dragInfo.Release();
+ }
+ }
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.println(" canDrag: " + canDrag); //$NON-NLS-1$
+ }
+ return canDrag;
+ }
+
+ VpeDropWindow dropWindow = null;
+
+ public MozillaDropInfo canInnerDrop(nsIDOMMouseEvent event) {
+ onHideTooltip();
+
+ if (dropWindow.active) {
+ if (!event.getAltKey()) {
+ dropWindow.close();
+ } else {
+ return null;
+ }
+ }
+ if (event.getAltKey()) {
+ nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
+ Node sourceNode = domMapping.getNearSourceNode(visualNode);
+ if (sourceNode != null) {
+ dropWindow.active = true;
+ dropWindow.setEventPosition(event.getScreenX(), event
+ .getScreenY());
+ dropWindow.setInitialTargetNode(sourceNode);
+ dropWindow.open();
+ event.stopPropagation();
+ event.preventDefault();
+ return null;
+ }
+ }
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.print("<<<<<< canInnerDrop"); //$NON-NLS-1$
+ }
+ boolean canDrop = false;
+ ;
+ nsIDOMNode caretParent = null;
+ long caretOffset = 0;
+ if (innerDragInfo != null) {
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
+ .getInnerDropInfo(event);
+ if (visualDropInfo.getDropContainer() != null) {
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out
+ .print(" x: " + visualDropInfo.getMouseX() + " y: " + visualDropInfo.getMouseY() + //$NON-NLS-1$ //$NON-NLS-2$
+ " container: "
+ + visualDropInfo.getDropContainer()
+ .getNodeName()
+ + //$NON-NLS-1$
+ "("
+ + visualDropInfo.getDropContainer()
+ + ")" + //$NON-NLS-1$ //$NON-NLS-2$
+ " parent: "
+ + visualDropInfo.getDropContainer()
+ .getParentNode().getNodeName()
+ + //$NON-NLS-1$
+ "("
+ + visualDropInfo.getDropContainer()
+ .getParentNode() + ")" + //$NON-NLS-1$ //$NON-NLS-2$
+ " offset: "
+ + visualDropInfo.getDropOffset()); //$NON-NLS-1$
+ }
+ VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder
+ .getSourceInnerDragInfo(innerDragInfo);
+ VpeSourceInnerDropInfo sourceDropInfo = visualBuilder
+ .getSourceInnerDropInfo(sourceInnerDragInfo.getNode(),
+ visualDropInfo, true);
+ canDrop = sourceDropInfo.canDrop();
+ if (canDrop) {
+ VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder
+ .getInnerDropInfo(sourceDropInfo.getContainer(),
+ sourceDropInfo.getOffset());
+ if (newVisualDropInfo != null) {
+ visualBuilder.correctVisualDropPosition(
+ newVisualDropInfo, visualDropInfo);
+ caretParent = newVisualDropInfo.getDropContainer();
+ caretOffset = newVisualDropInfo.getDropOffset();
+ }
+ }
+ }
+ visualDropInfo.Release();
+ }
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.println(" canDrop: " + canDrop); //$NON-NLS-1$
+ }
+ return new MozillaDropInfo(canDrop, caretParent, caretOffset);
+ }
+
+ public void innerDrop(nsIDOMMouseEvent event) {
+ onHideTooltip();
+
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.print("<<<<<< innerDrop"); //$NON-NLS-1$
+ }
+ if (innerDragInfo != null) {
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
+ .getInnerDropInfo(event);
+ if (visualDropInfo.getDropContainer() != null) {
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out
+ .print(" container: " + visualDropInfo.getDropContainer().getNodeName() + //$NON-NLS-1$
+ "(" + visualDropInfo.getDropContainer()
+ + ")" + //$NON-NLS-1$ //$NON-NLS-2$
+ " offset: "
+ + visualDropInfo.getDropOffset()); //$NON-NLS-1$
+ }
+
+ VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder
+ .getSourceInnerDragInfo(innerDragInfo);
+ VpeSourceInnerDropInfo sourceDropInfo = visualBuilder
+ .getSourceInnerDropInfo(sourceInnerDragInfo.getNode(),
+ visualDropInfo, true);
+ if (sourceDropInfo.canDrop()) {
+ VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder
+ .getInnerDropInfo(sourceDropInfo.getContainer(),
+ sourceDropInfo.getOffset());
+ if (newVisualDropInfo != null) {
+ visualBuilder.correctVisualDropPosition(
+ newVisualDropInfo, visualDropInfo);
+ sourceDropInfo.setTop(visualDropInfo.getMouseY());
+ sourceDropInfo.setLeft(visualDropInfo.getMouseX());
+ visualBuilder.innerDrop(sourceInnerDragInfo,
+ sourceDropInfo);
+ if (innerDragInfo != null) {
+ innerDragInfo.Release();
+ innerDragInfo = null;
+ }
+ }
+ }
+ }
+ }
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.println();
+ }
+ }
+
+ public MozillaDropInfo canExternalDrop(nsIDOMMouseEvent mouseEvent,
+ String flavor, String data) {
+ InnerDragBuffer.object = null;
+ onHideTooltip();
+
+ if (dropWindow.active) {
+ if (!mouseEvent.getAltKey()) {
+ dropWindow.close();
+ } else {
+ return new MozillaDropInfo(false, null, 0);
+ }
+ }
+ if (mouseEvent.getAltKey()) {
+ nsIDOMEvent event = (nsIDOMEvent) mouseEvent
+ .queryInterface(nsIDOMEvent.NS_IDOMEVENT_IID);
+ nsIDOMNode visualNode = (nsIDOMNode) event.getTarget()
+ .queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
+ Node sourceNode = domMapping.getNearSourceNode(visualNode);
+ if (sourceNode != null) {
+ if (ModelTransfer.MODEL.equals(flavor)) { //$NON-NLS-1$
+ // XModelObject object =
+ // PreferenceModelUtilities.getPreferenceModel().
+ // getModelBuffer().source();
+ // InnerDragBuffer.object = object;
+ } else {
+ dropWindow.flavor = flavor;
+ }
+ dropWindow.active = true;
+ dropWindow.setEventPosition(mouseEvent.getScreenX(), mouseEvent
+ .getScreenY());
+ dropWindow.setInitialTargetNode(sourceNode);
+ dropWindow.open();
+ mouseEvent.stopPropagation();
+ mouseEvent.preventDefault();
+ return new MozillaDropInfo(false, null, 0);
+ }
+ }
+ boolean canDrop = false;
+ nsIDOMNode caretParent = null;
+ long caretOffset = 0;
+
+ if (MODEL_FLAVOR.equals(flavor)) {
+ XModelObject object = PreferenceModelUtilities.getPreferenceModel()
+ .getModelBuffer().source();
+ if (object.getFileType() == XModelObject.FILE
+ && !TLDUtil.isTaglib(object)) {
+ IFile f = (IFile) EclipseResourceUtil.getResource(object);
+ canDrop = f != null;
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
+ .getInnerDropInfo(mouseEvent);
+ caretParent = visualDropInfo.getDropContainer();
+ caretOffset = visualDropInfo.getDropOffset();
+ } else {
+ String tagname = getTagName(object);
+ if (tagname.indexOf("taglib") >= 0)tagname = "taglib"; //$NON-NLS-1$ //$NON-NLS-2$
+ Node sourceDragNode = ((Document) getModel().getAdapter(
+ Document.class)).createElement(tagname);
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
+ .getInnerDropInfo(mouseEvent);
+ if (visualDropInfo.getDropContainer() != null) {
+ VpeSourceInnerDropInfo sourceDropInfo = visualBuilder
+ .getSourceInnerDropInfo(sourceDragNode,
+ visualDropInfo, true);
+ canDrop = sourceDropInfo.canDrop();
+ if (canDrop) {
+ VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder
+ .getInnerDropInfo(
+ sourceDropInfo.getContainer(),
+ sourceDropInfo.getOffset());
+ if (newVisualDropInfo != null) {
+ visualBuilder.correctVisualDropPosition(
+ newVisualDropInfo, visualDropInfo);
+ caretParent = newVisualDropInfo.getDropContainer();
+ caretOffset = newVisualDropInfo.getDropOffset();
+ }
+ }
+ }
+ visualDropInfo.Release();
+ }
+ } else if (XulRunnerEditor.TRANS_FLAVOR_kFileMime.equals(flavor)
+ || XulRunnerEditor.TRANS_FLAVOR_kURLMime.equals(flavor)) {
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
+ .getInnerDropInfo(mouseEvent);
+ caretParent = visualDropInfo.getDropContainer();
+ caretOffset = visualDropInfo.getDropOffset();
+ canDrop = true;
+
+ }
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out
+ .println(" canDrop: " + canDrop + (canDrop ? " container: " + caretParent.getNodeName() + " offset: " + caretOffset : "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+ return new MozillaDropInfo(canDrop, caretParent, caretOffset);
+
+ }
+
+ public VpeSourceInnerDropInfo canExternalDropMacro(XModelObject object,
+ Node parentNode, int offset) {
+ String tagname = getTagName(object);
+ Node sourceDragNode = ((Document) getModel().getAdapter(Document.class))
+ .createElement(tagname);
+ return visualBuilder.getSourceInnerDropInfo(sourceDragNode, parentNode,
+ offset, false);
+ }
+
+ public void externalDropAny(final String flavor, final String data,
+ final Point range, Node container) {
+ if (flavor == null || flavor.length() == 0)
+ return;
+ IDropCommand dropCommand = DropCommandFactory.getInstance()
+ .getDropCommand(flavor, JSPTagProposalFactory.getInstance());
+
+ boolean promptAttributes = "yes"
+ .equals(VpePreference.ALWAYS_REQUEST_FOR_ATTRIBUTE.getValue());
+ dropCommand.getDefaultModel().setPromptForTagAttributesRequired(
+ promptAttributes);
+
+ // because it is external, convert path to URL
+ final String mimeData = DropUtils.convertPathToUrl(data);
+
+ dropCommand.execute(new DropData(flavor, mimeData, sourceEditor
+ .getEditorInput(), (ISourceViewer) sourceEditor
+ .getAdapter(ISourceViewer.class), new VpeSelectionProvider(
+ range.x, range.y), container));
+ }
+
+ private String getTagName(XModelObject object) {
+ String tagname = object.getAttributeValue("name"); //$NON-NLS-1$
+
+ XModelObject parent = object.getParent();
+ String uri = (parent == null) ? "" : parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
+ String defaultPrefix = (parent == null) ? "" : parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
+
+ String[] texts = new String[] { "<" + tagname + ">" }; //$NON-NLS-1$ //$NON-NLS-2$
+ PaletteInsertHelper.applyPrefix(texts, sourceEditor, tagname, uri,
+ defaultPrefix);
+ tagname = texts[0].substring(1, texts[0].length() - 1);
+
+ return tagname;
+ }
+
+ public void externalDrop(nsIDOMMouseEvent mouseEvent, String flavor, String data) {
+ onHideTooltip();
+
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder.getInnerDropInfo(mouseEvent);
+ Point range = selectionBuilder.getSourceSelectionRangeAtVisualNode(visualDropInfo.getDropContainer(), (int) visualDropInfo
+ .getDropOffset());
+ VpeSourceInnerDropInfo sourceDropInfo = null;
+
+ // if (MODEL_FLAVOR.equals(flavor)) {
+ // XModelObject object = PreferenceModelUtilities.getPreferenceModel()
+ // .getModelBuffer().source();
+ // if(object == null)
+
+ nsISupports aValue = DndUtil.getDnDValue(mouseEvent);
+ String aFlavor = ""; //$NON-NLS-1$
+ if (VpeDndUtil.isNsIFileInstance(aValue)) {
+ nsIFile aFile = (nsIFile) aValue.queryInterface(nsIFile.NS_IFILE_IID);
+
+ if (aValue != null) {
+ data = aFile.getPath();
+ aFlavor = DndUtil.kFileMime;
+ }
+
+ } else if (VpeDndUtil.isNsICStringInstance(aValue)) {
+ nsISupportsCString aString = (nsISupportsCString) aValue.queryInterface(nsISupportsCString.NS_ISUPPORTSCSTRING_IID);
+ data = aString.getData();
+ aFlavor = DndUtil.kHTMLMime;
+ } else if (VpeDndUtil.isNsIStringInstance(aValue)) {
+ nsISupportsString aString = (nsISupportsString) aValue.queryInterface(nsISupportsString.NS_ISUPPORTSSTRING_IID);
+ data = aString.getData();
+ aFlavor = DndUtil.kURLMime;
+ }
+
+ // if (object.getFileType() == XModelObject.FILE
+ // && !TLDUtil.isTaglib(object)) {
+ // flavor = "application/x-moz-file"; //$NON-NLS-1$
+ // IFile f = (IFile) EclipseResourceUtil.getResource(object);
+ // try {
+ // data = f.getLocation().toFile().toURL().toString();
+ // } catch (Exception e) {
+ // VpePlugin.getPluginLog().logError(e);
+ // }
+ // } else {
+ // String tagname = getTagName(object);
+ // if (tagname.indexOf("taglib") >= 0)tagname = "taglib"; //$NON-NLS-1$ //$NON-NLS-2$
+ // Node sourceDragNode = ((Document) getModel().getAdapter(
+ // Document.class)).createElement(tagname);
+ // if (visualDropInfo.getDropContainer() != null) {
+ // sourceDropInfo = visualBuilder.getSourceInnerDropInfo(
+ // sourceDragNode, visualDropInfo, true);
+ // range = selectionBuilder.getSourceSelectionRange(
+ // sourceDropInfo.getContainer(), sourceDropInfo
+ // .getOffset());
+ // }
+ // }
+
+ if (visualDropInfo.getDropContainer() != null && data != null) {
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out.println(" drop! container: " + visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
+ }
+ externalDropAny(aFlavor, data, range, sourceDropInfo == null ? null : sourceDropInfo.getContainer());
+
+ DropContext dropContext = new DropContext();
+ IDNDTextEditor textEditor = (IDNDTextEditor) VpeController.this.editPart.getSourceEditor();
+
+ // TypedEvent tEvent = new TypedEvent(mouseEvent);
+ // tEvent.data = data;
+ // dropContext.setFlavor(aFlavor);
+ // dropContext.setMimeData(data);
+ // DnDUtil.fireDnDEvent(dropContext, textEditor, tEvent);
+ }
+ }
+
+ public void onShowTooltip(int x, int y, final String text) {
+
+ if (tip != null && !tip.isDisposed())
+ tip.dispose();
+
+ Display display = visualEditor.getControl().getDisplay();
+ Shell parent = visualEditor.getControl().getShell();
+
+ tip = new Shell(parent, SWT.NO_FOCUS | SWT.ON_TOP);
+ Color bckgColor = new Color(tip.getDisplay(), 255, 250, 236);
+ tip.setBackground(bckgColor);
+
+ Composite composite = tip;
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.verticalSpacing = 0;
+ layout.horizontalSpacing = 0;
+ composite.setLayout(layout);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ composite.setLayoutData(gd);
+
+ final StyledText tipControlHeaderText = new StyledText(composite,
+ SWT.MULTI | SWT.READ_ONLY);
+
+ tipControlHeaderText.setForeground(bckgColor);
+ tipControlHeaderText.setBackground(bckgColor);
+
+ String formatText = text.trim();
+
+ /**
+ * attributeString string containing the pairs attribute and it's value
+ * as one string
+ */
+ String[] attributeString = formatText.split("\n"); //$NON-NLS-1$
+ /**
+ * buffer string containing the attribute and the value in the different
+ * succeding string
+ */
+ String[] buffer = attributeString[0].split(" "); //$NON-NLS-1$
+
+ tipControlHeaderText.setText(buffer[0].toString());
+
+ tipControlHeaderText.addLineStyleListener(new LineStyleListener() {
+ public void lineGetStyle(LineStyleEvent event) {
+ Color color = new Color(tipControlHeaderText.getDisplay(), 201,
+ 51, 40);
+ if (event.lineOffset == 0) {
+ StyleRange st = new StyleRange();
+ st.fontStyle = SWT.BOLD;
+ st.foreground = color;
+ event.styles = new StyleRange[] { st };
+ st.start = event.lineOffset;
+ st.length = event.lineText.length();
+ }
+ }
+ });
+
+ GridData gridData = new GridData(GridData.BEGINNING
+ | GridData.FILL_BOTH);
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.horizontalSpan = 2;
+ tipControlHeaderText.setLayoutData(gridData);
+
+ StringBuffer tempAttr = new StringBuffer();
+ StringBuffer tempValue = new StringBuffer();
+
+ if (attributeString.length >= 2) {
+ for (int i = 1; i < attributeString.length; i++) {
+ buffer = attributeString[i].split(" ", 2); //$NON-NLS-1$
+ if (i == 1) {
+ tempAttr.append(buffer[0] + " "); //$NON-NLS-1$
+ tempValue
+ .append((buffer.length >= 2 ? buffer[1] : "") + " "); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ tempAttr.append("\n" + buffer[0] + " "); //$NON-NLS-1$ //$NON-NLS-2$
+ tempValue
+ .append(" \n" + (buffer.length >= 2 ? buffer[1] : "") + " "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+
+ final StyledText tipControlAttributeText = new StyledText(
+ composite, SWT.MULTI | SWT.READ_ONLY);
+
+ tipControlAttributeText.setForeground(bckgColor);
+ tipControlAttributeText.setBackground(bckgColor);
+
+ tipControlAttributeText.setText(tempAttr.toString());
+ tipControlAttributeText
+ .addLineStyleListener(new LineStyleListener() {
+ public void lineGetStyle(LineStyleEvent event) {
+ Color color = new Color(tipControlHeaderText
+ .getDisplay(), 42, 148, 0);
+ StyleRange st = new StyleRange();
+ st.start = event.lineOffset;
+ st.length = event.lineText.length();
+ st.foreground = color;
+ st.fontStyle = SWT.NORMAL;
+ event.styles = new StyleRange[] { st };
+ }
+ });
+ GridData gridData1 = new GridData(GridData.BEGINNING
+ | GridData.FILL_BOTH);
+ gridData1.horizontalAlignment = GridData.FILL;
+ tipControlAttributeText.setLayoutData(gridData1);
+
+ final StyledText tipControlValueText = new StyledText(composite,
+ SWT.MULTI | SWT.READ_ONLY);
+
+ tipControlValueText.setBackground(bckgColor);
+
+ tipControlValueText.setText(tempValue.toString());
+
+ GridData gridData2 = new GridData(GridData.BEGINNING
+ | GridData.FILL_BOTH);
+ gridData2.horizontalAlignment = GridData.FILL;
+ tipControlValueText.setLayoutData(gridData2);
+ }
+ /*
+ * Bug in Mozilla embedded API. Tooltip coordinates are wrong for
+ * elements inside an inline frame (IFrame tag). The workaround is to
+ * position the tooltip based on the mouse cursor location.
+ */
+ Point point = display.getCursorLocation();
+ /*
+ * Assuming cursor is 21x21 because this is the size of the arrow cursor
+ * on Windows
+ */
+ point.y += 21;
+ tip.setLocation(point);
+ tip.pack();
+ tip.setVisible(true);
+ }
+
+ public void onHideTooltip() {
+ if (tip != null && !tip.isDisposed())
+ tip.dispose();
+ tip = null;
+ }
+
+ public VpePageContext getPageContext() {
+
+ return pageContext;
+ }
+
+ public StructuredTextEditor getSourceEditor() {
+ return sourceEditor;
+ }
+
+ public FormatControllerManager getToolbarFormatControllerManager() {
+ return toolbarFormatControllerManager;
+ }
+
+ public void setToolbarFormatControllerManager(
+ FormatControllerManager formatControllerManager) {
+ toolbarFormatControllerManager = formatControllerManager;
+ }
+
+ public void setSelectionBarController(SelectionBar selectionBar) {
+ this.selectionBar = selectionBar;
+ }
+
+ public IStructuredModel getModel() {
+ return sourceEditor.getModel();
+ }
+
+ public VpeDomMapping getDomMapping() {
+ return domMapping;
+ }
+
+ public VpeIncludeList getIncludeList() {
+
+ if (includeList == null)
+ VpePlugin.getPluginLog().logError("includeList - NULL!!!");
+
+ return includeList;
+ }
+
+ /**
+ * Processed selection events from source editor,
+ * if reason of selection is visial editor,
+ * selection will be stopped processing by
+ * this condition (!switcher.startActiveEditor)
+ */
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (selectionBar != null)
+ selectionBar.selectionChanged();
+ // FIX for JBIDE-2114
+ if (!isVisualEditorVisible()) {
+ // selection event doesn't changes a content
+ // synced = false;
+ return;
+ }
+
+ if (editPart.getVisualMode() != VpeEditorPart.SOURCE_MODE) {
+ if (toolbarFormatControllerManager != null)
+ toolbarFormatControllerManager.selectionChanged();
+ }
+
+ if (!switcher
+ .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ try {
+
+ if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
+ System.out
+ .println(">>>>>>>>>>>>>> selectionChanged " + event.getSource()); //$NON-NLS-1$
+ }
+ sourceSelectionChanged();
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ // nsIClipboardDragDropHooks implementation
+ public void onPasteOrDrop(nsIDOMMouseEvent mouseEvent, String flavor,
+ String data) {
+ onHideTooltip();
+
+ VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
+ .getInnerDropInfo(mouseEvent);
+ Point range = selectionBuilder.getSourceSelectionRangeAtVisualNode(
+ visualDropInfo.getDropContainer(), (int) visualDropInfo
+ .getDropOffset());
+ VpeSourceInnerDropInfo sourceDropInfo = null;
+
+ XModelObject object = PreferenceModelUtilities.getPreferenceModel()
+ .getModelBuffer().source();
+
+ String tagname = getTagName(object);
+ if (tagname.indexOf("taglib") >= 0)tagname = "taglib"; //$NON-NLS-1$ //$NON-NLS-2$
+ Node sourceDragNode = ((Document) getModel().getAdapter(Document.class))
+ .createElement(tagname);
+ if (visualDropInfo.getDropContainer() != null) {
+ sourceDropInfo = visualBuilder.getSourceInnerDropInfo(
+ sourceDragNode, visualDropInfo, true);
+ range = selectionBuilder.getSourceSelectionRange(sourceDropInfo
+ .getContainer(), sourceDropInfo.getOffset());
+ }
+
+ if (visualDropInfo.getDropContainer() != null) {
+ if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+ System.out
+ .println(" drop! container: " + visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
+ }
+ final String finalFlavor = flavor;
+ final String finalData = data;
+ final Point finalRange = range;
+ final Node finalDropContainer = sourceDropInfo == null ? null
+ : sourceDropInfo.getContainer();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ externalDropAny(finalFlavor, finalData, finalRange,
+ finalDropContainer);
+ }
+ });
+ }
+ }
+
+ public void drop(Node node, Node parentNode, int offset) {
+ visualBuilder.innerDrop(node, parentNode, offset);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.mozilla.interfaces.nsISupports#queryInterface(java.lang.String)
+ */
+ public nsISupports queryInterface(String arg0) {
+ return Mozilla.getInstance().queryInterface(this, arg0);
+ }
+
+ /**
+ * Calls when editor content should be refreshed
+ */
+ public void onRefresh() {
+ // when we using separate thread to display selection rectangle
+ // it's working better than without
+ /*
+ * HACK We need wait some time while standart event will be handled and
+ * in process event handles some components are repainted(like buttons)
+ * and flasher are not repainted, so we should paint flasher
+ */
+
+ Display.getDefault().asyncExec(new Thread() {
+ public void run() {
+ if (getXulRunnerEditor() != null)
+ getXulRunnerEditor().showSelectionRectangle();
+ }
+ });
+
+ }
+
+ /**
+ * @return the xulRunnerEditor
+ */
+ public XulRunnerEditor getXulRunnerEditor() {
+ return xulRunnerEditor;
+ }
+
+ /**
+ * @param xulRunnerEditor
+ * the xulRunnerEditor to set
+ */
+ public void setXulRunnerEditor(XulRunnerEditor xulRunnerEditor) {
+ this.xulRunnerEditor = xulRunnerEditor;
+ }
+
+ /**
+ * Start drag session
+ */
+ public void startDragSession(nsIDOMEvent domEvent) {
+
+ visualBuilder.getDnd().startDragSession(domEvent);
+ }
+
+ public void dragDrop(nsIDOMEvent domEvent) {
+
+ visualBuilder.getDnd().dragDrop(domEvent, this);
+ }
+
+ /**
+ * @return the selectionBuilder
+ */
+ public VpeSelectionBuilder getSelectionBuilder() {
+ return selectionBuilder;
+ }
+
+ /**
+ * @param selectionBuilder
+ * the selectionBuilder to set
+ */
+ public void setSelectionBuilder(VpeSelectionBuilder selectionBuilder) {
+ this.selectionBuilder = selectionBuilder;
+ }
+
+ public boolean isVisualEditorVisible() {
+ return visualEditorVisible;
+ }
+
+ public void setVisualEditorVisible(boolean visualEditorVisible) {
+ this.visualEditorVisible = visualEditorVisible;
+ }
+
+ public boolean isSynced() {
+ return synced;
+ }
+
+ public void setSynced(boolean synced) {
+ this.synced = synced;
+ }
+
+ /**
+ * @return the changeEvents
+ */
+ public LinkedList<VpeEventBean> getChangeEvents() {
+
+ if (changeEvents == null) {
+
+ changeEvents = new LinkedList<VpeEventBean>();
+ }
+ return changeEvents;
+ }
+ public void reinit(){
+ if(reinitJob!=null) {
+ reinitJob.cancel();
+ }
+ reinitJob = new UIJob(VpeUIMessages.VPE_VISUAL_REFRESH_JOB) {
+
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ if(monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ reinitImpl();
+ return Status.OK_STATUS;
+ }
+ };
+ reinitJob.schedule();
+ }
+
+ private void reinitImpl() {
+ try {
+ if(switcher==null||!switcher
+ .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ return;
+ }
+ visualBuilder.setSelectionRectangle(null);
+ visualEditor.setEditorDomEventListener(this);
+ IDOMModel sourceModel = (IDOMModel) getModel();
+ if (sourceModel != null) {
+ IDOMDocument sourceDocument = sourceModel.getDocument();
+ visualBuilder.rebuildDom(sourceDocument);
+ } else {
+ visualBuilder.rebuildDom(null);
+ }
+ //reinits selection controller+ controller
+ visualEditor.reinitDesignMode();
+ visualSelectionController = new VpeSelectionController(visualEditor.getEditor().getSelectionController());
+
+ selectionBuilder = new VpeSelectionBuilder(domMapping, sourceBuilder,
+ visualBuilder, visualSelectionController);
+
+ selectionManager = new SelectionManager(pageContext,
+ sourceEditor, visualSelectionController);
+
+ keyEventHandler = new KeyEventManager(sourceEditor, domMapping,
+ pageContext);
+ //restore selection in visula part
+ sourceSelectionChanged();
+ }catch(VpeDisposeException ex) {
+ //vpe vas closed when refresh job is running, so just
+ //ignore this exception
+ }
+ finally {
+ if(switcher!=null) {
+ switcher.stopActiveEditor();
+ }
+ }
+
+ }
+
+ /**
+ * @return the visualSelectionController
+ */
+ public VpeSelectionController getVisualSelectionController() {
+ return visualSelectionController;
+ }
+
+ /**
+ *
+ * @return sourceBuilder
+ */
+ public VpeSourceDomBuilder getSourceBuilder() {
+ return sourceBuilder;
+ }
+
+ /**
+ *
+ * @return visualBuilder
+ */
+ public VpeVisualDomBuilder getVisualBuilder() {
+ return visualBuilder;
+ }
+
+ /**
+ * @return the vpeUpdateDelayTime
+ */
+ private int getVpeUpdateDelayTime() {
+ return vpeUpdateDelayTime;
+ }
+
+ /**
+ * @param vpeUpdateDelayTime the vpeUpdateDelayTime to set
+ */
+ private void setVpeUpdateDelayTime(int vpeUpdateDelayTime) {
+ this.vpeUpdateDelayTime = vpeUpdateDelayTime;
+ }
+
+ /**
+ * @return the selectionManager
+ */
+ public ISelectionManager getSelectionManager() {
+ return selectionManager;
+ }
+
+}
15 years, 3 months
JBoss Tools SVN: r14270 - in branches/jbosstools-3.0.x: common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: yradtsevich
Date: 2009-03-19 14:54:39 -0400 (Thu, 19 Mar 2009)
New Revision: 14270
Modified:
branches/jbosstools-3.0.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropData.java
branches/jbosstools-3.0.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropUtils.java
branches/jbosstools-3.0.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java
branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
Log:
RESOLVED - issue JBIDE-3985: java.lang.NullPointerException when DND external image file into Visual Pane
https://jira.jboss.org/jira/browse/JBIDE-3985
Modified: branches/jbosstools-3.0.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropData.java
===================================================================
--- branches/jbosstools-3.0.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropData.java 2009-03-19 17:27:15 UTC (rev 14269)
+++ branches/jbosstools-3.0.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropData.java 2009-03-19 18:54:39 UTC (rev 14270)
@@ -27,7 +27,7 @@
private ISourceViewer fViewer;
private ISelectionProvider fProvider;
private String fMimeType;
- private String fData;
+ private String fMimeData;
private IDropCommand fDropCommand = null;
private Node container = null;
private String attributeName = null;
@@ -56,7 +56,7 @@
/**
*
* @param mimeType
- * @param data
+ * @param mimeData
* @param pageContext
* @param input
* @param viewer
@@ -64,13 +64,13 @@
*/
public DropData(
String mimeType,
- String data,
+ String mimeData,
IEditorInput input,
ISourceViewer viewer,
ISelectionProvider provider
) {
fMimeType = mimeType;
- fData = data;
+ fMimeData = mimeData;
fInput = input;
fViewer = viewer;
fProvider = provider;
@@ -89,14 +89,14 @@
*
*/
public String getMimeData() {
- return fData;
+ return fMimeData;
}
/**
*
*/
- public void setMimeData(String data) {
- fData = data;
+ public void setMimeData(String mimeData) {
+ fMimeData = mimeData;
}
/**
Modified: branches/jbosstools-3.0.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropUtils.java
===================================================================
--- branches/jbosstools-3.0.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropUtils.java 2009-03-19 17:27:15 UTC (rev 14269)
+++ branches/jbosstools-3.0.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropUtils.java 2009-03-19 18:54:39 UTC (rev 14270)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.common.model.ui.editors.dnd;
+import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -204,4 +205,17 @@
}
return container;
}
+
+ /**
+ * If it is possible, then converts given {@code path} into URL,
+ * otherwise returns {@code path} unchanged
+ * @return
+ */
+ public static String convertPathToUrl(String path) {
+ try {
+ return new File(path).toURL().toString();
+ } catch (MalformedURLException e) {
+ return path;
+ }
+ }
}
\ No newline at end of file
Modified: branches/jbosstools-3.0.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java
===================================================================
--- branches/jbosstools-3.0.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java 2009-03-19 17:27:15 UTC (rev 14269)
+++ branches/jbosstools-3.0.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java 2009-03-19 18:54:39 UTC (rev 14270)
@@ -34,6 +34,7 @@
import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
import org.jboss.tools.common.model.ui.dnd.VpeDnDEvent;
import org.jboss.tools.common.model.ui.dnd.VpeTextDropAction;
+import org.jboss.tools.common.model.ui.editors.dnd.DropUtils;
import org.jboss.tools.common.model.ui.editors.dnd.FileTagProposalLoader;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.jst.web.tld.TLDUtil;
@@ -119,12 +120,10 @@
private String getURL(TypedEvent event) {
String[] s = (String[])event.data;
- if(s == null || s.length == 0) return null;
- File f = new File(s[0]);
- try {
- return f.toURL().toString();
- } catch (MalformedURLException e) {
- return s[0];
+ if(s == null || s.length == 0) {
+ return null;
+ } else {
+ return DropUtils.convertPathToUrl(s[0]);
}
}
private File getFile(TypedEvent event) {
Modified: branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
--- branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2009-03-19 17:27:15 UTC (rev 14269)
+++ branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2009-03-19 18:54:39 UTC (rev 14270)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.vpe.editor;
+import java.io.File;
+import java.net.MalformedURLException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -83,6 +85,7 @@
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.DropUtils;
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;
@@ -2193,7 +2196,10 @@
dropCommand.getDefaultModel().setPromptForTagAttributesRequired(
promptAttributes);
- dropCommand.execute(new DropData(flavor, data, sourceEditor
+ // because it is external, convert path to URL
+ final String mimeData = DropUtils.convertPathToUrl(data);
+
+ dropCommand.execute(new DropData(flavor, mimeData, sourceEditor
.getEditorInput(), (ISourceViewer) sourceEditor
.getAdapter(ISourceViewer.class), new VpeSelectionProvider(
range.x, range.y), container));
15 years, 3 months
JBoss Tools SVN: r14269 - branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp.
by jbosstools-commits@lists.jboss.org
Author: sdzmitrovich
Date: 2009-03-19 13:27:15 -0400 (Thu, 19 Mar 2009)
New Revision: 14269
Modified:
branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
Log:
https://jira.jboss.org/jira/browse/JBIDE-4008
Modified: branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
===================================================================
--- branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2009-03-19 16:30:07 UTC (rev 14268)
+++ branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2009-03-19 17:27:15 UTC (rev 14269)
@@ -148,7 +148,8 @@
</extension>
<extension point="org.eclipse.ui.editorActions">
- <editorContribution id="formatJSPActionContribution" targetID="org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor">
+ <!-- necessary menu items -->
+ <!--<editorContribution id="formatJSPActionContribution" targetID="org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor">
<action actionID="formatJSPAction" class="org.jboss.tools.jst.jsp.ui.action.FormatJSPActionDelegate" id="formatJSPAction" label="Format" menubarPath="edit/additions">
</action>
</editorContribution>
@@ -314,7 +315,7 @@
id="StructureSelectHistory"
label="Restore Last Selection">
</action>
- </editorContribution>
+ </editorContribution>-->
<editorContribution
id="org.jboss.tools.jst.jsp.cssClassDialogEditorContribution"
targetID="org.eclipse.wst.css.core.csssource.source">
@@ -342,8 +343,100 @@
tooltip="Open CSS Dialog based on the active CSS file">
</action>
</editorContribution>
+
</extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution locationURI="menu:sourceMenuId?after=sourceBegin">
+
+ <action
+ actionID="org.eclipse.wst.sse.ui.toggle.comment"
+ class="org.eclipse.wst.xml.ui.internal.actions.ToggleCommentActionXMLDelegate"
+ definitionId="org.eclipse.wst.sse.ui.toggle.comment"
+ id="ToggleComment"
+ menubarPath="sourceMenuId/sourceBegin"
+ label="Toggle Comment">
+ </action>
+ <command commandId="org.eclipse.wst.sse.ui.toggle.comment"
+ id="ToggleComment"
+ mnemonic="%command.toggle.comment.mnemonic"
+ style="push">
+ <visibleWhen checkEnabled="false">
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </visibleWhen>
+ </command>
+ <command commandId="org.eclipse.wst.sse.ui.add.block.comment"
+ id="AddBlockComment"
+ mnemonic="%command.add.block.comment.mnemonic"
+ style="push">
+ <visibleWhen checkEnabled="false">
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </visibleWhen>
+ </command>
+ <command commandId="org.eclipse.wst.sse.ui.remove.block.comment"
+ id="RemoveBlockComment"
+ mnemonic="%command.remove.block.comment.mnemonic"
+ style="push">
+ <visibleWhen checkEnabled="false">
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.wst.xml.ui.internal.handlers.ToggleCommentHandler"
+ commandId="org.eclipse.wst.sse.ui.toggle.comment">
+ <activeWhen>
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </activeWhen>
+ <enabledWhen>
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </enabledWhen>
+ </handler>
+ <handler
+ class="org.eclipse.wst.xml.ui.internal.handlers.AddBlockCommentHandler"
+ commandId="org.eclipse.wst.sse.ui.add.block.comment">
+ <activeWhen>
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </activeWhen>
+ <enabledWhen>
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </enabledWhen>
+ </handler>
+ <handler
+ class="org.eclipse.wst.xml.ui.internal.handlers.RemoveBlockCommentHandler"
+ commandId="org.eclipse.wst.sse.ui.remove.block.comment">
+ <activeWhen>
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </activeWhen>
+ <enabledWhen>
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </enabledWhen>
+ </handler>
+ </extension>
+ <extension point="org.eclipse.core.expressions.definitions">
+ <definition id="org.jboss.tools.ui.comments">
+ <and>
+ <with variable="activeContexts">
+ <iterate operator="or">
+ <equals value="org.eclipse.wst.sse.ui.structuredTextEditorScope"/>
+ </iterate>
+ </with>
+ <or>
+ <with variable="activeEditorId">
+ <equals value="org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor"/>
+ </with>
+ <with variable="activeEditorId">
+ <equals value="org.jboss.tools.jst.jsp.jspeditor.HTMLTextEditor"/>
+ </with>
+ </or>
+ </and>
+ </definition>
+ </extension>
<!--extension point="org.jboss.tools.common.verification.rules">
<rule-set path="meta/.rule-sets.xml"/>
</extension-->
15 years, 3 months
JBoss Tools SVN: r14268 - in trunk/seam: plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/project/facet and 3 other directories.
by jbosstools-commits@lists.jboss.org
Author: akazakov
Date: 2009-03-19 12:30:07 -0400 (Thu, 19 Mar 2009)
New Revision: 14268
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamUtil.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/project/facet/SeamVersion.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/SeamRuntimeManagerTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3933 Seam version should be set 2.1 not 2.0 when Seam 2.1.x runtime selected. - Fixed.
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamUtil.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamUtil.java 2009-03-19 15:58:41 UTC (rev 14267)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamUtil.java 2009-03-19 16:30:07 UTC (rev 14268)
@@ -12,6 +12,7 @@
import java.io.File;
import java.io.IOException;
+import java.util.StringTokenizer;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
@@ -68,11 +69,50 @@
* @return
*/
public static String getSeamVersionFromManifest(SeamRuntime runtime) {
- File jarFile = new File(runtime.getLibDir(), seamJarName);
+ return getSeamVersionFromManifest(runtime.getHomeDir());
+ }
+
+ /**
+ * Returns trimmed Seam version from <SeamHome>/lib/jboss-seam.jar/META-INF/MANIFEST.MF
+ * @param depth - number of segments of Seam version string.
+ * @param seamHome
+ * @return
+ */
+ public static String getSeamVersionFromManifest(String seamHome, int depth) {
+ return trimSeamVersion(getSeamVersionFromManifest(seamHome), depth);
+ }
+
+ /**
+ * Returns true if two versions are matched.
+ * For example "2.1.1.GA" matches "2.1"
+ * @param version1
+ * @param version2
+ * @return
+ */
+ public static boolean areSeamVersionsMatched(String version1, String version2) {
+ String longerVersion = version1.length()>version2.length()?version1:version2;
+ String shorterVersion = longerVersion==version1?version2:version1;
+ StringTokenizer sSt = new StringTokenizer(shorterVersion, ".", false);
+ StringTokenizer lSt = new StringTokenizer(longerVersion, ".", false);
+ while (sSt.hasMoreElements() && lSt.hasMoreElements()) {
+ if(!sSt.nextToken().equals(lSt.nextToken())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns Seam version from <SeamHome>/lib/jboss-seam.jar/META-INF/MANIFEST.MF
+ * @param seamHome
+ * @return
+ */
+ public static String getSeamVersionFromManifest(String seamHome) {
+ File jarFile = new File(seamHome, "lib/" + seamJarName);
if(!jarFile.isFile()) {
- jarFile = new File(runtime.getHomeDir(), seamJarName);
+ jarFile = new File(seamHome, seamJarName);
if(!jarFile.isFile()) {
- SeamCorePlugin.getPluginLog().logWarning(jarFile.getAbsolutePath() + " as well as " + new File(runtime.getLibDir(), seamJarName).getAbsolutePath() + " don't exist for Seam Runtime " + runtime.getName());
+ SeamCorePlugin.getPluginLog().logWarning(jarFile.getAbsolutePath() + " as well as " + new File(seamHome, "lib/" + seamJarName).getAbsolutePath() + " don't exist.");
return null;
}
}
@@ -89,8 +129,31 @@
return null;
}
}
-
+
/**
+ * Trims Seam version string.
+ * For example "2.1.0.SP1" will be trimmed to 2.1 (depth=2); "2.1.1.GA" -> "2.1.1" (depth=3); "2.0.0.SP1" -> "2.0.0.SP1" (depth<1)
+ * @param fullSeamVersion
+ * @param depth - number of segments of Seam version string.
+ * @return
+ */
+ public static String trimSeamVersion(String fullSeamVersion, int depth) {
+ if(fullSeamVersion==null || depth<1) {
+ return fullSeamVersion;
+ }
+ StringBuffer version = new StringBuffer();
+ StringTokenizer st = new StringTokenizer(fullSeamVersion, ".", false);
+ while (st.hasMoreElements() && depth>0) {
+ version.append(st.nextToken());
+ depth--;
+ if(st.hasMoreElements() && depth>0) {
+ version.append('.');
+ }
+ }
+ return version.toString();
+ }
+
+ /**
* Converts seam project name to string which suitable for package names
* @param projectNamePackage
* @return
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/project/facet/SeamVersion.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/project/facet/SeamVersion.java 2009-03-19 15:58:41 UTC (rev 14267)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/project/facet/SeamVersion.java 2009-03-19 16:30:07 UTC (rev 14268)
@@ -11,6 +11,7 @@
package org.jboss.tools.seam.core.project.facet;
import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.seam.core.SeamUtil;
/**
* Seam Versions enumeration
@@ -92,4 +93,25 @@
}
return null;
}
-}
+
+ /**
+ * Find matching version
+ * @param vs
+ * @return
+ */
+ public static SeamVersion findMatchingVersion(String vs) {
+ if(vs == null) {
+ return null;
+ }
+ if(SeamUtil.areSeamVersionsMatched(SeamVersion.SEAM_1_2.toString(), vs)) {
+ return SeamVersion.SEAM_1_2;
+ }
+ if(SeamUtil.areSeamVersionsMatched(SeamVersion.SEAM_2_0.toString(), vs)) {
+ return SeamVersion.SEAM_2_0;
+ }
+ if(SeamUtil.areSeamVersionsMatched(SeamVersion.SEAM_2_1.toString(), vs)) {
+ return SeamVersion.SEAM_2_1;
+ }
+ return null;
+ }
+}
\ No newline at end of file
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java 2009-03-19 15:58:41 UTC (rev 14267)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java 2009-03-19 16:30:07 UTC (rev 14268)
@@ -67,7 +67,6 @@
import org.jboss.tools.seam.ui.internal.project.facet.ValidatorFactory;
import org.jboss.tools.seam.ui.widget.editor.IFieldEditor;
import org.jboss.tools.seam.ui.widget.editor.IFieldEditorFactory;
-import org.jboss.tools.seam.ui.widget.editor.SeamRuntimeListFieldEditor;
import org.jboss.tools.seam.ui.wizard.IParameter;
import org.jboss.tools.seam.ui.wizard.SeamWizardFactory;
import org.jboss.tools.seam.ui.wizard.SeamWizardUtils;
@@ -959,8 +958,8 @@
String jarLocation = getJBossSeamJarLocation();
if(jarLocation != null) {
String folder = new File(jarLocation).getParent();
- String vs = SeamRuntimeListFieldEditor.SeamRuntimeWizardPage.getSeamVersion(folder);
- SeamVersion v = findMatchingVersion(vs);
+ String vs = SeamUtil.getSeamVersionFromManifest(folder);
+ SeamVersion v = SeamVersion.findMatchingVersion(vs);
if(v != null) {
return new SeamVersion[]{v};
}
@@ -969,20 +968,6 @@
return SeamVersion.ALL_VERSIONS;
}
- private SeamVersion findMatchingVersion(String vs) {
- if(vs == null) return null;
- if(vs.matches(SeamVersion.SEAM_1_2.toString().replace(".", "\\.") + ".*")) {
- return SeamVersion.SEAM_1_2;
- }
- if(vs.matches(SeamVersion.SEAM_2_0.toString().replace(".", "\\.") + ".*")) {
- return SeamVersion.SEAM_2_0;
- }
- if(vs.matches(SeamVersion.SEAM_2_1.toString().replace(".", "\\.") + ".*")) {
- return SeamVersion.SEAM_2_1;
- }
- return null;
- }
-
private String getJBossSeamJarLocation() {
IJavaProject jp = EclipseResourceUtil.getJavaProject(project);
if(jp == null) return null;
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java 2009-03-19 15:58:41 UTC (rev 14267)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java 2009-03-19 16:30:07 UTC (rev 14268)
@@ -67,6 +67,7 @@
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.core.SeamUtil;
import org.jboss.tools.seam.core.project.facet.SeamRuntime;
import org.jboss.tools.seam.core.project.facet.SeamVersion;
import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
@@ -558,16 +559,15 @@
}
name.setValue(homeDirName);
- String seamVersion = getSeamVersion(homeDir
- .getValueAsString());
+ String seamVersion = SeamUtil.getSeamVersionFromManifest(homeDir.getValueAsString());
if (seamVersion == null) {
setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_CANNOT_FIND_JBOSS_SEAM_JAR);
setPageComplete(false);
return;
}
- if (seamVersion != null && validSeamVersions != null) {
+ if (validSeamVersions != null) {
for (SeamVersion ver : validSeamVersions) {
- if (seamVersion.matches(ver.toString().substring(0,1)+ ".*")) { //$NON-NLS-1$
+ if(SeamUtil.areSeamVersionsMatched(ver.toString(), seamVersion)) {
version.setValue(ver.toString());
break;
}
@@ -575,7 +575,7 @@
}
}
}
-
+
if (name.getValueAsString() == null || "".equals(//$NON-NLS-1$
name.getValueAsString().toString().trim())) {
setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_NAME_CANNOT_BE_EMPTY);
@@ -620,7 +620,7 @@
return;
}
- String seamVersion = getSeamVersion(homeDir.getValueAsString());
+ String seamVersion = SeamUtil.getSeamVersionFromManifest(homeDir.getValueAsString());
if (seamVersion == null) {
setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_CANNOT_FIND_JBOSS_SEAM_JAR);
setPageComplete(false);
@@ -630,19 +630,11 @@
IMessageProvider.WARNING);
setPageComplete(true);
return;
- } else if (!seamVersion.matches(version.getValueAsString().replace(
- ".", "\\.") + ".*")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- if(seamVersion.matches(version.getValueAsString().substring(0,1)+".*")) { //$NON-NLS-1$
- if(!seamVersion.matches(version.getValueAsString().substring(0,1)+"\\.1\\..*")) { //$NON-NLS-1$
- setMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_THE_SELECTED_SEAM_APPEARS_TO_BE_OF_INCOMATIBLE_VERSION
- + seamVersion + "'", IMessageProvider.WARNING); //$NON-NLS-1$
- }
- } else {
- setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_THE_SELECTED_SEAM_APPEARS_TO_BE_OF_INCOMATIBLE_VERSION
- + seamVersion + "'"); //$NON-NLS-1$
- setPageComplete(false);
- return;
- }
+ } else if(!SeamUtil.areSeamVersionsMatched(version.getValueAsString(), seamVersion)) {
+ setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_THE_SELECTED_SEAM_APPEARS_TO_BE_OF_INCOMATIBLE_VERSION
+ + seamVersion + "'"); //$NON-NLS-1$
+ setPageComplete(false);
+ return;
} else {
setMessage(null);
}
@@ -662,59 +654,6 @@
}
/**
- * Return Seam runtime version obtained form jboss-seam.jar manifest
- * 'Seam Version' property
- *
- * @param path
- * path to Seam home folder
- * @return String value of 'Seam Version' manifest property
- */
- public static String getSeamVersion(String path) {
- File seamJarFile = new File(path, "jboss-seam.jar"); //$NON-NLS-1$
- if (!seamJarFile.exists()) {
- seamJarFile = new File(path, "lib/jboss-seam.jar"); // hack to //$NON-NLS-1$
- // make it
- // work for
- // seam2
- if (!seamJarFile.exists()) {
- return null;
- }
- }
- InputStream str = null;
- ZipFile seamJar;
- try {
- seamJar = new ZipFile(seamJarFile);
-
- ZipFileStructureProvider provider = new ZipFileStructureProvider(
- seamJar);
- ZipEntry entry = seamJar.getEntry("META-INF/MANIFEST.MF"); //$NON-NLS-1$
- str = provider.getContents(entry);
-
- Properties manifest = new Properties();
- manifest.load(str);
- Object sv = manifest
- .get(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_SEAM_VERSION);
- return sv == null ? "" : sv.toString(); //$NON-NLS-1$
-
- } catch (IOException e) {
- SeamCorePlugin
- .getPluginLog()
- .logError(
- SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_CANNOT_READ_JAR_FILE,
- e);
- } finally {
- if (str != null) {
- try {
- str.close();
- } catch (IOException e) {
- SeamGuiPlugin.getPluginLog().logError(e);
- }
- }
- }
- return ""; //$NON-NLS-1$
- }
-
- /**
* Return Seam Runtime instance initialized by user input
*
* @return SeamRuntime instance
Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/SeamRuntimeManagerTest.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/SeamRuntimeManagerTest.java 2009-03-19 15:58:41 UTC (rev 14267)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/SeamRuntimeManagerTest.java 2009-03-19 16:30:07 UTC (rev 14268)
@@ -16,6 +16,7 @@
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
+import org.jboss.tools.seam.core.SeamUtil;
import org.jboss.tools.seam.core.project.facet.SeamRuntime;
import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
import org.jboss.tools.seam.core.project.facet.SeamVersion;
@@ -83,6 +84,17 @@
assertNotNull("Cannot find runtime 'Seam 1.2.0'",srt);
}
+ public void testMatchedRuntimes() {
+ assertTrue(SeamUtil.areSeamVersionsMatched("2.1", "2.1.1.GA"));
+ assertFalse(SeamUtil.areSeamVersionsMatched("1.2", "2.1.1.GA"));
+ assertFalse(SeamUtil.areSeamVersionsMatched("2.0", "2.1.1.GA"));
+ assertTrue(SeamUtil.areSeamVersionsMatched("2.0", "2.0.1.SP1"));
+ assertTrue(SeamUtil.areSeamVersionsMatched("1.2", "1.2.1.GA"));
+ assertTrue(SeamUtil.areSeamVersionsMatched("1.2", "1.2.0"));
+ assertTrue(SeamUtil.areSeamVersionsMatched("2", "2.0.0"));
+ assertFalse(SeamUtil.areSeamVersionsMatched("2.1", "2.0.0"));
+ }
+
/**
* Test method for {@link org.jboss.tools.seam.core.project.facet.SeamRuntimeManager#removeRuntime(org.jboss.tools.seam.core.project.facet.SeamRuntime)}.
*/
15 years, 3 months
JBoss Tools SVN: r14266 - in workspace/jgraham/bpel: trunk and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: john.graham(a)jboss.org
Date: 2009-03-19 11:54:09 -0400 (Thu, 19 Mar 2009)
New Revision: 14266
Added:
workspace/jgraham/bpel/trunk/
workspace/jgraham/bpel/trunk/org.eclipse.bpel.apache.ode.deploy.model/
workspace/jgraham/bpel/trunk/org.eclipse.bpel.apache.ode.deploy.ui/
workspace/jgraham/bpel/trunk/org.eclipse.bpel.apache.ode.runtime/
workspace/jgraham/bpel/trunk/org.eclipse.bpel.common.model/
workspace/jgraham/bpel/trunk/org.eclipse.bpel.common.ui/
workspace/jgraham/bpel/trunk/org.eclipse.bpel.model/
workspace/jgraham/bpel/trunk/org.eclipse.bpel.runtimes/
workspace/jgraham/bpel/trunk/org.eclipse.bpel.ui/
workspace/jgraham/bpel/trunk/org.eclipse.bpel.validator/
workspace/jgraham/bpel/trunk/org.eclipse.bpel.wsil.model/
workspace/jgraham/bpel/trunk/org.eclipse.bpel.xpath10/
Log:
Initial commit
15 years, 3 months
JBoss Tools SVN: r14265 - workspace/jgraham.
by jbosstools-commits@lists.jboss.org
Author: john.graham(a)jboss.org
Date: 2009-03-19 11:47:08 -0400 (Thu, 19 Mar 2009)
New Revision: 14265
Added:
workspace/jgraham/bpel/
Log:
15 years, 3 months
JBoss Tools SVN: r14264 - in branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe: editor/template and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: yradtsevich
Date: 2009-03-19 10:55:25 -0400 (Thu, 19 Mar 2009)
New Revision: 14264
Added:
branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/Message.java
Modified:
branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java
branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
Log:
RESOLVED - issue JBIDE-2521: Allow to select html tag wich should be used to render unknown tag in VPE Template dialog
https://jira.jboss.org/jira/browse/JBIDE-2521
- Validation of VPE Template dialog has been added.
Added: branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/Message.java
===================================================================
--- branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/Message.java (rev 0)
+++ branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/Message.java 2009-03-19 14:55:25 UTC (rev 14264)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.editor;
+
+import org.eclipse.jface.dialogs.IMessageProvider;
+
+/**
+ * Simple implementation of {@link IMessageProvider}.
+ *
+ * @author yradtsevich
+ *
+ */
+public class Message implements IMessageProvider {
+ private String message;
+ private int messageType;
+
+ public Message(String text, int type) {
+ this.message = text;
+ this.messageType = type;
+ }
+ public String getMessage() {
+ return message;
+ }
+ public int getMessageType() {
+ return messageType;
+ }
+}
Modified: branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java
===================================================================
--- branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java 2009-03-19 13:36:13 UTC (rev 14263)
+++ branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java 2009-03-19 14:55:25 UTC (rev 14264)
@@ -10,12 +10,18 @@
******************************************************************************/
package org.jboss.tools.vpe.editor.template;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
@@ -30,7 +36,13 @@
import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.jsp.outline.cssdialog.CSSStyleDialog;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.editor.template.expression.VpeExpressionBuilder;
+import org.jboss.tools.vpe.editor.Message;
+import org.jboss.tools.vpe.editor.template.expression.VpeExpressionBuilderException;
import org.jboss.tools.vpe.messages.VpeUIMessages;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
/**
* Class which presents dialog for any template
@@ -41,9 +53,10 @@
private VpeAnyData data;
private CheckControl ctlChildren;
- private Text txtTagForDisplay;
+ private Text txtTagForDisplay;
private Text txtValue;
private Text txtStyle;
+ private VpeEditAnyDialogValidator templateVerifier;
public VpeEditAnyDialog(Shell shell, VpeAnyData data) {
super(shell);
@@ -52,10 +65,12 @@
@Override
protected Control createDialogArea(Composite parent) {
+ templateVerifier = new VpeEditAnyDialogValidator();
getShell().setText(VpeUIMessages.TEMPLATE);
setTitle(VpeUIMessages.TAG_ATTRIBUTES);
- setMessage((data.getUri() != null ? ("URI: " + data.getUri() + "\n") : "") + VpeUIMessages.TAG_NAME + data.getName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ setMessage(getDefaultMessage());
+
Composite topComposite = (Composite)super.createDialogArea(parent);
((GridData)topComposite.getLayoutData()).widthHint = 300;
@@ -80,6 +95,7 @@
gd.horizontalSpan=2;
txtTagForDisplay.setLayoutData(gd);
txtTagForDisplay.setText(data.getTagForDisplay() != null ? data.getTagForDisplay() : ""); //$NON-NLS-1$
+ txtTagForDisplay.addModifyListener(templateVerifier);
// txtTagForDisplay.select(tagNameItemIndex);
@@ -95,6 +111,7 @@
gd.horizontalSpan = 2;
txtValue.setLayoutData(gd);
txtValue.setText(data.getValue() != null ? data.getValue() : ""); //$NON-NLS-1$
+ txtValue.addModifyListener(templateVerifier);
//style control
Label lbStyle = makeLabel(composite, VpeUIMessages.STYLE);
@@ -132,7 +149,20 @@
return composite;
}
+
+
+ @Override
+ public void create() {
+ super.create();
+ templateVerifier.validateAll(false);
+ }
+
+ private IMessageProvider getDefaultMessage() {
+ final String message = (data.getUri() != null ? ("URI: " + data.getUri() + "\n") : "") + VpeUIMessages.TAG_NAME + data.getName(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return new Message(message, IMessageProvider.NONE);
+ }
+
private Label makeLabel(Composite parent, String text) {
Label lbl = new Label(parent, SWT.NONE);
lbl.setText(text);
@@ -174,6 +204,20 @@
return data.isChanged() || (oldValue != newValue);
}
+ /**
+ * Sets the message for this dialog with an indication of what type of
+ * message it is.
+ * <p>
+ * @param message the message, or <code>null</code> to clear the message
+ */
+ public void setMessage(IMessageProvider message) {
+ if (message == null) {
+ setMessage(null, IMessageProvider.NONE);
+ } else {
+ setMessage(message.getMessage(), message.getMessageType());
+ }
+ }
+
private class CheckControl {
private Label label;
private Button button;
@@ -198,4 +242,97 @@
return button.getSelection();
}
}
+
+ /**
+ * Validator of {@link VpeEditAnyDialog}.
+ *
+ * @author yradtsevich
+ */
+ private class VpeEditAnyDialogValidator implements ModifyListener {
+ /**
+ * Used to validate tag-names.
+ */
+ private Document xmlDocument = null;
+ public VpeEditAnyDialogValidator() {
+ try {
+ xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ } catch (ParserConfigurationException e) {
+ VpePlugin.getPluginLog().logError(e);
+ }
+ }
+
+ /**
+ * Validates {@link VpeEditAnyDialog#txtTagForDisplay} field.
+ *
+ * @return {@code null} if it is valid or an instance of {@code IMessageProvider} if
+ * it contains any error.
+ */
+ private IMessageProvider validateTagForDisplay() {
+ if (xmlDocument != null) {
+ try {
+ xmlDocument.createElement(txtTagForDisplay.getText());
+ } catch (DOMException e) {
+ return new Message(VpeUIMessages.TAG_FOR_DISPLAY + VpeUIMessages.ERROR_MESSAGE_POSTFIX + " (" + //$NON-NLS-1$
+ e.getMessage() + ")." , IMessageProvider.ERROR); //$NON-NLS-1$
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Validates {@link VpeEditAnyDialog#txtValue} field.
+ *
+ * @return {@code null} if it is valid or an instance of {@code IMessageProvider} if
+ * it contains any error.
+ */
+ private IMessageProvider validateValue() {
+
+ try {
+ VpeExpressionBuilder.buildCompletedExpression(txtValue.getText(), true);
+ } catch (VpeExpressionBuilderException e) {
+ return new Message(VpeUIMessages.VALUE + VpeUIMessages.ERROR_MESSAGE_POSTFIX + " (" + //$NON-NLS-1$
+ e.getMessage() + ")." , IMessageProvider.ERROR); //$NON-NLS-1$
+ }
+
+ return null;
+ }
+
+ /**
+ * Validates all fields of {@link VpeEditAnyDialog} and changes the view of
+ * dialog according to validation results.
+ *
+ * @param updateMessage if it is {@code true}, the dialog's message will be updated.
+ */
+ void validateAll(boolean updateMessage) {
+ IMessageProvider message = VpeEditAnyDialog.this.getDefaultMessage();
+
+ IMessageProvider tagForDisplayMessage = validateTagForDisplay();
+ IMessageProvider valueMessage = validateValue();
+
+ if (tagForDisplayMessage != null) {
+ message = tagForDisplayMessage;
+ } else if (valueMessage != null) {
+ message = valueMessage;
+ }
+
+ Button okButton = getButton(IDialogConstants.OK_ID);
+ if (message.getMessageType() <= IMessageProvider.INFORMATION) {
+ okButton.setEnabled(true);
+ } else {
+ okButton.setEnabled(false);
+ }
+
+ if (updateMessage) {
+ VpeEditAnyDialog.this.setMessage(message);
+ }
+ }
+
+ /**
+ * Fired when a field is modified.
+ */
+ public void modifyText(ModifyEvent e) {
+ validateAll(true);
+ }
+ }
}
Modified: branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
===================================================================
--- branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2009-03-19 13:36:13 UTC (rev 14263)
+++ branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2009-03-19 14:55:25 UTC (rev 14264)
@@ -81,6 +81,7 @@
public static String SHOW;
public static String HIDE;
public static String TAG_FOR_DISPLAY;
+ public static String ERROR_MESSAGE_POSTFIX;
public static String TemplatesPreferencePage_Edit;
public static String TemplatesPreferencePage_Remove;
public static String TemplatesTableProvider_Children;
Modified: branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
===================================================================
--- branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2009-03-19 13:36:13 UTC (rev 14263)
+++ branches/jbosstools-3.0.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2009-03-19 14:55:25 UTC (rev 14264)
@@ -59,6 +59,7 @@
SHOW=Show
HIDE=Hide
TAG_FOR_DISPLAY=Tag for Display
+ERROR_MESSAGE_POSTFIX=\ is not valid
TemplatesPreferencePage_Edit=Edit
TemplatesPreferencePage_Remove=Remove
TemplatesTableProvider_Children=Children
15 years, 3 months
JBoss Tools SVN: r14263 - in branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog: common and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: yradtsevich
Date: 2009-03-19 09:36:13 -0400 (Thu, 19 Mar 2009)
New Revision: 14263
Modified:
branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java
branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSModel.java
branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSValidator.java
branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/StyleAttributes.java
Log:
RESOLVED - issue JBIDE-3910: Need extended validator for CSS class name
https://jira.jboss.org/jira/browse/JBIDE-3910
- validator has been added.
- now css dialog does not format CSS before save
Modified: branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java
===================================================================
--- branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java 2009-03-19 09:19:53 UTC (rev 14262)
+++ branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java 2009-03-19 13:36:13 UTC (rev 14263)
@@ -1,878 +1,879 @@
-/*******************************************************************************
- * 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.outline.cssdialog;
-
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.IInputValidator;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.browser.Browser;
-import org.eclipse.swt.events.FocusAdapter;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.jboss.tools.common.model.ui.widgets.Split;
-import org.jboss.tools.jst.jsp.messages.JstUIMessages;
-import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSModel;
-import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSValidator;
-import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
-import org.jboss.tools.jst.jsp.outline.cssdialog.common.Util;
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleEvent;
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleListener;
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.ManualChangeStyleListener;
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.MessageDialogEvent;
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.MessageDialogListener;
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
-
-/**
- * This dialog represents CSSClass dialog.
- *
- * @author Igor Zhukov (izhukov(a)exadel.com)
- */
-public class CSSClassDialog extends TitleAreaDialog implements ChangeStyleListener {
-
- public static final String ID = "org.jboss.tools.jst.jsp.outline.cssdialog.CSSClassDialog"; //$NON-NLS-1$
-
- private static String notUsed = "not_used"; //$NON-NLS-1$
-// private final static String[] fileExtensions = { Util.CSS_FILE_EXTENTION };
-
- private Composite browserContainer = null;
- private Browser browser = null;
- private Text textBrowser = null;
- private String previewBrowserValue = JstUIMessages.DEFAULT_TEXT_FOR_BROWSER_PREVIEW;
-
- private StyleComposite styleComposite = null;
- private StyleAttributes styleAttributes = null;
- // css file path
- private Text text;
- // css style classes
- private Combo classCombo;
- // combo box content assist
-// private ContentAssistCommandAdapter contentAssistAdapter = null;
- // apply button
- private Button applyButton;
-
- // model is the core of the CSS Class Dialog, it manages style attributes
- private CSSModel cssModel;
-
- // file is "current" in case of the following priority order:
- // 1 - this is selected css file in eclipse project tree
- // 2 - this is opened and active css file
- private IFile currentFile;
- private String currentClassStyle = null;
-
- // workbench selection when the wizard was started
- protected IStructuredSelection selection;
-
- private boolean styleChanged = false;
-
-// private boolean keyInputSelector = false;
-
- // Status variables for the possible errors on this page.
- // 1. timeStatus holds an error if CSS file is not specified
- private IStatus filePathStatus = null;
- // 2. holds an error if the destination class style is empty
- private IStatus classNameStatus = null;
- // 3. holds an error if inccorrect property was specified
- private IStatus cssValueStatus =null;
-
- // an array of subscribed message dialog listener
- private ArrayList<MessageDialogListener> errorListeners = new ArrayList<MessageDialogListener>();
-
- // parameter indicates if dialog was opened from Wizard
- private final boolean callFromWizard;
-
- private Button addNewClass;
-
-
- /**
- * Constructor.
- *
- * @param parentShell Shell object
- * @param allProject (if allProject is true - browse css file in all projects, else only in current project)
- * @param callFromWizard indicates if CSS dialog is created within Wizard page
- */
- public CSSClassDialog(Shell parentShell, IStructuredSelection selection, boolean callFromWizard) {
- super(parentShell);
-
- setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX | SWT.APPLICATION_MODAL);
-
- filePathStatus = new Status(IStatus.ERROR, notUsed, 0, JstUIMessages.CSS_EMPTY_FILE_PATH_MESSAGE, null);
- classNameStatus = new Status(IStatus.ERROR, notUsed, 0, JstUIMessages.CSS_EMPTY_STYLE_CLASS_MESSAGE, null);
-
- styleAttributes = new StyleAttributes();
- styleAttributes.addChangeStyleListener(this);
- this.callFromWizard = callFromWizard;
- this.selection = selection;
- init();
- }
-
- /**
- * Initialize method.
- */
- private void init() {
- if (selection != null && !selection.isEmpty()) {
- for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
- Object element = iterator.next();
- if (element instanceof IResource) {
- if (element instanceof IFile) {
- if (((IFile) element).getName().toLowerCase().endsWith(Util.CSS_FILE_EXTENTION)) {
- currentFile = (IFile)element;
- }
- }
- }
- }
- }
- // if any CSS file is currently opened and has active page status this method should return style class
- // within this file where cursor is located
- if (currentFile == null) {
- currentFile = Util.getActiveCssFile();
- }
- }
-
- /**
- * Sets current style class value.
- *
- * @param currentClassStyle String value
- */
- public void setCurrentStyleClass(String currentClassStyle) {
- this.currentClassStyle = Util.formatStyleClassToCSSView(currentClassStyle);
- }
-
- /**
- * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite)
- */
- @Override
- protected Control createDialogArea(final Composite parent) {
- final Composite composite = (Composite) super.createDialogArea(parent);
- if(composite.getLayoutData()!=null && composite.getLayoutData() instanceof GridData) {
- ((GridData)composite.getLayoutData()).widthHint=500;
- ((GridData)composite.getLayoutData()).heightHint=500;
- }
- final Control control = createDialogComposite(composite);
- return control;
- }
-
- public Control createDialog(final Composite parent) {
- return createDialogArea(parent);
- }
-
- /**
- * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(Composite)
- */
- @Override
- protected void createButtonsForButtonBar(Composite parent) {
- super.createButtonsForButtonBar(parent);
- updateOKButtonState();
-
- }
- private Split split;
- /**
- * Create the dialog itself.
- *
- * @param composite parent window
- * @return eclipse Control object
- */
- private Control createDialogComposite(Composite composite) {
- if (!this.callFromWizard) {
- setTitle(JstUIMessages.CSS_STYLE_CLASS_EDITOR_TITLE);
- setMessage(JstUIMessages.CSS_STYLE_CLASS_EDITOR_DESCRIPTION);
- }
- composite.setLayout(new GridLayout());
-
- // ===============================================================================
- // Create split component that separates dialog on 2 parts
- // ===============================================================================
- split = new Split(composite, SWT.VERTICAL);
-
- // ===============================================================================
- // Create browser container
- // ===============================================================================
- browserContainer = getCompositeElement(split);
- // create browser component
- createBrowserComponent();
-
- // ===============================================================================
- // Create down splitter container
- // ===============================================================================
- Composite downSplitPane = getCompositeElement(split);
-
- Composite classComposite = new Composite(downSplitPane, SWT.BORDER);
- classComposite.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
- classComposite.setLayout(new GridLayout(3, false));
-
- // ===============================================================================
- // Create component that contains CSS file pass and it's selectors (style classes combo box)
- // ===============================================================================
- createCSSFilePathComponent(classComposite);
- createStyleClassCombo(classComposite);
-
- // ===============================================================================
- // Create style composite component
- // ===============================================================================
- styleComposite = new StyleComposite(downSplitPane, styleAttributes, Constants.EMPTY);
- styleComposite.addManualChangeStyleListener(new ManualChangeStyleListener() {
- public void styleChanged(ChangeStyleEvent event) {
- styleChanged = true;
- if (currentClassStyle != null && !currentClassStyle.equals(Constants.EMPTY)
- && currentFile != null && !currentFile.equals(Constants.EMPTY)) {
- updateApplyButton(true);
- }
- }
- });
-
- // ===============================================================================
- // Create custom button panel
- // ===============================================================================
- createCustomButtonPanel(downSplitPane);
-
- styleAttributes.addChangeStyleListener(new ChangeStyleListener() {
- public void styleChanged(ChangeStyleEvent event) {
- if (!browser.isDisposed()) {
- browser.setText(getTextForBrowser());
- }
- }
- });
-
- if (currentFile != null) {
- initCSSModel(currentFile, true, true);
- } else if (currentClassStyle != null) {
- classCombo.setText(currentClassStyle);
- styleAttributes.setCssSelector(currentClassStyle);
- }
-
- // add content assist to style COMBO component
- SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(classCombo.getItems());
- proposalProvider.setFiltering(true);
-
- split.setWeights(new int[]{15, 85});
- split.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
-
- return composite;
- }
-
- private void createCSSFilePathComponent(Composite parent) {
- Label label = new Label(parent, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.CSS_CLASS_DIALOG_FILE_LABEL);
-
- // Text field contains path to the CSS file
- text = new Text(parent, SWT.BORDER|SWT.READ_ONLY);
- GridData gridData =new GridData(GridData.FILL, GridData.CENTER, true, false);
- gridData.grabExcessHorizontalSpace=true;
- gridData.horizontalSpan=2;
- text.setLayoutData(gridData);
-// text.setEditable(false);
- text.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- String cssFile = text.getText().trim();
- // Initialize a variable with the no error status
- filePathStatus = new Status(IStatus.ERROR, notUsed, 0, JstUIMessages.CSS_EMPTY_FILE_PATH_MESSAGE, null);
- if (cssFile != null && !cssFile.equals(Constants.EMPTY)) {
- filePathStatus = new Status(IStatus.OK, notUsed, 0, JstUIMessages.CSS_STYLE_CLASS_EDITOR_DESCRIPTION, null);
- }
- // show corresponding message
- IStatus status = findMostSevere();
- notifyListeners(text, status);
- applyToStatusLine(status);
- }
- });
- }
-
- /**
- * This method is used to create and initialize style class comboBox component.
- *
- * @param parent Composite component
- */
- private void createStyleClassCombo(final Composite parent) {
- Label label = new Label(parent, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.CSS_CLASS_DIALOG_STYLE_CLASS_LABEL);
-
- GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
- gridData.horizontalSpan = 1;
-
- classCombo = new Combo(parent, SWT.BORDER|SWT.READ_ONLY);
- classCombo.setLayoutData(gridData);
- // this listener is responsible for processing dialog header message events
- classCombo.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- String cssClass = classCombo.getText().trim();
- // Initialize a variable with the no error status
- classNameStatus = new Status(IStatus.ERROR, notUsed, 0, JstUIMessages.CSS_EMPTY_STYLE_CLASS_MESSAGE, null);
- if (cssClass != null && !cssClass.equals(Constants.EMPTY)) {
- classNameStatus = new Status(IStatus.OK, notUsed, 0, JstUIMessages.CSS_STYLE_CLASS_EDITOR_DESCRIPTION, null);
- }
- // show corresponding message
- IStatus status = findMostSevere();
- notifyListeners(classCombo, status);
- applyToStatusLine(status);
- // update CSS style cmposite if needed
- if ((currentClassStyle != null && currentClassStyle.equals(classCombo.getText().trim()))
- || (currentClassStyle == null && classCombo.getText().trim().equals(Constants.EMPTY))) {
- return;
- }
- cssStyleClassChanged();
- updateApplyButton(false);
- }
- });
- //creates a button for add new class
- addNewClass = new Button(parent, SWT.PUSH);
- addNewClass.setText(JstUIMessages.BUTTON_ADD_NEW_STYLE_CLASS);
- addNewClass.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- InputDialog dlg = new InputDialog(parent.getShell(),
- JstUIMessages.ENTER_CSS_CLASS_NAME, JstUIMessages.ENTER_CSS_CLASS_NAME, classCombo.getText(),
- new IInputValidator(){
- /**
- * Simple validation of new CSS Class Name, now we just check that it's not empty string
- */
- public String isValid(String newText) {
- if(newText==null || newText.trim().length()==0){
- return JstUIMessages.CSS_CLASS_NAME_NOT_VALID;
- }
- return null;
- }
-
- });
- if (dlg.open() == Window.OK) {
- addNewStyleClass(dlg.getValue().trim());
- }
- }
- });
- }
- /**
- * Add New Class to CSS Class Dialog
- * @param styleClassName - name of new style class
- */
- public void addNewStyleClass(String styleClassName) {
- updateApplyButton(true);
- styleChanged = true;
- currentClassStyle = styleClassName;
- updateStyleComposite();
- styleAttributes.setCssSelector(currentClassStyle);
- styleComposite.updatePreview(currentClassStyle);
- updateOKButtonState();
- // add new class to end of list
- if (classCombo.indexOf(currentClassStyle) == -1)
- classCombo.add(currentClassStyle);
- // end select it
- classCombo.select(classCombo.getItemCount() - 1);
- cssModel.setCSS(currentClassStyle, styleAttributes);
- }
-// /**
-// * This method is invoked to correctly process class style combo modify event.
-// */
-// private void notifyStyleClassChanged() {
-// Display display = null;
-// if (PlatformUI.isWorkbenchRunning()) {
-// display = PlatformUI.getWorkbench().getDisplay();
-// }
-// if (display != null && (Thread.currentThread() == display.getThread())) {
-// if (uiJob == null) {
-// uiJob = new UIJob(jobName) {
-// @Override
-// public IStatus runInUIThread(IProgressMonitor monitor) {
-// if (monitor.isCanceled()) {
-// return Status.CANCEL_STATUS;
-// }
-// monitor.beginTask(jobName, IProgressMonitor.UNKNOWN);
-//
-// // start operation
-// cssStyleClassChanged();
-// // end operation
-//
-// monitor.done();
-//
-// return Status.OK_STATUS;
-// }
-// };
-// }
-//
-// uiJob.setPriority(Job.SHORT);
-// uiJob.schedule(delay);
-//
-// return;
-// }
-// }
-
- /**
- * This method is used to create custom button panel.
- *
- * @param parent Composite component
- */
- private void createCustomButtonPanel(Composite parent) {
- Composite buttonComposite = new Composite(parent, SWT.NONE);
- buttonComposite.setLayoutData(new GridData(GridData.END, GridData.BEGINNING, true, false));
- buttonComposite.setLayout(new GridLayout());
- // add APPLY button
- applyButton = createCustomButton(buttonComposite, JstUIMessages.BUTTON_APPLY);
- updateApplyButton(false);
- applyButton.setToolTipText(JstUIMessages.CSS_APPLY_CHANGES);
- applyButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- if (currentClassStyle != null && !currentClassStyle.equals(Constants.EMPTY)) {
- // update ComboBox element list
- if (classCombo.indexOf(currentClassStyle) == -1) {
- classCombo.add(currentClassStyle);
- }
- saveChanges(false);
- updateApplyButton(false);
- styleChanged = false;
- }
- }
- });
- // add CLEAR button
- Button clearButton = createCustomButton(buttonComposite, JstUIMessages.BUTTON_CLEAR);
- clearButton.setToolTipText(JstUIMessages.CSS_CLEAR_STYLE_SHEET);
- clearButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- styleComposite.clearStyleComposite(currentClassStyle);
- styleComposite.updatePreview(currentClassStyle);
- styleComposite.updateStyle();
- updateApplyButton(true);
- styleChanged = true;
- }
- });
- }
-
- /**
- * This method is used to create custom button.
- *
- * @param parent Composite component
- * @param label Button label value
- */
- protected Button createCustomButton(Composite parent, String label) {
- // increment the number of columns in the button bar
- ((GridLayout) parent.getLayout()).numColumns++;
- Button button = new Button(parent, SWT.PUSH);
- button.setText(label);
-// setButtonLayoutData(button);
- return button;
- }
-
- /**
- * Method is used to correctly process style class change operation.
- */
- private void cssStyleClassChanged() {
- if (currentFile != null && !currentFile.equals(Constants.EMPTY)) {
-// if (styleChanged && currentClassStyle != null && !currentClassStyle.equals(Constants.EMPTY)) {
-// MessageBox messageBox = new MessageBox(getParentShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
-// messageBox.setText(JstUIMessages.CSS_SAVE_DIALOG_TITLE);
-// messageBox.setMessage(CSSClassDialog.getMessageForSaveDialog(currentFile));
-// int result = messageBox.open();
-// if (result == SWT.YES) {
-// // update ComboBox element list
-// if (classCombo.indexOf(currentClassStyle) == -1) {
-// classCombo.add(currentClassStyle);
-// }
- cssModel.setCSS(currentClassStyle, styleAttributes);
-// // update content assist proposals
-// SimpleContentProposalProvider proposalProvider =
-// (SimpleContentProposalProvider)contentAssistAdapter.getContentProposalProvider();
-// proposalProvider.setProposals(classCombo.getItems());
-// } else {
-// // FOR https://jira.jboss.org/jira/browse/JBIDE-3542
-// // cssModel.init(currentFile);
-// // styleComposite.revertPreview();
-// }
-// }
- // update current class style value
- currentClassStyle = classCombo.getText().trim();
-
- // if new css was added
-// if (classCombo.indexOf(currentClassStyle) == -1) {
-// classCombo.add(currentClassStyle);
-// styleChanged = true;
-// } else {
-// styleChanged = false;
-// }
- updateApplyButton(true);
- styleChanged = true;
-
- updateStyleComposite();
- styleAttributes.setCssSelector(currentClassStyle);
- styleComposite.updatePreview(currentClassStyle);
- updateOKButtonState();
- } else {
- currentClassStyle = classCombo.getText().trim();
- styleAttributes.setCssSelector(currentClassStyle);
- styleChanged = false;
- }
-
- }
-
- /**
- * Initialize CSS model with active opened CSS file.
- *
- * @param file IFile object
- * @param useRelativePathPath
- */
- private void initCSSModel(IFile file, boolean useRelativePathPath, boolean updateCSSModel) {
- if (file != null) {
- // create CSS Model
- cssModel = new CSSModel(file);
- currentClassStyle = null;
- classCombo.removeAll();
- classCombo.setEnabled(true);
- // set file path to corresponding text field
- if (useRelativePathPath) {
- text.setText(file.getProjectRelativePath().toOSString());
- } else {
- text.setText(file.getFullPath().toOSString());
- }
-
- Point selectionInFile = Util.getSelectionInFile(file);
-
- currentClassStyle = cssModel.getSelectorByPosition(selectionInFile);
-
- // fill in ComboBox component with CSS model selectors
-// List<Selector> selectors = cssModel.getSelectors();
- List<String> selectors = cssModel.getSelectorLabels();
- for (int i = 0; i < selectors.size(); i++) {
-// Selector value = selectors.get(i);
- String label = selectors.get(i);
- classCombo.add(/*value.getValue()*/ label);
-
- }
- /*
- *
- */
- if (currentClassStyle != null) {
- classCombo.setText(currentClassStyle);
- } else {
- classCombo.select(0);
- }
- classCombo.setToolTipText(cssModel.getCSSText(currentClassStyle));
-
- styleComposite.setShowPreviewTab(true);
- styleComposite.setCSSModel(cssModel);
- // update style composite component with the values from new CSS file
- if (updateCSSModel) {
- updateStyleComposite();
- }
- styleComposite.initPreview(cssModel);
- }
- }
-
- /**
- * This method takes affect to OK button when dialog is opened in "dialog" mode and not in "wizard".
- * In case of "wizard" mode OK button is not available.
- */
- private void updateOKButtonState() {
- Button okButton = getButton(IDialogConstants.OK_ID);
- if (okButton != null) {
- if (findMostSevere()!=null&&findMostSevere().getSeverity()==IStatus.ERROR) {
- okButton.setEnabled(false);
- } else {
- okButton.setEnabled(true);
- }
- }
- }
-
- /**
- * Method is used to create browser component to display preview HTML.
- */
- private void createBrowserComponent() {
- GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
- browser = new Browser(browserContainer, SWT.BORDER | SWT.MOZILLA);
- browser.setText(getTextForBrowser());
- browser.addMouseListener(new MouseAdapter() {
- public void mouseDoubleClick(MouseEvent e) {
- if (e.widget == browser) {
- browser.removeMouseListener(this);
- browser.dispose();
- // create Text area component instead of HTML Browser
- GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
-// textBrowser = new Text(browserContainer, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
- textBrowser = new Text(browserContainer, SWT.NONE | SWT.H_SCROLL);
- textBrowser.setText(previewBrowserValue);
- textBrowser.addFocusListener(new FocusAdapter() {
- public void focusLost(FocusEvent e) {
- if (e.widget == textBrowser) {
- String text = textBrowser.getText();
- if (text == null || text.equals(Constants.EMPTY)) {
- previewBrowserValue = JstUIMessages.DEFAULT_TEXT_FOR_BROWSER_PREVIEW;
- } else {
- previewBrowserValue = text;
- }
- textBrowser.dispose();
- // create Browse component instead of text area
- createBrowserComponent();
- }
- browserContainer.layout();
- }
- });
- textBrowser.setLayoutData(gridData);
- textBrowser.setEditable(true);
- textBrowser.setFocus();
- }
- browserContainer.layout();
- }
- });
- browser.setLayoutData(gridData);
- }
-
- /**
- * Update style composite component in accordance with the attributes of selected CSS selector.
- */
- private void updateStyleComposite() {
- String style = cssModel.getStyle(currentClassStyle);
- styleComposite.recreateStyleComposite(style, currentClassStyle);
- }
-
- /**
- * Method is used to build html body that is appropriate to browse.
- *
- * @return String html text representation
- */
- private String getTextForBrowser() {
- String styleForSpan = Constants.EMPTY;
- Set<String> keySet = styleAttributes.keySet();
- for (String key : keySet) {
- styleForSpan += (key + Constants.COLON + styleAttributes.getAttribute(key) + Constants.SEMICOLON);
- }
- String html = Constants.OPEN_DIV_TAG + styleForSpan + "\">" + previewBrowserValue + Constants.CLOSE_DIV_TAG; //$NON-NLS-1$
-
- return html;
- }
-
- /**
- * Create container that take up 2 cells and contains fontSizeCombo and extFontSizeCombo elements.
- */
- private Composite getCompositeElement(Composite parent) {
- GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
- GridLayout gridLayoutTmp = new GridLayout();
- gridLayoutTmp.marginHeight = 0;
- gridLayoutTmp.marginWidth = 0;
- Composite classComposite = new Composite(parent, SWT.FILL);
- classComposite.setLayout(gridLayoutTmp);
- classComposite.setLayoutData(gridData);
-
- return classComposite;
- }
-
- public void releaseResources() {
-
- if (cssModel != null){
- cssModel.releaseModel();
- cssModel = null;
- }
- }
-
- /**
- * Method should be called in case of dialog closure operation.
- */
- public void saveChanges(boolean close) {
- styleComposite.updateStyle();
- cssModel.setCSS(currentClassStyle, styleAttributes);
- cssModel.saveModel();
- }
-
- /**
- * Gets current selected style class value.
- *
- * @return selector name
- */
- public String getSelectorName() {
- return Util.formatCSSSelectorToStyleClassView(currentClassStyle);
- }
-
- /**
- * Method for setting title for dialog
- *
- * @param newShell Shell object
- * @see org.eclipse.jface.window.Window#configureShell(Shell)
- */
- @Override
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- newShell.setText(JstUIMessages.CSS_STYLE_CLASS_EDITOR_TITLE);
- }
-
- /**
- * This method close the dialog.
- *
- * @return true if dialog was closed, false - otherwise
- */
- public boolean closeDialog() {
- setReturnCode(Window.CANCEL);
- return close();
- }
-
- /**
- * @see org.eclipse.jface.dialogs.Dialog#close()
- */
- @Override
- public boolean close() {
- int code = getReturnCode();
- switch (code) {
- case OK:
- if (styleChanged || classCombo.indexOf(currentClassStyle) == -1) {
- saveChanges(true);
- }
- break;
- case CANCEL:
- default:
- // make some closure operation
- }
- releaseResources();
- return super.close();
- }
-
- /**
- * Add MessageDialogListener object.
- *
- * @param listener MessageDialogListener object to be added
- */
- public void addMessageDialogListener(MessageDialogListener listener) {
- errorListeners.add(listener);
- }
-
- /**
- * Method is used to notify all subscribed listeners about possible any errors on the page.
- */
- private void notifyListeners(Object source, IStatus operationStatus) {
- MessageDialogEvent event = new MessageDialogEvent(source, operationStatus);
- for (MessageDialogListener listener : errorListeners) {
- listener.throwMessage(event);
- }
- }
-
- /**
- * Method return the most serious error occurs on the page and that should be displayed.
- *
- * @return IStatus object
- */
- private IStatus findMostSevere() {
- if (filePathStatus.matches(IStatus.ERROR)) {
- return filePathStatus;
- }
- if (classNameStatus.matches(IStatus.ERROR)) {
- return classNameStatus;
- }
- if(cssValueStatus!=null && cssValueStatus.matches(IStatus.ERROR)){
- return cssValueStatus;
- }
- if(cssValueStatus!=null && cssValueStatus.matches(IStatus.ERROR)){
- return cssValueStatus;
- } else {
- return classNameStatus;
- }
-
- }
-
- /**
- * Applies the status to the status line of a dialog page.
- */
- private void applyToStatusLine(IStatus status) {
- if (!callFromWizard) {
- String message= status.getMessage();
- if (message.length() == 0) {
- message = null;
- }
- switch (status.getSeverity()) {
- case IStatus.OK:
- setErrorMessage(null);
- setMessage(message);
- break;
- case IStatus.WARNING:
- setErrorMessage(null);
- setMessage(message, WizardPage.WARNING);
- break;
- case IStatus.INFO:
- setErrorMessage(null);
- setMessage(message, WizardPage.INFORMATION);
- break;
- default:
- setErrorMessage(message);
- setMessage(null);
- break;
- }
- }
- }
-
- public void reinit(){
- releaseResources();
- initCSSModel(currentFile, true,true);
- }
-
- public void setCurrentFile(IFile currentFile) {
- this.currentFile = currentFile;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleListener#styleChanged(org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleEvent)
- */
- public void styleChanged(ChangeStyleEvent event) {
- if (!this.styleAttributes.isValid()) {
- cssValueStatus = new Status(IStatus.ERROR, notUsed, 0,
- JstUIMessages.CSS_INVALID_STYLE_PROPERTY, null);
- notifyListeners(event, cssValueStatus);
- addNewClass.setEnabled(false);
- } else {
- cssValueStatus = null;
- addNewClass.setEnabled(true);
- notifyListeners(event, new Status(IStatus.OK, notUsed, 0,
- JstUIMessages.CSS_STYLE_CLASS_EDITOR_DESCRIPTION, null));
- }
- if (cssValueStatus != null && classCombo != null) {
- classCombo.setEnabled(false);
- } else {
- classCombo.setEnabled(true);
-
- }
- updateApplyButton(true);
- updateOKButtonState();
- applyToStatusLine(findMostSevere());
- }
- /**
- * Update upplyButtonState
- * @param available
- */
- private void updateApplyButton(boolean enabled){
- if(cssValueStatus!=null
- &&cssValueStatus.matches(IStatus.ERROR)) {
- applyButton.setEnabled(false);
- }else {
- applyButton.setEnabled(enabled);
- }
-
- }
-}
+/*******************************************************************************
+ * 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.outline.cssdialog;
+
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.common.model.ui.widgets.Split;
+import org.jboss.tools.jst.jsp.messages.JstUIMessages;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSModel;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSValidator;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Util;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleEvent;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleListener;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.ManualChangeStyleListener;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.MessageDialogEvent;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.MessageDialogListener;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
+
+/**
+ * This dialog represents CSSClass dialog.
+ *
+ * @author Igor Zhukov (izhukov(a)exadel.com)
+ */
+public class CSSClassDialog extends TitleAreaDialog implements ChangeStyleListener {
+
+ public static final String ID = "org.jboss.tools.jst.jsp.outline.cssdialog.CSSClassDialog"; //$NON-NLS-1$
+
+ private static String notUsed = "not_used"; //$NON-NLS-1$
+// private final static String[] fileExtensions = { Util.CSS_FILE_EXTENTION };
+
+ private Composite browserContainer = null;
+ private Browser browser = null;
+ private Text textBrowser = null;
+ private String previewBrowserValue = JstUIMessages.DEFAULT_TEXT_FOR_BROWSER_PREVIEW;
+
+ private StyleComposite styleComposite = null;
+ private StyleAttributes styleAttributes = null;
+ // css file path
+ private Text text;
+ // css style classes
+ private Combo classCombo;
+ // combo box content assist
+// private ContentAssistCommandAdapter contentAssistAdapter = null;
+ // apply button
+ private Button applyButton;
+
+ // model is the core of the CSS Class Dialog, it manages style attributes
+ private CSSModel cssModel;
+
+ // file is "current" in case of the following priority order:
+ // 1 - this is selected css file in eclipse project tree
+ // 2 - this is opened and active css file
+ private IFile currentFile;
+ private String currentClassStyle = null;
+
+ // workbench selection when the wizard was started
+ protected IStructuredSelection selection;
+
+ private boolean styleChanged = false;
+
+// private boolean keyInputSelector = false;
+
+ // Status variables for the possible errors on this page.
+ // 1. timeStatus holds an error if CSS file is not specified
+ private IStatus filePathStatus = null;
+ // 2. holds an error if the destination class style is empty
+ private IStatus classNameStatus = null;
+ // 3. holds an error if inccorrect property was specified
+ private IStatus cssValueStatus =null;
+
+ // an array of subscribed message dialog listener
+ private ArrayList<MessageDialogListener> errorListeners = new ArrayList<MessageDialogListener>();
+
+ // parameter indicates if dialog was opened from Wizard
+ private final boolean callFromWizard;
+
+ private Button addNewClass;
+
+
+ /**
+ * Constructor.
+ *
+ * @param parentShell Shell object
+ * @param allProject (if allProject is true - browse css file in all projects, else only in current project)
+ * @param callFromWizard indicates if CSS dialog is created within Wizard page
+ */
+ public CSSClassDialog(Shell parentShell, IStructuredSelection selection, boolean callFromWizard) {
+ super(parentShell);
+
+ setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX | SWT.APPLICATION_MODAL);
+
+ filePathStatus = new Status(IStatus.ERROR, notUsed, 0, JstUIMessages.CSS_EMPTY_FILE_PATH_MESSAGE, null);
+ classNameStatus = new Status(IStatus.ERROR, notUsed, 0, JstUIMessages.CSS_EMPTY_STYLE_CLASS_MESSAGE, null);
+
+ styleAttributes = new StyleAttributes();
+ styleAttributes.addChangeStyleListener(this);
+ this.callFromWizard = callFromWizard;
+ this.selection = selection;
+ init();
+ }
+
+ /**
+ * Initialize method.
+ */
+ private void init() {
+ if (selection != null && !selection.isEmpty()) {
+ for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
+ Object element = iterator.next();
+ if (element instanceof IResource) {
+ if (element instanceof IFile) {
+ if (((IFile) element).getName().toLowerCase().endsWith(Util.CSS_FILE_EXTENTION)) {
+ currentFile = (IFile)element;
+ }
+ }
+ }
+ }
+ }
+ // if any CSS file is currently opened and has active page status this method should return style class
+ // within this file where cursor is located
+ if (currentFile == null) {
+ currentFile = Util.getActiveCssFile();
+ }
+ }
+
+ /**
+ * Sets current style class value.
+ *
+ * @param currentClassStyle String value
+ */
+ public void setCurrentStyleClass(String currentClassStyle) {
+ this.currentClassStyle = Util.formatStyleClassToCSSView(currentClassStyle);
+ }
+
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite)
+ */
+ @Override
+ protected Control createDialogArea(final Composite parent) {
+ final Composite composite = (Composite) super.createDialogArea(parent);
+ if(composite.getLayoutData()!=null && composite.getLayoutData() instanceof GridData) {
+ ((GridData)composite.getLayoutData()).widthHint=500;
+ ((GridData)composite.getLayoutData()).heightHint=500;
+ }
+ final Control control = createDialogComposite(composite);
+ return control;
+ }
+
+ public Control createDialog(final Composite parent) {
+ return createDialogArea(parent);
+ }
+
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(Composite)
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+ updateOKButtonState();
+
+ }
+ private Split split;
+ /**
+ * Create the dialog itself.
+ *
+ * @param composite parent window
+ * @return eclipse Control object
+ */
+ private Control createDialogComposite(Composite composite) {
+ if (!this.callFromWizard) {
+ setTitle(JstUIMessages.CSS_STYLE_CLASS_EDITOR_TITLE);
+ setMessage(JstUIMessages.CSS_STYLE_CLASS_EDITOR_DESCRIPTION);
+ }
+ composite.setLayout(new GridLayout());
+
+ // ===============================================================================
+ // Create split component that separates dialog on 2 parts
+ // ===============================================================================
+ split = new Split(composite, SWT.VERTICAL);
+
+ // ===============================================================================
+ // Create browser container
+ // ===============================================================================
+ browserContainer = getCompositeElement(split);
+ // create browser component
+ createBrowserComponent();
+
+ // ===============================================================================
+ // Create down splitter container
+ // ===============================================================================
+ Composite downSplitPane = getCompositeElement(split);
+
+ Composite classComposite = new Composite(downSplitPane, SWT.BORDER);
+ classComposite.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
+ classComposite.setLayout(new GridLayout(3, false));
+
+ // ===============================================================================
+ // Create component that contains CSS file pass and it's selectors (style classes combo box)
+ // ===============================================================================
+ createCSSFilePathComponent(classComposite);
+ createStyleClassCombo(classComposite);
+
+ // ===============================================================================
+ // Create style composite component
+ // ===============================================================================
+ styleComposite = new StyleComposite(downSplitPane, styleAttributes, Constants.EMPTY);
+ styleComposite.addManualChangeStyleListener(new ManualChangeStyleListener() {
+ public void styleChanged(ChangeStyleEvent event) {
+ styleChanged = true;
+ if (currentClassStyle != null && !currentClassStyle.equals(Constants.EMPTY)
+ && currentFile != null && !currentFile.equals(Constants.EMPTY)) {
+ updateApplyButton(true);
+ }
+ }
+ });
+
+ // ===============================================================================
+ // Create custom button panel
+ // ===============================================================================
+ createCustomButtonPanel(downSplitPane);
+
+ styleAttributes.addChangeStyleListener(new ChangeStyleListener() {
+ public void styleChanged(ChangeStyleEvent event) {
+ if (!browser.isDisposed()) {
+ browser.setText(getTextForBrowser());
+ }
+ }
+ });
+
+ if (currentFile != null) {
+ initCSSModel(currentFile, true, true);
+ } else if (currentClassStyle != null) {
+ classCombo.setText(currentClassStyle);
+ styleAttributes.setCssSelector(currentClassStyle);
+ }
+
+ // add content assist to style COMBO component
+ SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(classCombo.getItems());
+ proposalProvider.setFiltering(true);
+
+ split.setWeights(new int[]{15, 85});
+ split.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
+
+ return composite;
+ }
+
+ private void createCSSFilePathComponent(Composite parent) {
+ Label label = new Label(parent, SWT.LEFT);
+ label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
+ label.setText(JstUIMessages.CSS_CLASS_DIALOG_FILE_LABEL);
+
+ // Text field contains path to the CSS file
+ text = new Text(parent, SWT.BORDER|SWT.READ_ONLY);
+ GridData gridData =new GridData(GridData.FILL, GridData.CENTER, true, false);
+ gridData.grabExcessHorizontalSpace=true;
+ gridData.horizontalSpan=2;
+ text.setLayoutData(gridData);
+// text.setEditable(false);
+ text.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ String cssFile = text.getText().trim();
+ // Initialize a variable with the no error status
+ filePathStatus = new Status(IStatus.ERROR, notUsed, 0, JstUIMessages.CSS_EMPTY_FILE_PATH_MESSAGE, null);
+ if (cssFile != null && !cssFile.equals(Constants.EMPTY)) {
+ filePathStatus = new Status(IStatus.OK, notUsed, 0, JstUIMessages.CSS_STYLE_CLASS_EDITOR_DESCRIPTION, null);
+ }
+ // show corresponding message
+ IStatus status = findMostSevere();
+ notifyListeners(text, status);
+ applyToStatusLine(status);
+ }
+ });
+ }
+
+ /**
+ * This method is used to create and initialize style class comboBox component.
+ *
+ * @param parent Composite component
+ */
+ private void createStyleClassCombo(final Composite parent) {
+ Label label = new Label(parent, SWT.LEFT);
+ label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
+ label.setText(JstUIMessages.CSS_CLASS_DIALOG_STYLE_CLASS_LABEL);
+
+ GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
+ gridData.horizontalSpan = 1;
+
+ classCombo = new Combo(parent, SWT.BORDER|SWT.READ_ONLY);
+ classCombo.setLayoutData(gridData);
+ // this listener is responsible for processing dialog header message events
+ classCombo.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ String cssClass = classCombo.getText().trim();
+ // Initialize a variable with the no error status
+ classNameStatus = new Status(IStatus.ERROR, notUsed, 0, JstUIMessages.CSS_EMPTY_STYLE_CLASS_MESSAGE, null);
+ if (cssClass != null && !cssClass.equals(Constants.EMPTY)) {
+ classNameStatus = new Status(IStatus.OK, notUsed, 0, JstUIMessages.CSS_STYLE_CLASS_EDITOR_DESCRIPTION, null);
+ }
+ // show corresponding message
+ IStatus status = findMostSevere();
+ notifyListeners(classCombo, status);
+ applyToStatusLine(status);
+ // update CSS style cmposite if needed
+ if ((currentClassStyle != null && currentClassStyle.equals(classCombo.getText().trim()))
+ || (currentClassStyle == null && classCombo.getText().trim().equals(Constants.EMPTY))) {
+ return;
+ }
+ cssStyleClassChanged();
+ updateApplyButton(false);
+ }
+ });
+ //creates a button for add new class
+ addNewClass = new Button(parent, SWT.PUSH);
+ addNewClass.setText(JstUIMessages.BUTTON_ADD_NEW_STYLE_CLASS);
+ addNewClass.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ InputDialog dlg = new InputDialog(parent.getShell(),
+ JstUIMessages.ENTER_CSS_CLASS_NAME, JstUIMessages.ENTER_CSS_CLASS_NAME, classCombo.getText(),
+ new IInputValidator(){
+ private CSSValidator cssValidator = CSSValidator.getInstance();
+ /**
+ * Validation of new CSS Class Name
+ */
+ public String isValid(String newText) {
+ if (cssValidator.isValidSelector(newText)) {
+ return null;
+ } else {
+ return JstUIMessages.CSS_CLASS_NAME_NOT_VALID;
+ }
+ }
+ });
+ if (dlg.open() == Window.OK) {
+ addNewStyleClass(dlg.getValue().trim());
+ }
+ }
+ });
+ }
+ /**
+ * Add New Class to CSS Class Dialog
+ * @param styleClassName - name of new style class
+ */
+ public void addNewStyleClass(String styleClassName) {
+ updateApplyButton(true);
+ styleChanged = true;
+ currentClassStyle = styleClassName;
+ updateStyleComposite();
+ styleAttributes.setCssSelector(currentClassStyle);
+ styleComposite.updatePreview(currentClassStyle);
+ updateOKButtonState();
+ // add new class to end of list
+ if (classCombo.indexOf(currentClassStyle) == -1)
+ classCombo.add(currentClassStyle);
+ // end select it
+ classCombo.select(classCombo.getItemCount() - 1);
+ cssModel.setCSS(currentClassStyle, styleAttributes);
+ }
+// /**
+// * This method is invoked to correctly process class style combo modify event.
+// */
+// private void notifyStyleClassChanged() {
+// Display display = null;
+// if (PlatformUI.isWorkbenchRunning()) {
+// display = PlatformUI.getWorkbench().getDisplay();
+// }
+// if (display != null && (Thread.currentThread() == display.getThread())) {
+// if (uiJob == null) {
+// uiJob = new UIJob(jobName) {
+// @Override
+// public IStatus runInUIThread(IProgressMonitor monitor) {
+// if (monitor.isCanceled()) {
+// return Status.CANCEL_STATUS;
+// }
+// monitor.beginTask(jobName, IProgressMonitor.UNKNOWN);
+//
+// // start operation
+// cssStyleClassChanged();
+// // end operation
+//
+// monitor.done();
+//
+// return Status.OK_STATUS;
+// }
+// };
+// }
+//
+// uiJob.setPriority(Job.SHORT);
+// uiJob.schedule(delay);
+//
+// return;
+// }
+// }
+
+ /**
+ * This method is used to create custom button panel.
+ *
+ * @param parent Composite component
+ */
+ private void createCustomButtonPanel(Composite parent) {
+ Composite buttonComposite = new Composite(parent, SWT.NONE);
+ buttonComposite.setLayoutData(new GridData(GridData.END, GridData.BEGINNING, true, false));
+ buttonComposite.setLayout(new GridLayout());
+ // add APPLY button
+ applyButton = createCustomButton(buttonComposite, JstUIMessages.BUTTON_APPLY);
+ updateApplyButton(false);
+ applyButton.setToolTipText(JstUIMessages.CSS_APPLY_CHANGES);
+ applyButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ if (currentClassStyle != null && !currentClassStyle.equals(Constants.EMPTY)) {
+ // update ComboBox element list
+ if (classCombo.indexOf(currentClassStyle) == -1) {
+ classCombo.add(currentClassStyle);
+ }
+ saveChanges(false);
+ updateApplyButton(false);
+ styleChanged = false;
+ }
+ }
+ });
+ // add CLEAR button
+ Button clearButton = createCustomButton(buttonComposite, JstUIMessages.BUTTON_CLEAR);
+ clearButton.setToolTipText(JstUIMessages.CSS_CLEAR_STYLE_SHEET);
+ clearButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ styleComposite.clearStyleComposite(currentClassStyle);
+ styleComposite.updatePreview(currentClassStyle);
+ styleComposite.updateStyle();
+ updateApplyButton(true);
+ styleChanged = true;
+ }
+ });
+ }
+
+ /**
+ * This method is used to create custom button.
+ *
+ * @param parent Composite component
+ * @param label Button label value
+ */
+ protected Button createCustomButton(Composite parent, String label) {
+ // increment the number of columns in the button bar
+ ((GridLayout) parent.getLayout()).numColumns++;
+ Button button = new Button(parent, SWT.PUSH);
+ button.setText(label);
+// setButtonLayoutData(button);
+ return button;
+ }
+
+ /**
+ * Method is used to correctly process style class change operation.
+ */
+ private void cssStyleClassChanged() {
+ if (currentFile != null && !currentFile.equals(Constants.EMPTY)) {
+// if (styleChanged && currentClassStyle != null && !currentClassStyle.equals(Constants.EMPTY)) {
+// MessageBox messageBox = new MessageBox(getParentShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
+// messageBox.setText(JstUIMessages.CSS_SAVE_DIALOG_TITLE);
+// messageBox.setMessage(CSSClassDialog.getMessageForSaveDialog(currentFile));
+// int result = messageBox.open();
+// if (result == SWT.YES) {
+// // update ComboBox element list
+// if (classCombo.indexOf(currentClassStyle) == -1) {
+// classCombo.add(currentClassStyle);
+// }
+ cssModel.setCSS(currentClassStyle, styleAttributes);
+// // update content assist proposals
+// SimpleContentProposalProvider proposalProvider =
+// (SimpleContentProposalProvider)contentAssistAdapter.getContentProposalProvider();
+// proposalProvider.setProposals(classCombo.getItems());
+// } else {
+// // FOR https://jira.jboss.org/jira/browse/JBIDE-3542
+// // cssModel.init(currentFile);
+// // styleComposite.revertPreview();
+// }
+// }
+ // update current class style value
+ currentClassStyle = classCombo.getText().trim();
+
+ // if new css was added
+// if (classCombo.indexOf(currentClassStyle) == -1) {
+// classCombo.add(currentClassStyle);
+// styleChanged = true;
+// } else {
+// styleChanged = false;
+// }
+ updateApplyButton(true);
+ styleChanged = true;
+
+ updateStyleComposite();
+ styleAttributes.setCssSelector(currentClassStyle);
+ styleComposite.updatePreview(currentClassStyle);
+ updateOKButtonState();
+ } else {
+ currentClassStyle = classCombo.getText().trim();
+ styleAttributes.setCssSelector(currentClassStyle);
+ styleChanged = false;
+ }
+
+ }
+
+ /**
+ * Initialize CSS model with active opened CSS file.
+ *
+ * @param file IFile object
+ * @param useRelativePathPath
+ */
+ private void initCSSModel(IFile file, boolean useRelativePathPath, boolean updateCSSModel) {
+ if (file != null) {
+ // create CSS Model
+ cssModel = new CSSModel(file);
+ currentClassStyle = null;
+ classCombo.removeAll();
+ classCombo.setEnabled(true);
+ // set file path to corresponding text field
+ if (useRelativePathPath) {
+ text.setText(file.getProjectRelativePath().toOSString());
+ } else {
+ text.setText(file.getFullPath().toOSString());
+ }
+
+ Point selectionInFile = Util.getSelectionInFile(file);
+
+ currentClassStyle = cssModel.getSelectorByPosition(selectionInFile);
+
+ // fill in ComboBox component with CSS model selectors
+// List<Selector> selectors = cssModel.getSelectors();
+ List<String> selectors = cssModel.getSelectorLabels();
+ for (int i = 0; i < selectors.size(); i++) {
+// Selector value = selectors.get(i);
+ String label = selectors.get(i);
+ classCombo.add(/*value.getValue()*/ label);
+
+ }
+ /*
+ *
+ */
+ if (currentClassStyle != null) {
+ classCombo.setText(currentClassStyle);
+ } else {
+ classCombo.select(0);
+ }
+ classCombo.setToolTipText(cssModel.getCSSText(currentClassStyle));
+
+ styleComposite.setShowPreviewTab(true);
+ styleComposite.setCSSModel(cssModel);
+ // update style composite component with the values from new CSS file
+ if (updateCSSModel) {
+ updateStyleComposite();
+ }
+ styleComposite.initPreview(cssModel);
+ }
+ }
+
+ /**
+ * This method takes affect to OK button when dialog is opened in "dialog" mode and not in "wizard".
+ * In case of "wizard" mode OK button is not available.
+ */
+ private void updateOKButtonState() {
+ Button okButton = getButton(IDialogConstants.OK_ID);
+ if (okButton != null) {
+ if (findMostSevere()!=null&&findMostSevere().getSeverity()==IStatus.ERROR) {
+ okButton.setEnabled(false);
+ } else {
+ okButton.setEnabled(true);
+ }
+ }
+ }
+
+ /**
+ * Method is used to create browser component to display preview HTML.
+ */
+ private void createBrowserComponent() {
+ GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
+ browser = new Browser(browserContainer, SWT.BORDER | SWT.MOZILLA);
+ browser.setText(getTextForBrowser());
+ browser.addMouseListener(new MouseAdapter() {
+ public void mouseDoubleClick(MouseEvent e) {
+ if (e.widget == browser) {
+ browser.removeMouseListener(this);
+ browser.dispose();
+ // create Text area component instead of HTML Browser
+ GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
+// textBrowser = new Text(browserContainer, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
+ textBrowser = new Text(browserContainer, SWT.NONE | SWT.H_SCROLL);
+ textBrowser.setText(previewBrowserValue);
+ textBrowser.addFocusListener(new FocusAdapter() {
+ public void focusLost(FocusEvent e) {
+ if (e.widget == textBrowser) {
+ String text = textBrowser.getText();
+ if (text == null || text.equals(Constants.EMPTY)) {
+ previewBrowserValue = JstUIMessages.DEFAULT_TEXT_FOR_BROWSER_PREVIEW;
+ } else {
+ previewBrowserValue = text;
+ }
+ textBrowser.dispose();
+ // create Browse component instead of text area
+ createBrowserComponent();
+ }
+ browserContainer.layout();
+ }
+ });
+ textBrowser.setLayoutData(gridData);
+ textBrowser.setEditable(true);
+ textBrowser.setFocus();
+ }
+ browserContainer.layout();
+ }
+ });
+ browser.setLayoutData(gridData);
+ }
+
+ /**
+ * Update style composite component in accordance with the attributes of selected CSS selector.
+ */
+ private void updateStyleComposite() {
+ String style = cssModel.getStyle(currentClassStyle);
+ styleComposite.recreateStyleComposite(style, currentClassStyle);
+ }
+
+ /**
+ * Method is used to build html body that is appropriate to browse.
+ *
+ * @return String html text representation
+ */
+ private String getTextForBrowser() {
+ String styleForSpan = Constants.EMPTY;
+ Set<String> keySet = styleAttributes.keySet();
+ for (String key : keySet) {
+ styleForSpan += (key + Constants.COLON + styleAttributes.getAttribute(key) + Constants.SEMICOLON);
+ }
+ String html = Constants.OPEN_DIV_TAG + styleForSpan + "\">" + previewBrowserValue + Constants.CLOSE_DIV_TAG; //$NON-NLS-1$
+
+ return html;
+ }
+
+ /**
+ * Create container that take up 2 cells and contains fontSizeCombo and extFontSizeCombo elements.
+ */
+ private Composite getCompositeElement(Composite parent) {
+ GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
+ GridLayout gridLayoutTmp = new GridLayout();
+ gridLayoutTmp.marginHeight = 0;
+ gridLayoutTmp.marginWidth = 0;
+ Composite classComposite = new Composite(parent, SWT.FILL);
+ classComposite.setLayout(gridLayoutTmp);
+ classComposite.setLayoutData(gridData);
+
+ return classComposite;
+ }
+
+ public void releaseResources() {
+
+ if (cssModel != null){
+ cssModel.releaseModel();
+ cssModel = null;
+ }
+ }
+
+ /**
+ * Method should be called in case of dialog closure operation.
+ */
+ public void saveChanges(boolean close) {
+ styleComposite.updateStyle();
+ cssModel.setCSS(currentClassStyle, styleAttributes);
+ cssModel.saveModel();
+ }
+
+ /**
+ * Gets current selected style class value.
+ *
+ * @return selector name
+ */
+ public String getSelectorName() {
+ return Util.formatCSSSelectorToStyleClassView(currentClassStyle);
+ }
+
+ /**
+ * Method for setting title for dialog
+ *
+ * @param newShell Shell object
+ * @see org.eclipse.jface.window.Window#configureShell(Shell)
+ */
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText(JstUIMessages.CSS_STYLE_CLASS_EDITOR_TITLE);
+ }
+
+ /**
+ * This method close the dialog.
+ *
+ * @return true if dialog was closed, false - otherwise
+ */
+ public boolean closeDialog() {
+ setReturnCode(Window.CANCEL);
+ return close();
+ }
+
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#close()
+ */
+ @Override
+ public boolean close() {
+ int code = getReturnCode();
+ switch (code) {
+ case OK:
+ if (styleChanged || classCombo.indexOf(currentClassStyle) == -1) {
+ saveChanges(true);
+ }
+ break;
+ case CANCEL:
+ default:
+ // make some closure operation
+ }
+ releaseResources();
+ return super.close();
+ }
+
+ /**
+ * Add MessageDialogListener object.
+ *
+ * @param listener MessageDialogListener object to be added
+ */
+ public void addMessageDialogListener(MessageDialogListener listener) {
+ errorListeners.add(listener);
+ }
+
+ /**
+ * Method is used to notify all subscribed listeners about possible any errors on the page.
+ */
+ private void notifyListeners(Object source, IStatus operationStatus) {
+ MessageDialogEvent event = new MessageDialogEvent(source, operationStatus);
+ for (MessageDialogListener listener : errorListeners) {
+ listener.throwMessage(event);
+ }
+ }
+
+ /**
+ * Method return the most serious error occurs on the page and that should be displayed.
+ *
+ * @return IStatus object
+ */
+ private IStatus findMostSevere() {
+ if (filePathStatus.matches(IStatus.ERROR)) {
+ return filePathStatus;
+ }
+ if (classNameStatus.matches(IStatus.ERROR)) {
+ return classNameStatus;
+ }
+ if(cssValueStatus!=null && cssValueStatus.matches(IStatus.ERROR)){
+ return cssValueStatus;
+ }
+ if(cssValueStatus!=null && cssValueStatus.matches(IStatus.ERROR)){
+ return cssValueStatus;
+ } else {
+ return classNameStatus;
+ }
+
+ }
+
+ /**
+ * Applies the status to the status line of a dialog page.
+ */
+ private void applyToStatusLine(IStatus status) {
+ if (!callFromWizard) {
+ String message= status.getMessage();
+ if (message.length() == 0) {
+ message = null;
+ }
+ switch (status.getSeverity()) {
+ case IStatus.OK:
+ setErrorMessage(null);
+ setMessage(message);
+ break;
+ case IStatus.WARNING:
+ setErrorMessage(null);
+ setMessage(message, WizardPage.WARNING);
+ break;
+ case IStatus.INFO:
+ setErrorMessage(null);
+ setMessage(message, WizardPage.INFORMATION);
+ break;
+ default:
+ setErrorMessage(message);
+ setMessage(null);
+ break;
+ }
+ }
+ }
+
+ public void reinit(){
+ releaseResources();
+ initCSSModel(currentFile, true,true);
+ }
+
+ public void setCurrentFile(IFile currentFile) {
+ this.currentFile = currentFile;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleListener#styleChanged(org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleEvent)
+ */
+ public void styleChanged(ChangeStyleEvent event) {
+ if (!this.styleAttributes.isValid()) {
+ cssValueStatus = new Status(IStatus.ERROR, notUsed, 0,
+ JstUIMessages.CSS_INVALID_STYLE_PROPERTY, null);
+ notifyListeners(event, cssValueStatus);
+ addNewClass.setEnabled(false);
+ } else {
+ cssValueStatus = null;
+ addNewClass.setEnabled(true);
+ notifyListeners(event, new Status(IStatus.OK, notUsed, 0,
+ JstUIMessages.CSS_STYLE_CLASS_EDITOR_DESCRIPTION, null));
+ }
+ if (cssValueStatus != null && classCombo != null) {
+ classCombo.setEnabled(false);
+ } else {
+ classCombo.setEnabled(true);
+
+ }
+ updateApplyButton(true);
+ updateOKButtonState();
+ applyToStatusLine(findMostSevere());
+ }
+ /**
+ * Update upplyButtonState
+ * @param available
+ */
+ private void updateApplyButton(boolean enabled){
+ if(cssValueStatus!=null
+ &&cssValueStatus.matches(IStatus.ERROR)) {
+ applyButton.setEnabled(false);
+ }else {
+ applyButton.setEnabled(enabled);
+ }
+
+ }
+}
Modified: branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSModel.java
===================================================================
--- branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSModel.java 2009-03-19 09:19:53 UTC (rev 14262)
+++ branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSModel.java 2009-03-19 13:36:13 UTC (rev 14263)
@@ -1,432 +1,430 @@
-/*******************************************************************************
- * 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.outline.cssdialog.common;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import org.eclipse.core.filebuffers.FileBuffers;
-import org.eclipse.core.filebuffers.IFileBuffer;
-import org.eclipse.core.filebuffers.LocationKind;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentExtension3;
-import org.eclipse.jface.text.IDocumentPartitioner;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.wst.css.core.internal.format.FormatProcessorCSS;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet;
-import org.eclipse.wst.css.core.internal.text.StructuredTextPartitionerForCSS;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-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.exceptions.ResourceInUse;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredPartitioning;
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
-import org.w3c.dom.css.CSSRuleList;
-import org.w3c.dom.css.CSSStyleDeclaration;
-import org.w3c.dom.css.CSSStyleRule;
-import org.w3c.dom.css.CSSStyleSheet;
-
-/**
- * CSS class model.
- *
- *
- */
-public class CSSModel {
-
- private static String startBraces = "{"; //$NON-NLS-1$
- private static String endBraces = "}"; //$NON-NLS-1$
-
- private FormatProcessorCSS formatProcessorCSS = null;
- private IStructuredModel model = null;
- private IFile styleFile = null;
-
- private CSSStyleSheet styleSheet = null;
- private ICSSStyleSheet eclipseStyleSheet = null;
- private String COPY_SUFFIX = "_copy";
- private boolean copy = false;
-
-
- /**
- * Constructor.
- *
- * @param styleFile CSS style class that should initialize CSS model
- */
- public CSSModel(IFile styleFile) {
- init(styleFile);
- }
-
- public void init(IFile styleFile) {
- try {
- this.styleFile = styleFile;
- if (model != null) {
- releaseModel();
- }
- copy = false;
- formatProcessorCSS = new FormatProcessorCSS();
- IModelManager modelManager = StructuredModelManager.getModelManager();
- model = modelManager.getExistingModelForEdit(styleFile);
-
-
- if (model == null)
- model = modelManager.getModelForEdit(styleFile);
- else {
-
- copy = true;
- // copy the model
- model = modelManager.copyModelForEdit(model.getId(), model
- .getId()
- + COPY_SUFFIX);
-
- // set the correct location
- model.setBaseLocation(styleFile.getLocation().toString());
-
- // some steps to prepare document ( it is necessary to correct
- // work of highlight in preview tab )
- IDocumentPartitioner partitioner = new StructuredTextPartitionerForCSS();
- ((IDocumentExtension3) model.getStructuredDocument())
- .setDocumentPartitioner(
- IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING,
- partitioner);
- partitioner.connect(model.getStructuredDocument());
-
- }
- if (model instanceof ICSSModel) {
- ICSSModel cssModel = (ICSSModel) model;
- ICSSDocument document = cssModel.getDocument();
- if (document instanceof CSSStyleSheet) {
- styleSheet = (CSSStyleSheet) document;
- }
- if (document instanceof ICSSStyleSheet) {
- eclipseStyleSheet = (ICSSStyleSheet) document;
- }
-
-
- }
- } catch (IOException e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- } catch (CoreException e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- } catch (ResourceInUse e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- }
- }
-
- /**
- * Method is used to select area that corresponds to specific selector.
- *
- * @param selector the selector that should be selected in editor area
- * @param index if CSS file contains more then one elements with the same selector name,
- * then index is serial number of this selector
- */
- public IndexedRegion getSelectorRegion(String selector, int index) {
- //FIXED by sdzmitrovich - JBIDE-3148
-// if (eclipseStyleSheet != null) {
-// if (selector != null && !selector.equals(Constants.EMPTY)) {
-// ICSSStyleRule styleRule = Util.getSelector(eclipseStyleSheet, selector, index);
-// if (styleRule != null) {
-// if (styleRule instanceof IndexedRegion) {
-// return (IndexedRegion) styleRule;
-// }
-// }
-// }
-// }
-
- if ( selector != null) {
- CSSStyleRule rule = getRulesMapping().get(selector);
- if (rule != null)
- if (rule instanceof IndexedRegion) {
- return (IndexedRegion) rule;
- }
-
- }
- return null;
- }
-
-
- public List<String> getSelectorLabels() {
-
- List<String> selectorLabels;
-
- selectorLabels = new ArrayList<String>(getRulesMapping().keySet());
-
- Collections.sort(selectorLabels);
-
- return selectorLabels;
- }
-
- /**
- * Gets CSS attributes for the given selector in string representation.
- *
- * @param selector CSS selector value
- * @return CSS attributes string representation
- */
- public String getCSSText(String selector) {
- //FIXED by sdzmitrovich - JBIDE-3148
-// if (styleSheet != null && selector != null) {
-// CSSRuleList list = styleSheet.getCssRules();
-//
-// if (list != null) {
-// for (int i = 0; i < list.getLength(); i++) {
-// if (list.item(i) instanceof CSSStyleRule &&
-// ((CSSStyleRule) list.item(i)).getSelectorText().equals(selector)) {
-// return ((CSSStyleRule) list.item(i)).getCssText();
-// }
-// }
-// }
-// }
- if ( selector != null) {
- CSSStyleRule rule = getRulesMapping().get(selector);
- if (rule != null)
- return rule.getCssText();
-
- }
-
- return null;
- }
-
- /**
- * Get style by selectorName
- *
- * @param selectorName
- * @return style
- */
- public String getStyle(String selectorName) {
- //FIXED by sdzmitrovich - JBIDE-3148
-// if (styleSheet != null) {
-// CSSRuleList list = styleSheet.getCssRules();
-//
-// if (list != null) {
-// for (int i = 0; i < list.getLength(); i++) {
-// if (list.item(i) instanceof CSSStyleRule &&
-// ((CSSStyleRule) list.item(i)).getSelectorText().equals(selectorName)) {
-// return ((CSSStyleRule) list.item(i)).getStyle().getCssText();
-// }
-// }
-// }
-// }
- if (selectorName != null) {
- CSSStyleRule rule = getRulesMapping().get(selectorName);
- if (rule != null)
- return rule.getStyle().getCssText();
-
- }
-
- return null;
- }
-
- /**
- * Sets CSS style for the given selector.
- *
- * @param selector CSS selector value
- * @param styleAttribute the style to be set
- */
- public void setCSS(String selector, StyleAttributes styleAttributes) {
- if (styleSheet != null && selector != null && !selector.equals(Constants.EMPTY)) {
- CSSRuleList list = styleSheet.getCssRules();
- //FIXED by sdzmitrovich - JBIDE-3148
-// if (list != null) {
-// // check if selector passed by parameter already exists in CSS
-// for (int i = 0; i < list.getLength(); i++) {
-// if (list.item(i) instanceof CSSStyleRule &&
-// ((CSSStyleRule) list.item(i)).getSelectorText().equals(selector)) {
-//
-// CSSStyleRule rule = (CSSStyleRule) list.item(i);
-// styleSheet.deleteRule(i);
-//
-// i = styleSheet.insertRule(selector + startBraces + styleAttributes.getStyle() + endBraces, i);
-// rule = (CSSStyleRule) list.item(i);
-// CSSStyleDeclaration declaration = rule.getStyle();
-// // set properties
-// Set<Entry<String, String>> set = styleAttributes.entrySet();
-// for (Map.Entry<String, String> me : set) {
-// declaration.setProperty(me.getKey(), me.getValue(), Constants.EMPTY);
-// }
-//
-// formatProcessorCSS.formatModel(model);
-// return;
-// }
-// }
-// // insert NEW selector to style sheet
-// styleSheet.insertRule(selector + startBraces + styleAttributes.getStyle() + endBraces, list.getLength());
-// formatProcessorCSS.formatModel(model);
- CSSStyleRule rule = getRulesMapping().get(selector);
- if (rule == null) {
- styleSheet.insertRule(selector + startBraces
- + styleAttributes.getStyle() + endBraces, list
- .getLength());
- } else {
-
- CSSStyleDeclaration declaration = rule.getStyle();
- // set properties
- Set<Entry<String, String>> set = styleAttributes.entrySet();
-
- if ((set.size() == 0) && (declaration.getLength()>0))
- declaration.setCssText(Constants.EMPTY);
- else
- for (Map.Entry<String, String> me : set) {
- declaration.setProperty(me.getKey(), me.getValue(),
- Constants.EMPTY);
- }
- }
-
- formatProcessorCSS.formatModel(model);
-
- }
- }
-
- /**
- * Gets file associated with current model.
- *
- * @return the styleFile
- */
- public IFile getStyleFile() {
- return this.styleFile;
- }
-
- /**
- * Release CSS model correctly from editing.
- */
- public void releaseModel() {
- IModelManager modelManager = StructuredModelManager.getModelManager();
- if (model != null && !modelManager.isShared(model.getId()))
- model.releaseFromEdit();
- model = null;
- }
-
- /**
- * Save model. Associate file will be saved automatically.
- */
- public void saveModel() {
- try {
-
- /*
- * it is necessary not to dialog appears when "dirty" css file is
- * being saved ( test case : 1) open css file 2) make same changes
- * 3) open css dialog 4) make some changes 5)press ok )
- *
- *
- * it is necessary to distinguish real model from copy. For real
- * model next step reject all changes
- */
- if (copy) {
- IFileBuffer buffer = FileBuffers.getTextFileBufferManager()
- .getFileBuffer(styleFile.getFullPath(),
- LocationKind.NORMALIZE);
- buffer.setDirty(false);
- }
-
- model.save();
- } catch (IOException e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- } catch (CoreException e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- }
- }
-
- /**
- * get mapping key is label ( label = class name + sequence number of such
- * css class ) value is CSSStyleRule
- *
- * now rule mapping is generated always ... keeping of ruleMapping is more
- * right but it demands more complex synchronization data
- *
- */
- private Map<String, CSSStyleRule> getRulesMapping() {
-
- Map<String, CSSStyleRule> rulesMapping = new HashMap<String, CSSStyleRule>();
- if (styleSheet != null) {
- CSSRuleList list = styleSheet.getCssRules();
-
- Map<String, Integer> frequencyMap = new HashMap<String, Integer>();
-
- if (list != null) {
- for (int i = 0; i < list.getLength(); i++) {
- if (list.item(i) instanceof CSSStyleRule) {
-
- CSSStyleRule rule = ((CSSStyleRule) list.item(i));
-
- Integer freq = frequencyMap.get(rule.getSelectorText());
-
- freq = freq == null ? 1 : freq + 1;
-
- frequencyMap.put(rule.getSelectorText(), freq);
-
- String ruleLabel = rule.getSelectorText()
- + (freq > 1 ? Constants.START_BRACKET + freq
- + Constants.END_BRACKET
- : Constants.EMPTY);
-
- rulesMapping.put(ruleLabel, rule);
-
- }
- }
- }
-
- }
-
- return rulesMapping;
- }
-
- public IDocument getStructuredDocument() {
- return model.getStructuredDocument();
- }
-
- public void reload() {
- try {
- if(model.isDirty()) {
- model.reload(new FileInputStream(styleFile.getLocation().toFile()));
- }
- } catch (Exception e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- }
-
- }
-
- public String getSelectorByPosition(Point selectionInFile) {
-
- ICSSNode node = (ICSSNode) model.getIndexedRegion(selectionInFile.x);
-
- while (node != null) {
-
- if (node.getNodeType() == ICSSNode.STYLERULE_NODE) {
- break;
- } else if (node.getNodeType() == ICSSNode.STYLESHEET_NODE) {
- node = ((ICSSStyleSheet) node).getFirstChild();
- break;
- }
-
- node = node.getParentNode();
- }
-
- Object rules= getRulesMapping();
- if (node != null)
- for (Entry<String, CSSStyleRule> rule : getRulesMapping()
- .entrySet()) {
- if (node.equals(rule.getValue()))
- return rule.getKey();
- }
- 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.outline.cssdialog.common;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.IFileBuffer;
+import org.eclipse.core.filebuffers.LocationKind;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentExtension3;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.wst.css.core.internal.format.FormatProcessorCSS;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet;
+import org.eclipse.wst.css.core.internal.text.StructuredTextPartitionerForCSS;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+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.exceptions.ResourceInUse;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredPartitioning;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
+import org.w3c.dom.css.CSSRuleList;
+import org.w3c.dom.css.CSSStyleDeclaration;
+import org.w3c.dom.css.CSSStyleRule;
+import org.w3c.dom.css.CSSStyleSheet;
+
+/**
+ * CSS class model.
+ *
+ *
+ */
+public class CSSModel {
+
+ private static String startBraces = "{"; //$NON-NLS-1$
+ private static String endBraces = "}"; //$NON-NLS-1$
+
+ private FormatProcessorCSS formatProcessorCSS = null;
+ private IStructuredModel model = null;
+ private IFile styleFile = null;
+
+ private CSSStyleSheet styleSheet = null;
+ private ICSSStyleSheet eclipseStyleSheet = null;
+ private String COPY_SUFFIX = "_copy";
+ private boolean copy = false;
+
+
+ /**
+ * Constructor.
+ *
+ * @param styleFile CSS style class that should initialize CSS model
+ */
+ public CSSModel(IFile styleFile) {
+ init(styleFile);
+ }
+
+ public void init(IFile styleFile) {
+ try {
+ this.styleFile = styleFile;
+ if (model != null) {
+ releaseModel();
+ }
+ copy = false;
+ formatProcessorCSS = new FormatProcessorCSS();
+ IModelManager modelManager = StructuredModelManager.getModelManager();
+ model = modelManager.getExistingModelForEdit(styleFile);
+
+
+ if (model == null)
+ model = modelManager.getModelForEdit(styleFile);
+ else {
+
+ copy = true;
+ // copy the model
+ model = modelManager.copyModelForEdit(model.getId(), model
+ .getId()
+ + COPY_SUFFIX);
+
+ // set the correct location
+ model.setBaseLocation(styleFile.getLocation().toString());
+
+ // some steps to prepare document ( it is necessary to correct
+ // work of highlight in preview tab )
+ IDocumentPartitioner partitioner = new StructuredTextPartitionerForCSS();
+ ((IDocumentExtension3) model.getStructuredDocument())
+ .setDocumentPartitioner(
+ IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING,
+ partitioner);
+ partitioner.connect(model.getStructuredDocument());
+
+ }
+ if (model instanceof ICSSModel) {
+ ICSSModel cssModel = (ICSSModel) model;
+ ICSSDocument document = cssModel.getDocument();
+ if (document instanceof CSSStyleSheet) {
+ styleSheet = (CSSStyleSheet) document;
+ }
+ if (document instanceof ICSSStyleSheet) {
+ eclipseStyleSheet = (ICSSStyleSheet) document;
+ }
+
+
+ }
+ } catch (IOException e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ } catch (CoreException e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ } catch (ResourceInUse e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ }
+ }
+
+ /**
+ * Method is used to select area that corresponds to specific selector.
+ *
+ * @param selector the selector that should be selected in editor area
+ * @param index if CSS file contains more then one elements with the same selector name,
+ * then index is serial number of this selector
+ */
+ public IndexedRegion getSelectorRegion(String selector, int index) {
+ //FIXED by sdzmitrovich - JBIDE-3148
+// if (eclipseStyleSheet != null) {
+// if (selector != null && !selector.equals(Constants.EMPTY)) {
+// ICSSStyleRule styleRule = Util.getSelector(eclipseStyleSheet, selector, index);
+// if (styleRule != null) {
+// if (styleRule instanceof IndexedRegion) {
+// return (IndexedRegion) styleRule;
+// }
+// }
+// }
+// }
+
+ if ( selector != null) {
+ CSSStyleRule rule = getRulesMapping().get(selector);
+ if (rule != null)
+ if (rule instanceof IndexedRegion) {
+ return (IndexedRegion) rule;
+ }
+
+ }
+ return null;
+ }
+
+
+ public List<String> getSelectorLabels() {
+
+ List<String> selectorLabels;
+
+ selectorLabels = new ArrayList<String>(getRulesMapping().keySet());
+
+ Collections.sort(selectorLabels);
+
+ return selectorLabels;
+ }
+
+ /**
+ * Gets CSS attributes for the given selector in string representation.
+ *
+ * @param selector CSS selector value
+ * @return CSS attributes string representation
+ */
+ public String getCSSText(String selector) {
+ //FIXED by sdzmitrovich - JBIDE-3148
+// if (styleSheet != null && selector != null) {
+// CSSRuleList list = styleSheet.getCssRules();
+//
+// if (list != null) {
+// for (int i = 0; i < list.getLength(); i++) {
+// if (list.item(i) instanceof CSSStyleRule &&
+// ((CSSStyleRule) list.item(i)).getSelectorText().equals(selector)) {
+// return ((CSSStyleRule) list.item(i)).getCssText();
+// }
+// }
+// }
+// }
+ if ( selector != null) {
+ CSSStyleRule rule = getRulesMapping().get(selector);
+ if (rule != null)
+ return rule.getCssText();
+
+ }
+
+ return null;
+ }
+
+ /**
+ * Get style by selectorName
+ *
+ * @param selectorName
+ * @return style
+ */
+ public String getStyle(String selectorName) {
+ //FIXED by sdzmitrovich - JBIDE-3148
+// if (styleSheet != null) {
+// CSSRuleList list = styleSheet.getCssRules();
+//
+// if (list != null) {
+// for (int i = 0; i < list.getLength(); i++) {
+// if (list.item(i) instanceof CSSStyleRule &&
+// ((CSSStyleRule) list.item(i)).getSelectorText().equals(selectorName)) {
+// return ((CSSStyleRule) list.item(i)).getStyle().getCssText();
+// }
+// }
+// }
+// }
+ if (selectorName != null) {
+ CSSStyleRule rule = getRulesMapping().get(selectorName);
+ if (rule != null)
+ return rule.getStyle().getCssText();
+
+ }
+
+ return null;
+ }
+
+ /**
+ * Sets CSS style for the given selector.
+ *
+ * @param selector CSS selector value
+ * @param styleAttribute the style to be set
+ */
+ public void setCSS(String selector, StyleAttributes styleAttributes) {
+ if (styleSheet != null && selector != null && !selector.equals(Constants.EMPTY)) {
+ CSSRuleList list = styleSheet.getCssRules();
+ //FIXED by sdzmitrovich - JBIDE-3148
+// if (list != null) {
+// // check if selector passed by parameter already exists in CSS
+// for (int i = 0; i < list.getLength(); i++) {
+// if (list.item(i) instanceof CSSStyleRule &&
+// ((CSSStyleRule) list.item(i)).getSelectorText().equals(selector)) {
+//
+// CSSStyleRule rule = (CSSStyleRule) list.item(i);
+// styleSheet.deleteRule(i);
+//
+// i = styleSheet.insertRule(selector + startBraces + styleAttributes.getStyle() + endBraces, i);
+// rule = (CSSStyleRule) list.item(i);
+// CSSStyleDeclaration declaration = rule.getStyle();
+// // set properties
+// Set<Entry<String, String>> set = styleAttributes.entrySet();
+// for (Map.Entry<String, String> me : set) {
+// declaration.setProperty(me.getKey(), me.getValue(), Constants.EMPTY);
+// }
+//
+// formatProcessorCSS.formatModel(model);
+// return;
+// }
+// }
+// // insert NEW selector to style sheet
+// styleSheet.insertRule(selector + startBraces + styleAttributes.getStyle() + endBraces, list.getLength());
+// formatProcessorCSS.formatModel(model);
+ CSSStyleRule rule = getRulesMapping().get(selector);
+ if (rule == null) {
+ rule = (CSSStyleRule)((ICSSDocument)styleSheet).createCSSRule(
+ selector + startBraces + styleAttributes.getStyle() + endBraces);
+ ((ICSSStyleSheet)styleSheet).appendRule(rule);
+ } else {
+
+ CSSStyleDeclaration declaration = rule.getStyle();
+ // set properties
+ Set<Entry<String, String>> set = styleAttributes.entrySet();
+
+ if ((set.size() == 0) && (declaration.getLength()>0))
+ declaration.setCssText(Constants.EMPTY);
+ else
+ for (Map.Entry<String, String> me : set) {
+ declaration.setProperty(me.getKey(), me.getValue(),
+ Constants.EMPTY);
+ }
+ }
+ }
+ }
+
+ /**
+ * Gets file associated with current model.
+ *
+ * @return the styleFile
+ */
+ public IFile getStyleFile() {
+ return this.styleFile;
+ }
+
+ /**
+ * Release CSS model correctly from editing.
+ */
+ public void releaseModel() {
+ IModelManager modelManager = StructuredModelManager.getModelManager();
+ if (model != null && !modelManager.isShared(model.getId()))
+ model.releaseFromEdit();
+ model = null;
+ }
+
+ /**
+ * Save model. Associate file will be saved automatically.
+ */
+ public void saveModel() {
+ try {
+
+ /*
+ * it is necessary not to dialog appears when "dirty" css file is
+ * being saved ( test case : 1) open css file 2) make same changes
+ * 3) open css dialog 4) make some changes 5)press ok )
+ *
+ *
+ * it is necessary to distinguish real model from copy. For real
+ * model next step reject all changes
+ */
+ if (copy) {
+ IFileBuffer buffer = FileBuffers.getTextFileBufferManager()
+ .getFileBuffer(styleFile.getFullPath(),
+ LocationKind.NORMALIZE);
+ buffer.setDirty(false);
+ }
+
+ model.save();
+ } catch (IOException e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ } catch (CoreException e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ }
+ }
+
+ /**
+ * get mapping key is label ( label = class name + sequence number of such
+ * css class ) value is CSSStyleRule
+ *
+ * now rule mapping is generated always ... keeping of ruleMapping is more
+ * right but it demands more complex synchronization data
+ *
+ */
+ private Map<String, CSSStyleRule> getRulesMapping() {
+
+ Map<String, CSSStyleRule> rulesMapping = new HashMap<String, CSSStyleRule>();
+ if (styleSheet != null) {
+ CSSRuleList list = styleSheet.getCssRules();
+
+ Map<String, Integer> frequencyMap = new HashMap<String, Integer>();
+
+ if (list != null) {
+ for (int i = 0; i < list.getLength(); i++) {
+ if (list.item(i) instanceof CSSStyleRule) {
+
+ CSSStyleRule rule = ((CSSStyleRule) list.item(i));
+
+ Integer freq = frequencyMap.get(rule.getSelectorText());
+
+ freq = freq == null ? 1 : freq + 1;
+
+ frequencyMap.put(rule.getSelectorText(), freq);
+
+ String ruleLabel = rule.getSelectorText()
+ + (freq > 1 ? Constants.START_BRACKET + freq
+ + Constants.END_BRACKET
+ : Constants.EMPTY);
+
+ rulesMapping.put(ruleLabel, rule);
+
+ }
+ }
+ }
+
+ }
+
+ return rulesMapping;
+ }
+
+ public IDocument getStructuredDocument() {
+ return model.getStructuredDocument();
+ }
+
+ public void reload() {
+ try {
+ if(model.isDirty()) {
+ model.reload(new FileInputStream(styleFile.getLocation().toFile()));
+ }
+ } catch (Exception e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ }
+
+ }
+
+ public String getSelectorByPosition(Point selectionInFile) {
+
+ ICSSNode node = (ICSSNode) model.getIndexedRegion(selectionInFile.x);
+
+ while (node != null) {
+
+ if (node.getNodeType() == ICSSNode.STYLERULE_NODE) {
+ break;
+ } else if (node.getNodeType() == ICSSNode.STYLESHEET_NODE) {
+ node = ((ICSSStyleSheet) node).getFirstChild();
+ break;
+ }
+
+ node = node.getParentNode();
+ }
+
+ Object rules= getRulesMapping();
+ if (node != null)
+ for (Entry<String, CSSStyleRule> rule : getRulesMapping()
+ .entrySet()) {
+ if (node.equals(rule.getValue()))
+ return rule.getKey();
+ }
+ return null;
+ }
+}
Modified: branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSValidator.java
===================================================================
--- branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSValidator.java 2009-03-19 09:19:53 UTC (rev 14262)
+++ branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSValidator.java 2009-03-19 13:36:13 UTC (rev 14263)
@@ -1,135 +1,159 @@
-/*******************************************************************************
- * Copyright (c) 2007-2009 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.outline.cssdialog.common;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.w3c.dom.css.CSSStyleDeclaration;
-import org.w3c.dom.css.CSSStyleRule;
-import org.w3c.dom.css.CSSStyleSheet;
-
-/**
- * CSS Validator
- *
- * @author yradtsevich
- *
- */
-public class CSSValidator {
- // FIXME: this hard-coded string have to be replaced by reference
- private static final String CSS_CONTENT_TYPE_IDENTIFIER = "org.eclipse.wst.css.core.csssource"; //$NON-NLS-1$
- private final CSSStyleSheet validatingCSS;
- private final LogHacker logHacker = new LogHacker();
-
- @SuppressWarnings("restriction")
- public CSSValidator() {
- IModelManager modelManager = StructuredModelManager.getModelManager();
- ICSSModel validatingModel = (ICSSModel) modelManager.createUnManagedStructuredModelFor(CSS_CONTENT_TYPE_IDENTIFIER);
-
- validatingCSS = (CSSStyleSheet) validatingModel.getDocument();
- }
-
- private void cleanValidatingCSS() {
- int ruleNumber;
-
- while ((ruleNumber = validatingCSS.getCssRules().getLength()) > 0) {
- validatingCSS.deleteRule(ruleNumber - 1);
- }
- }
-
- /**
- * Validates value of a CSS attribute.
- *
- * @param value the
- * @return {@code true} if the attribute is valid, {@code false} otherwise
- */
- public boolean isValidValue(String value) {
- logHacker.disableLogging();
- boolean valid = true;
- try {
- validatingCSS.insertRule(".testSelector {}", 0); //$NON-NLS-1$
- CSSStyleRule cssRule = ((CSSStyleRule) validatingCSS.getCssRules().item(0));
- CSSStyleDeclaration declaration = cssRule.getStyle();
- declaration.setProperty("background", value, Constants.EMPTY); //$NON-NLS-1$
- } catch (Throwable e) {
- valid = false;
- } finally {
- logHacker.enableLogging();
- cleanValidatingCSS();
- }
-
- return valid;
- }
-
- /**
- * Validates CSS selector value.
- *
- * @param selector the selector value
- * @return {@code true} if the selector is valid, {@code false} otherwise
- */
- public boolean isValidSelector(String selector) {
- boolean valid = true;
- try {
- validatingCSS.insertRule(selector + " {}", 0); //$NON-NLS-1$
- } catch (Throwable e) {
- valid = false;
- } finally {
- cleanValidatingCSS();
- }
-
- return valid;
- }
-
- /**
- * Gives opportunity to delete all loggers from {@link org.eclipse.core.internal.runtime.RuntimeLog}
- *
- * @author yradtsevich
- *
- */
- private class LogHacker {
- private Field logListeners = null;
- private Object oldValue = null;
-
- public LogHacker() {
- try {
- logListeners = org.eclipse.core.internal.runtime.RuntimeLog.class.getDeclaredField("logListeners");
- logListeners.setAccessible(true);
- } catch (Throwable e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- }
-
- public void disableLogging() {
- try {
- oldValue = logListeners.get(null);
- logListeners.set(null, new ArrayList(0));
- } catch (Throwable e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- }
-
- public void enableLogging() {
- try {
- if (oldValue != null) {
- logListeners.set(null, oldValue);
- }
- } catch (Throwable e) {
- JspEditorPlugin.getPluginLog().logError(e);
- } finally {
- oldValue = null;
- }
- }
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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.outline.cssdialog.common;
+
+import java.lang.ref.Reference;
+import java.lang.ref.SoftReference;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.w3c.dom.css.CSSRuleList;
+import org.w3c.dom.css.CSSStyleDeclaration;
+import org.w3c.dom.css.CSSStyleRule;
+import org.w3c.dom.css.CSSStyleSheet;
+
+/**
+ * CSS Validator
+ *
+ * @author yradtsevich
+ *
+ */
+@SuppressWarnings("restriction")
+public class CSSValidator {
+ // FIXME: this hard-coded string have to be replaced by reference
+ private static final String CSS_CONTENT_TYPE_IDENTIFIER = "org.eclipse.wst.css.core.csssource"; //$NON-NLS-1$
+ private final CSSStyleSheet validatingCSS;
+ private final IStructuredDocument validatingDocument;
+ private final LogHacker logHacker = new LogHacker();
+ private static Reference<CSSValidator> instanceCache;
+
+ public static CSSValidator getInstance() {
+ CSSValidator instance = null;
+ if (instanceCache != null) {
+ instance = instanceCache.get();
+ }
+ if (instance == null) {
+ instance = new CSSValidator();
+ instanceCache = new SoftReference<CSSValidator>(instance);
+ }
+ return instance;
+ }
+
+ private CSSValidator() {
+ IModelManager modelManager = StructuredModelManager.getModelManager();
+ ICSSModel validatingModel = (ICSSModel) modelManager
+ .createUnManagedStructuredModelFor(CSS_CONTENT_TYPE_IDENTIFIER);
+ validatingDocument = validatingModel.getStructuredDocument();
+ validatingCSS = (CSSStyleSheet) validatingModel.getDocument();
+ }
+
+ private void cleanValidatingDocument() {
+ validatingDocument.set(""); //$NON-NLS-1$
+ }
+
+ /**
+ * Validates value of a CSS attribute.
+ *
+ * @param value the value of a CSS attribute
+ * @return {@code true} if the attribute is valid, {@code false} otherwise
+ */
+ public boolean isValidValue(String value) {
+ logHacker.disableLogging();
+ boolean valid = true;
+ try {
+ validatingCSS.insertRule(".testSelector {}", 0); //$NON-NLS-1$
+ CSSStyleRule cssRule = ((CSSStyleRule) validatingCSS.getCssRules().item(0));
+ CSSStyleDeclaration declaration = cssRule.getStyle();
+ declaration.setProperty("background", value, Constants.EMPTY); //$NON-NLS-1$
+ } catch (Throwable e) {
+ valid = false;
+ } finally {
+ logHacker.enableLogging();
+ cleanValidatingDocument();
+ }
+
+ return valid;
+ }
+
+ /**
+ * Validates CSS selector value.
+ *
+ * @param selector the selector value
+ * @return {@code true} if the selector is valid, {@code false} otherwise
+ */
+ public boolean isValidSelector(String selector) {
+ validatingDocument.set(selector + "{}"); //$NON-NLS-1$
+
+ CSSRuleList cssRules = validatingCSS.getCssRules();
+ if (cssRules.getLength() != 1) {
+ // if the selector is like 'a{} b', or it is empty, or the rule cannot be created
+ return false;
+ }
+
+ CSSStyleRule cssRule = (CSSStyleRule) cssRules.item(0);
+ if (!selector.equals(cssRule.getSelectorText())) {
+ // if the selector is like 'a{{{'
+ return false;
+ }
+
+ cleanValidatingDocument();
+
+ return true;
+ }
+
+ /**
+ * Provides a way to temporarily delete all loggers from
+ * {@link org.eclipse.core.internal.runtime.RuntimeLog}
+ *
+ * @author yradtsevich
+ *
+ */
+ private class LogHacker {
+ private Field logListeners = null;
+ private Object oldValue = null;
+
+ public LogHacker() {
+ try {
+ logListeners = org.eclipse.core.internal.runtime.RuntimeLog.class
+ .getDeclaredField("logListeners");
+ logListeners.setAccessible(true);
+ } catch (Throwable e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ }
+
+ public void disableLogging() {
+ try {
+ oldValue = logListeners.get(null);
+ logListeners.set(null, new ArrayList<Object>(0));
+ } catch (Throwable e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ }
+
+ public void enableLogging() {
+ try {
+ if (oldValue != null) {
+ logListeners.set(null, oldValue);
+ }
+ } catch (Throwable e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ } finally {
+ oldValue = null;
+ }
+ }
+ }
+}
Modified: branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/StyleAttributes.java
===================================================================
--- branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/StyleAttributes.java 2009-03-19 09:19:53 UTC (rev 14262)
+++ branches/jbosstools-3.0.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/StyleAttributes.java 2009-03-19 13:36:13 UTC (rev 14263)
@@ -33,7 +33,7 @@
*/
public StyleAttributes() {
this.attributeMap = new HashMap<String, String>();
- cssValidator = new CSSValidator();
+ cssValidator = CSSValidator.getInstance();
}
/**
15 years, 3 months
JBoss Tools SVN: r14262 - trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect.
by jbosstools-commits@lists.jboss.org
Author: dgeraskov
Date: 2009-03-19 05:19:53 -0400 (Thu, 19 Mar 2009)
New Revision: 14262
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java
Log:
AllEntitiesInfoCollector should either return copy of the mapCUs_Info map
or recreate it on every 'initCollector' call.
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java 2009-03-19 08:13:34 UTC (rev 14261)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java 2009-03-19 09:19:53 UTC (rev 14262)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.hibernate.eclipse.jdt.ui.internal.jpa.collect;
+import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -53,7 +54,7 @@
// setup java project
this.javaProject = javaProject;
// clear collection
- mapCUs_Info.clear();
+ mapCUs_Info = new TreeMap<String, EntityInfo>();
}
/**
15 years, 3 months
JBoss Tools SVN: r14261 - trunk/jst/plugins/org.jboss.tools.jst.jsp.
by jbosstools-commits@lists.jboss.org
Author: sdzmitrovich
Date: 2009-03-19 04:13:34 -0400 (Thu, 19 Mar 2009)
New Revision: 14261
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
Log:
https://jira.jboss.org/jira/browse/JBIDE-4008
https://jira.jboss.org/jira/browse/JBIDE-4043
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2009-03-19 08:07:07 UTC (rev 14260)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2009-03-19 08:13:34 UTC (rev 14261)
@@ -148,7 +148,8 @@
</extension>
<extension point="org.eclipse.ui.editorActions">
- <editorContribution id="formatJSPActionContribution" targetID="org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor">
+ <!-- necessary menu items -->
+ <!--<editorContribution id="formatJSPActionContribution" targetID="org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor">
<action actionID="formatJSPAction" class="org.jboss.tools.jst.jsp.ui.action.FormatJSPActionDelegate" id="formatJSPAction" label="Format" menubarPath="edit/additions">
</action>
</editorContribution>
@@ -314,7 +315,7 @@
id="StructureSelectHistory"
label="Restore Last Selection">
</action>
- </editorContribution>
+ </editorContribution>-->
<editorContribution
id="org.jboss.tools.jst.jsp.cssClassDialogEditorContribution"
targetID="org.eclipse.wst.css.core.csssource.source">
@@ -342,8 +343,100 @@
tooltip="Open CSS Dialog based on the active CSS file">
</action>
</editorContribution>
+
</extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution locationURI="menu:sourceMenuId?after=sourceBegin">
+
+ <action
+ actionID="org.eclipse.wst.sse.ui.toggle.comment"
+ class="org.eclipse.wst.xml.ui.internal.actions.ToggleCommentActionXMLDelegate"
+ definitionId="org.eclipse.wst.sse.ui.toggle.comment"
+ id="ToggleComment"
+ menubarPath="sourceMenuId/sourceBegin"
+ label="Toggle Comment">
+ </action>
+ <command commandId="org.eclipse.wst.sse.ui.toggle.comment"
+ id="ToggleComment"
+ mnemonic="%command.toggle.comment.mnemonic"
+ style="push">
+ <visibleWhen checkEnabled="false">
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </visibleWhen>
+ </command>
+ <command commandId="org.eclipse.wst.sse.ui.add.block.comment"
+ id="AddBlockComment"
+ mnemonic="%command.add.block.comment.mnemonic"
+ style="push">
+ <visibleWhen checkEnabled="false">
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </visibleWhen>
+ </command>
+ <command commandId="org.eclipse.wst.sse.ui.remove.block.comment"
+ id="RemoveBlockComment"
+ mnemonic="%command.remove.block.comment.mnemonic"
+ style="push">
+ <visibleWhen checkEnabled="false">
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.wst.xml.ui.internal.handlers.ToggleCommentHandler"
+ commandId="org.eclipse.wst.sse.ui.toggle.comment">
+ <activeWhen>
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </activeWhen>
+ <enabledWhen>
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </enabledWhen>
+ </handler>
+ <handler
+ class="org.eclipse.wst.xml.ui.internal.handlers.AddBlockCommentHandler"
+ commandId="org.eclipse.wst.sse.ui.add.block.comment">
+ <activeWhen>
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </activeWhen>
+ <enabledWhen>
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </enabledWhen>
+ </handler>
+ <handler
+ class="org.eclipse.wst.xml.ui.internal.handlers.RemoveBlockCommentHandler"
+ commandId="org.eclipse.wst.sse.ui.remove.block.comment">
+ <activeWhen>
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </activeWhen>
+ <enabledWhen>
+ <reference definitionId="org.jboss.tools.ui.comments"/>
+ </enabledWhen>
+ </handler>
+ </extension>
+ <extension point="org.eclipse.core.expressions.definitions">
+ <definition id="org.jboss.tools.ui.comments">
+ <and>
+ <with variable="activeContexts">
+ <iterate operator="or">
+ <equals value="org.eclipse.wst.sse.ui.structuredTextEditorScope"/>
+ </iterate>
+ </with>
+ <or>
+ <with variable="activeEditorId">
+ <equals value="org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor"/>
+ </with>
+ <with variable="activeEditorId">
+ <equals value="org.jboss.tools.jst.jsp.jspeditor.HTMLTextEditor"/>
+ </with>
+ </or>
+ </and>
+ </definition>
+ </extension>
<!--extension point="org.jboss.tools.common.verification.rules">
<rule-set path="meta/.rule-sets.xml"/>
</extension-->
15 years, 3 months