Author: dgolovin
Date: 2011-09-28 18:16:46 -0400 (Wed, 28 Sep 2011)
New Revision: 35138
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorPart.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageSelectionProvider.java
trunk/vpe/plugins/org.jboss.tools.vpe.base.test/src/org/jboss/tools/vpe/base/test/TestUtil.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeElementMapping.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeNodeMapping.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaPreview.java
Log:
Improved Exception handling and minor style fixes for vpe
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java 2011-09-28
20:37:11 UTC (rev 35137)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java 2011-09-28
22:16:46 UTC (rev 35138)
@@ -109,19 +109,12 @@
private IVisualEditor visualEditor;
private int visualSourceIndex;
-
- private JSPTextEditor sourceEditor;
-
private int sourceIndex;
-
- /** composite control for default web-browser */
- // private IVisualEditor previewWebBrowser;
-
/** index of tab contain default web-browser */
private int previewIndex=-1;//by default 1, so if there no visual editor impl, this tab
will be not available
- // private boolean osWindows = true;
-
+ private JSPTextEditor sourceEditor;
+
private BundleMap bundleMap;
protected XModelTreeListenerSWTASync syncListener = new XModelTreeListenerSWTASync(
@@ -430,43 +423,48 @@
protected void createPages() {
- createPagesForVPE();
- loadSelectedTab();
+ try {
+ createPagesForVPE();
+ loadSelectedTab();
- switch (selectedPageIndex) {
- case 0: {
- // source/visual mode
- setActivePage(selectedPageIndex);
- pageChange(selectedPageIndex);
- break;
- } case 1: {
- // source mode
- setActivePage(selectedPageIndex);
- pageChange(selectedPageIndex);
- break;
- } case 2: {
- // preview mode
- setActivePage(selectedPageIndex);
- pageChange(selectedPageIndex);
- break;
- } default: {
- // by default we sets source/visual mode
- setActivePage(0);
- pageChange(0);
- break;
+ switch (selectedPageIndex) {
+ case 0: {
+ // source/visual mode
+ setActivePage(selectedPageIndex);
+ pageChange(selectedPageIndex);
+ break;
+ } case 1: {
+ // source mode
+ setActivePage(selectedPageIndex);
+ pageChange(selectedPageIndex);
+ break;
+ } case 2: {
+ // preview mode
+ setActivePage(selectedPageIndex);
+ pageChange(selectedPageIndex);
+ break;
+ } default: {
+ // by default we sets source/visual mode
+ setActivePage(0);
+ pageChange(0);
+ break;
+ }
}
+
+ IFile f = getFile();
+ if (f != null && f.exists()) {
+ new ResourceChangeListener(this, getContainer());
+ }
+ if (getModelObject() != null) {
+ getModelObject().getModel().addModelTreeListener(syncListener);
+ }
+ } catch (PartInitException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
}
-
- IFile f = getFile();
- if (f != null && f.exists()) {
- new ResourceChangeListener(this, getContainer());
- }
- if (getModelObject() != null) {
- getModelObject().getModel().addModelTreeListener(syncListener);
- }
+
}
- private void createPagesForVPE() {
+ private void createPagesForVPE() throws PartInitException {
/*
* Create Source Editor and BundleMap
*/
@@ -478,64 +476,32 @@
* or here if there is only the source part.
*/
bundleMap = new BundleMap();
-
+ String sourceTabLabel = JSPEditorMessages.JSPMultiPageEditor_TabLabel_Source;
if (visualEditorFactory != null) {
- visualEditor = visualEditorFactory.createVisualEditor(this,
- sourceEditor, IVisualEditor.VISUALSOURCE_MODE, bundleMap);
- }
- try {
- if (visualEditor != null) {
- visualSourceIndex = addPage(visualEditor, getEditorInput(),sourceEditor);
- setPageText(
- visualSourceIndex,
- JSPEditorMessages.JSPMultiPageEditor_TabLabel_VisualSource);
- setPartName(visualEditor.getTitle());
- }
- } catch (PartInitException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- /*
- * try { visualIndex = addPage(visualEditor, getEditorInput());
- * setPageText(visualIndex, JSPEditorMessages
- * .getString(VISUAL_TAB_LABEL)); setPartName(visualEditor.getTitle());
- * } catch (PartInitException e) {
- * JspEditorPlugin.getPluginLog().logError(e); }
- */
+ visualEditor = visualEditorFactory.createVisualEditor(this,sourceEditor,
IVisualEditor.VISUALSOURCE_MODE, bundleMap);
- try {
- String sourceTabLabel = JSPEditorMessages.JSPMultiPageEditor_TabLabel_Source;
- if (visualEditor != null) {
- sourceIndex = addPage(visualEditor, getEditorInput(),sourceEditor);
- setPageText(sourceIndex, sourceTabLabel);
- setPartName(visualEditor.getTitle());
- } else {
- sourceIndex = addPage(sourceEditor, getEditorInput(),sourceEditor);
- setPageText(sourceIndex, sourceTabLabel);
- setPartName(sourceEditor.getTitle());
- }
- } catch (PartInitException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
+ visualSourceIndex = addPage(visualEditor, getEditorInput(),sourceEditor);
+ setPageText(visualSourceIndex,JSPEditorMessages.JSPMultiPageEditor_TabLabel_VisualSource);
+ setPartName(visualEditor.getTitle());
- // Add tab contain default web-browser
- try {
- if (visualEditor != null) {
- setPreviewIndex(addPage(visualEditor, getEditorInput(),sourceEditor));
- setPageText(getPreviewIndex(),
- JSPEditorMessages.JSPMultiPageEditor_TabLabel_Preview);
- setPartName(visualEditor.getTitle());
- }
- } catch (PartInitException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
-
- /*
- * When there is only the source part --
- * then VpeController very likely hasn't been created.
- * Thus Bundle Map should be initialized here instead of
- * VpeController.
- */
- if (visualEditor == null) {
+ sourceIndex = addPage(visualEditor, getEditorInput(),sourceEditor);
+ setPageText(sourceIndex, sourceTabLabel);
+ setPartName(visualEditor.getTitle());
+
+ setPreviewIndex(addPage(visualEditor, getEditorInput(),sourceEditor));
+ setPageText(getPreviewIndex(),
+ JSPEditorMessages.JSPMultiPageEditor_TabLabel_Preview);
+ setPartName(visualEditor.getTitle());
+ } else {
+ sourceIndex = addPage(sourceEditor, getEditorInput(),sourceEditor);
+ setPageText(sourceIndex, sourceTabLabel);
+ setPartName(sourceEditor.getTitle());
+ /*
+ * When there is only the source part --
+ * then VpeController very likely hasn't been created.
+ * Thus Bundle Map should be initialized here instead of
+ * VpeController.
+ */
bundleMap.init(sourceEditor.getEditorInput());
}
}
@@ -845,7 +811,7 @@
.getString(IVpePreferencesPage.DEFAULT_VPE_TAB);
try {
int ind = Integer.parseInt(tabIndex);
- getTabFolder().setSelection(ind);
+ setActivePage(ind);
pageChange(ind);
} catch (NumberFormatException e) {
JspEditorPlugin.getPluginLog().logError(e);
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorPart.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorPart.java 2011-09-28
20:37:11 UTC (rev 35137)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditorPart.java 2011-09-28
22:16:46 UTC (rev 35138)
@@ -28,7 +28,9 @@
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -46,6 +48,7 @@
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.part.EditorPart;
+import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.part.MultiPageEditorSite;
import org.eclipse.ui.part.PageSwitcher;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
@@ -55,7 +58,7 @@
/**
*
*/
-public abstract class JSPMultiPageEditorPart extends EditorPart {
+public abstract class JSPMultiPageEditorPart extends MultiPageEditorPart {
private static final String COMMAND_NEXT_SUB_TAB =
"org.eclipse.ui.navigate.nextSubTab"; //$NON-NLS-1$
private static final String COMMAND_PREVIOUS_SUB_TAB =
"org.eclipse.ui.navigate.previousSubTab"; //$NON-NLS-1$
@@ -71,15 +74,9 @@
super();
}
- public int addPage(Control control) {
- createItem(control);
- return getPageCount() - 1;
- }
-
/**
*
*/
-
Composite ppp = null;
/**
*
@@ -138,143 +135,17 @@
return getPageCount() - 1;
}
- /**
- *
- * @param parent
- * @return
- */
- private CTabFolder createContainer(Composite parent) {
- final CTabFolder newContainer = new CTabFolder(parent, SWT.BOTTOM
- | SWT.FLAT);
- newContainer.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- int newPageIndex = newContainer.indexOf((CTabItem) e.item);
- pageChange(newPageIndex);
- }
- });
- newContainer.addTraverseListener(new TraverseListener() {
- // Switching tabs by Ctrl+PageUp/PageDown must not be caught on the inner tab set
- public void keyTraversed(TraverseEvent e) {
- switch (e.detail) {
- case SWT.TRAVERSE_PAGE_NEXT:
- case SWT.TRAVERSE_PAGE_PREVIOUS:
- int detail = e.detail;
- e.doit = true;
- e.detail = SWT.TRAVERSE_NONE;
- Control control = newContainer.getParent();
- control.traverse(detail, new Event());
- }
- }
- });
-
- return newContainer;
- }
-
/*
*
*/
private CTabItem createItem(Control control) {
- CTabItem item = new CTabItem(getTabFolder(), SWT.NONE);
+ CTabItem item = new CTabItem((CTabFolder)getContainer(), SWT.NONE);
item.setControl(control);
return item;
}
protected abstract void createPages();
- public final void createPartControl(Composite parent) {
- this.tabFolderContainer = createContainer(parent);
- createPages();
- // set the active page (page 0 by default), unless it has already been
- // done
- if (getActivePage() == -1)
- setActivePage(0);
-
- initializePageSwitching();
- initializeSubTabSwitching();
- }
-
- /*
- * Initialize the MultiPageEditorPart to use the page switching command.
- */
- protected void initializePageSwitching() {
- new PageSwitcher(this) {
- public Object[] getPages() {
- int pageCount = getPageCount();
- Object[] result = new Object[pageCount];
- for (int i = 0; i < pageCount; i++) {
- result[i] = new Integer(i);
- }
- return result;
- }
-
- public String getName(Object page) {
- return getPageText(((Integer) page).intValue());
- }
-
- public ImageDescriptor getImageDescriptor(Object page) {
- Image image = getPageImage(((Integer) page).intValue());
- if (image == null)
- return null;
-
- return ImageDescriptor.createFromImage(image);
- }
-
- public void activatePage(Object page) {
- setActivePage(((Integer) page).intValue());
- }
-
- public int getCurrentPageIndex() {
- return getActivePage();
- }
- };
- }
-
- /*
- * Initialize the MultiPageEditorPart to use the sub-tab switching commands.
- */
- private void initializeSubTabSwitching() {
- IHandlerService service = (IHandlerService)
getSite().getService(IHandlerService.class);
- service.activateHandler(COMMAND_NEXT_SUB_TAB, new AbstractHandler() {
- /**
- * {@inheritDoc}
- * @throws ExecutionException
- * if an exception occurred during execution
- */
- public Object execute(ExecutionEvent event) throws ExecutionException {
- int n= getPageCount();
- if (n == 0)
- return null;
-
- int i= getActivePage() + 1;
- if (i >= n)
- i= 0;
- setActivePage(i);
- pageChange(i);
- return null;
- }
- });
-
- service.activateHandler(COMMAND_PREVIOUS_SUB_TAB, new AbstractHandler() {
- /**
- * {@inheritDoc}
- * @throws ExecutionException
- * if an exception occurred during execution
- */
- public Object execute(ExecutionEvent event) throws ExecutionException {
- int n= getPageCount();
- if (n == 0)
- return null;
-
- int i= getActivePage() - 1;
- if (i < 0)
- i= n - 1;
- setActivePage(i);
- pageChange(i);
- return null;
- }
- });
- }
-
protected abstract IEditorSite createSite(IEditorPart editor);
public void dispose() {
@@ -288,7 +159,7 @@
}
nestedEditors.clear();
}
-
+
protected IEditorPart getActiveEditor() {
int index = getActivePage();
if (index != -1)
@@ -296,88 +167,10 @@
return null;
}
- protected int getActivePage() {
- CTabFolder tabFolder = getTabFolder();
- if (tabFolder != null && !tabFolder.isDisposed())
- return tabFolder.getSelectionIndex();
- return -1;
- }
-
- protected Composite getContainer() {
- return tabFolderContainer;
- }
-
- protected Control getControl(int pageIndex) {
- return getItem(0).getControl();
- }
-
- protected IEditorPart getEditor(int pageIndex) {
- Item item = getItem(pageIndex);
- if (item != null) {
- Object data = item.getData();
- if (data instanceof IEditorPart) {
- return (IEditorPart) data;
- }
- }
- return null;
- }
-
- /**
- * Find the editors contained in this multi-page editor
- * whose editor input match the provided input.
- * @param input the editor input
- * @return the editors contained in this multi-page editor
- * whose editor input match the provided input
- * @since 3.3
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public final IEditorPart[] findEditors(IEditorInput input) {
- List result = new ArrayList();
- int count = getPageCount();
- for (int i = 0; i < count; i++) {
- IEditorPart editor = getEditor(i);
- if (editor != null
- && editor.getEditorInput() != null
- && editor.getEditorInput().equals(input)) {
- result.add(editor);
- }
- }
- return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]);
- }
-
-
- private CTabItem getItem(int pageIndex) {
- return getTabFolder().getItem(pageIndex);
- }
-
- protected int getPageCount() {
- CTabFolder folder = getTabFolder();
- // May not have been created yet, or may have been disposed.
- if (folder != null && !folder.isDisposed())
- return folder.getItemCount();
- return 0;
- }
-
- protected Image getPageImage(int pageIndex) {
- return getItem(pageIndex).getImage();
- }
-
- protected String getPageText(int pageIndex) {
- return getItem(pageIndex).getText();
- }
-
- protected CTabFolder getTabFolder() {
- return tabFolderContainer;
- }
-
public SelectionBar getSelectionBar() {
return selectionBar;
}
- protected void handlePropertyChange(int propertyId) {
- firePropertyChange(propertyId);
- }
-
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
setSite(site);
@@ -385,17 +178,6 @@
site.setSelectionProvider(new JSPMultiPageSelectionProvider(this));
}
- public boolean isDirty() {
- // use nestedEditors to avoid SWT requests; see bug 12996
- for (Iterator i = nestedEditors.iterator(); i.hasNext();) {
- IEditorPart editor = (IEditorPart) i.next();
- if (editor.isDirty()) {
- return true;
- }
- }
- return false;
- }
-
protected abstract void pageChange(int newPageIndex);
private void disposePart(final IWorkbenchPart part) {
@@ -414,25 +196,6 @@
});
}
- public void removePage(int pageIndex) {
- Assert.isTrue(pageIndex >= 0 && pageIndex < getPageCount());
- IEditorPart editor = getEditor(pageIndex);
- getItem(pageIndex).dispose();
- if (editor != null) {
- nestedEditors.remove(editor);
- disposePart(editor);
- }
- }
-
- protected void setActivePage(int pageIndex) {
- Assert.isTrue(pageIndex >= 0 && pageIndex < getPageCount());
- getTabFolder().setSelection(pageIndex);
- }
-
- protected void setControl(int pageIndex, Control control) {
- getItem(pageIndex).setControl(control);
- }
-
public void setFocus() {
setFocus(getActivePage());
}
@@ -471,13 +234,4 @@
}
}
}
-
- protected void setPageImage(int pageIndex, Image image) {
- getItem(pageIndex).setImage(image);
- }
-
- protected void setPageText(int pageIndex, String text) {
- getItem(pageIndex).setText(text);
- }
-
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageSelectionProvider.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageSelectionProvider.java 2011-09-28
20:37:11 UTC (rev 35137)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageSelectionProvider.java 2011-09-28
22:16:46 UTC (rev 35138)
@@ -64,7 +64,7 @@
}
public ISelection getSelection() {
- IEditorPart activeEditor = multiPageEditor.getActiveEditor();
+ IEditorPart activeEditor = ((JSPMultiPageEditorPart)
multiPageEditor).getActiveEditor();
if (activeEditor != null) {
ISelectionProvider selectionProvider = activeEditor.getSite()
.getSelectionProvider();
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 2011-09-28
20:37:11 UTC (rev 35137)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2011-09-28
22:16:46 UTC (rev 35138)
@@ -1533,40 +1533,31 @@
}
// 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$
+ 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$
+ 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$
+ 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$
+ 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$
}
@@ -1629,24 +1620,6 @@
}
}
- // 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();
@@ -1678,164 +1651,6 @@
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;
- // }
- // }
-
public class VpeSelectionProvider implements ISelectionProvider {
VpeSelection selection;
@@ -1952,22 +1767,6 @@
}
}
-// this method is never used
-// public void dragEnter(nsIDOMEvent event) {
-// if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
-// System.out.println("<<<<<<<<<<<<<<<<<<<<
DragEnter"); //$NON-NLS-1$
-// }
-// }
-
-// this method is never used
-// 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 String getTagName(XModelObject object) {
String tagname = object.getAttributeValue("name"); //$NON-NLS-1$
@@ -2198,66 +1997,10 @@
}
}
-// this method is never used
-// // 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);
}
-// this method is never used
-// /*
-// * (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 changed, and we should highlight selected element.
*/
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2011-09-28
20:37:11 UTC (rev 35137)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2011-09-28
22:16:46 UTC (rev 35138)
@@ -340,12 +340,11 @@
}
// check source node can be changed and link can be a null in this case
// we shouldn't process this node
- if (sourceNode == null
- || (sourceNode.getNodeType() != Node.TEXT_NODE
- && sourceNode.getNodeType() != Node.ELEMENT_NODE
- && sourceNode.getNodeType() != Node.COMMENT_NODE
- && sourceNode.getNodeType() != Node.CDATA_SECTION_NODE
- && sourceNode.getNodeType() != Node.DOCUMENT_NODE)) {
+ if (sourceNode.getNodeType() != Node.TEXT_NODE
+ && sourceNode.getNodeType() != Node.ELEMENT_NODE
+ && sourceNode.getNodeType() != Node.COMMENT_NODE
+ && sourceNode.getNodeType() != Node.CDATA_SECTION_NODE
+ && sourceNode.getNodeType() != Node.DOCUMENT_NODE) {
return null;
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java 2011-09-28
20:37:11 UTC (rev 35137)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java 2011-09-28
22:16:46 UTC (rev 35138)
@@ -75,24 +75,9 @@
}
public VpeNodeMapping getNodeMappingAtVisualNode(nsIDOMNode visualNode) {
-
-
- Iterator<Map.Entry<nsIDOMNode, VpeNodeMapping>> iter =
visualMap.entrySet().iterator();
- //Map.get() doesn't work correctly for this situation
- while(iter.hasNext()){
- Map.Entry<nsIDOMNode,VpeNodeMapping> element = iter.next();
- nsIDOMNode key = element.getKey();
- if(visualNode!=null&&visualNode.equals(key)) {
-
- return element.getValue();
- }
-
+ if(visualNode!=null) {
+ return visualMap.get(visualNode);
}
-//
-// if (visualNode != null) {
-// return visualMap.get(visualNode);
-// }
-
return null;
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeElementMapping.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeElementMapping.java 2011-09-28
20:37:11 UTC (rev 35137)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeElementMapping.java 2011-09-28
22:16:46 UTC (rev 35138)
@@ -58,7 +58,7 @@
}
public nsIDOMElement getVisualElement() {
- return (nsIDOMElement) getVisualNode();
+ return (nsIDOMElement) this.visualNode;
}
public VpeTemplate getTemplate() {
@@ -96,7 +96,7 @@
while(true){
if(this.border.equals(element)) return true;
- if(getVisualNode().equals(element)) return false;
+ if(this.visualNode.equals(element)) return false;
element = element.getParentNode();
if(element == null) break;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeNodeMapping.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeNodeMapping.java 2011-09-28
20:37:11 UTC (rev 35137)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeNodeMapping.java 2011-09-28
22:16:46 UTC (rev 35138)
@@ -13,9 +13,13 @@
import org.mozilla.interfaces.nsIDOMNode;
import org.w3c.dom.Node;
+/**
+ * Stores a relation between Node in source model and nsIDOMNode in in visual model
+ * @see VpeDomMapping
+ */
public class VpeNodeMapping {
- private Node sourceNode;
- private nsIDOMNode visualNode;
+ Node sourceNode;
+ nsIDOMNode visualNode;
public VpeNodeMapping(Node sourceNode, nsIDOMNode visualNode) {
this.sourceNode = sourceNode;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2011-09-28
20:37:11 UTC (rev 35137)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2011-09-28
22:16:46 UTC (rev 35138)
@@ -122,12 +122,11 @@
public static final String ICON_NON_VISUAL_TAGS =
"icons/non-visusal-tags.gif"; //$NON-NLS-1$
public static final String ICON_TEXT_FORMATTING = "icons/text-formatting.gif";
//$NON-NLS-1$
public static final String ICON_BUNDLE_AS_EL= "icons/bundle-as-el.gif";
//$NON-NLS-1$
-//static String SELECT_BAR = "SELECT_LBAR"; //$NON-NLS-1$
+
private XulRunnerEditor xulRunnerEditor;
private nsIDOMElement contentArea;
private nsIDOMNode headNode;
- private MozillaEventAdapter mozillaEventAdapter
- = createMozillaEventAdapter();
+ private MozillaEventAdapter mozillaEventAdapter = createMozillaEventAdapter();
private EditorLoadWindowListener editorLoadWindowListener;
@@ -149,7 +148,7 @@
private Action showNonVisualTagsAction;
private Action showTextFormattingAction;
private Action showBundleAsELAction;
-// private Action externalizeStringsAction;
+
static {
/*
@@ -477,28 +476,15 @@
*/
@Override
public void createPartControl(final Composite parent) {
- //Setting Layout for the parent Composite
-// parent.setLayout(new FillLayout());
-
- /*
- *
https://jira.jboss.org/jira/browse/JBIDE-4062
- * Creating scrollable eclipse element.
- */
-// ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL |
SWT.BORDER);
-// sc.setLayout(new FillLayout());
-// Composite composite = new Composite(parent, SWT.NATIVE);
- GridLayout layout = new GridLayout(2,false);
+ GridLayout layout = new GridLayout(2,false);
layout.marginHeight = 0;
layout.marginWidth = 2;
layout.verticalSpacing = 2;
layout.horizontalSpacing = 2;
layout.marginBottom = 0;
parent.setLayout(layout);
-// composite.setLayout(layout);
-// composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
-
+
// Editors and Toolbar composite
Composite cmpEdTl = new Composite(parent, SWT.NONE);
GridLayout layoutEdTl = new GridLayout(1, false);
@@ -537,49 +523,11 @@
cmpEd.setLayout(layoutEd);
cmpEd.setLayoutData(new GridData(GridData.FILL_BOTH));
- //TODO Add a paintListener to cmpEd and give him a border top and left only
+ //TODO Add a paintListener to cmpEd and give him a border top and left only
Color buttonDarker =
parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
cmpEd.setBackground(buttonDarker);
try {
- /*xulRunnerEditor = new XulRunnerEditor(cmpEd) {
- public void onLoadWindow() {
- // if the first load page
- if (!isRefreshPage()) {
- super.onLoadWindow();
-// MozillaEditor.this.onLoadWindow();
- }
- // if only refresh page
- else {
-
- MozillaEditor.this.onReloadWindow();
- setRefreshPage(false);
- }
-
- }
- public void onElementResize(nsIDOMElement element, int constrains, int top, int left,
int width, int height) {
- if (editorDomEventListener != null) {
- editorDomEventListener.elementResized(element, constrains, top, left, width,
height);
- }
- }
- public void onShowTooltip(int x, int y, String text) {
- if (editorDomEventListener != null) {
- editorDomEventListener.onShowTooltip(x, y, text);
- }
- }
- public void onHideTooltip() {
- if (editorDomEventListener != null) {
- editorDomEventListener.onHideTooltip();
- }
- }
- public void onDispose() {
- tearDownEditor();
- removeDomEventListeners();
- headNode = null;
- contentArea = null;
- super.onDispose();
- }
- };*/
xulRunnerEditor = new XulRunnerEditor2(cmpEd, this);
xulRunnerEditor.getBrowser().addProgressListener(new ProgressListener() {
@@ -598,41 +546,20 @@
showXulRunnerError(cmpEd, ex);
}
}
-
});
-
+
setInitialContent();
- // Wait while visual part is loaded
- //commented by mareshkau, fix for jbide-3032
-// while (!loaded) {
-// if (!Display.getCurrent().readAndDispatch())
-// Display.getCurrent().sleep();
-// }
xulRunnerEditor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
} catch (Throwable t) {
/*
- *
https://jira.jboss.org/browse/JBIDE-6690
* Disable VPE toolbar
*/
if (verBar != null) {
verBar.setEnabled(false);
}
- /*
- * Show the exception
- */
showXulRunnerError(cmpEd, t);
}
-
- /*
- *
https://jira.jboss.org/jira/browse/JBIDE-4062
- * Computing elements sizes to set up scroll bars.
- */
-// Point totalSize = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
-// sc.setContent(composite);
-// sc.setExpandHorizontal(true);
-// sc.setExpandVertical(true);
-// sc.setMinSize(totalSize);
}
/**
@@ -716,23 +643,24 @@
link.addMouseListener(new MouseListener() {
public void mouseDown(org.eclipse.swt.events.MouseEvent e) {
- BusyIndicator.showWhile(link.getDisplay(), new Runnable() {
- public void run() {
- URL theURL=null;;
+ BusyIndicator.showWhile(link.getDisplay(), new Runnable() {
+ public void run() {
+ URL theURL = null;
+ ;
try {
theURL = new URL(VpeUIMessages.MOZILLA_LOADING_ERROR_LINK);
} catch (MalformedURLException e) {
VpePlugin.reportProblem(e);
}
- IWorkbenchBrowserSupport support =
PlatformUI.getWorkbench().getBrowserSupport();
- try {
+ IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
+ try {
support.getExternalBrowser().openURL(theURL);
} catch (PartInitException e) {
VpePlugin.reportProblem(e);
}
- }
- });
- }
+ }
+ });
+ }
public void mouseDoubleClick(MouseEvent e) {
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaPreview.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaPreview.java 2011-09-28
20:37:11 UTC (rev 35137)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaPreview.java 2011-09-28
22:16:46 UTC (rev 35138)
@@ -26,6 +26,10 @@
import org.jboss.tools.vpe.editor.mozilla.listener.EditorLoadWindowListener;
import org.jboss.tools.vpe.editor.mozilla.listener.MozillaDndListener;
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
+import org.jboss.tools.vpe.xulrunner.PlatformIsNotSupportedException;
+import org.jboss.tools.vpe.xulrunner.XulRunnerBundleNotFoundException;
+import org.jboss.tools.vpe.xulrunner.XulRunnerException;
+import org.mozilla.xpcom.XPCOMException;
/**
* a class implementation of mozilla preview
@@ -55,33 +59,20 @@
@Override
public void createPartControl(final Composite parent) {
try {
- /*setXulRunnerEditor(new XulRunnerEditor(parent) {
- public void onLoadWindow() {
- super.onLoadWindow();
- MozillaPreview.this.onLoadWindow();
- }
-
- public void onShowTooltip(int x, int y, String text) {
- if (editorDomEventListener != null) {
- editorDomEventListener.onShowTooltip(x, y, text);
- }
- }
- public void onHideTooltip() {
- if (editorDomEventListener != null) {
- editorDomEventListener.onHideTooltip();
- }
- }
- public void onDispose() {
- removeDomEventListeners();
- super.onDispose();
- }
- });*/
setXulRunnerEditor(new XulRunnerPreview(parent, this));
setInitialContent();
getXulRunnerEditor().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- } catch (Throwable e) {
+ } catch (XulRunnerBundleNotFoundException e) {
+ // TODO add page with explanation what to do
showXulRunnerError(parent, e);
- }
+ } catch (PlatformIsNotSupportedException e) {
+ // TODO add page with explanation what platforms supported and what tod o
+ showXulRunnerError(parent, e);
+ } catch (XulRunnerException e) {
+ showXulRunnerError(parent, e);
+ } catch(XPCOMException e) {
+ showXulRunnerError(parent, e);
+ }
}
@Override
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.base.test/src/org/jboss/tools/vpe/base/test/TestUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.base.test/src/org/jboss/tools/vpe/base/test/TestUtil.java 2011-09-28
20:37:11 UTC (rev 35137)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.base.test/src/org/jboss/tools/vpe/base/test/TestUtil.java 2011-09-28
22:16:46 UTC (rev 35138)
@@ -155,12 +155,6 @@
* Wait until all background tasks are complete.
*/
public static void waitForJobs() {
- //commented by Maksim Areshkau
- //because this method wait only for jobs which has been runned in current thread,
- //and don't wait for others. It can cause
https://jira.jboss.org/jira/browse/JBIDE-5820
- //https://jira.jboss.org/jira/browse/JBIDE-5821
-// while (Job.getJobManager().currentJob() != null)
-// delay(100);
waitForIdle();
}