### Eclipse Workspace Patch 1.0 #P org.eclipse.wst.sse.ui Index: plugin.xml =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/plugin.xml,v retrieving revision 1.46 diff -u -r1.46 plugin.xml --- plugin.xml 7 Feb 2008 07:46:35 -0000 1.46 +++ plugin.xml 21 Feb 2008 04:24:35 -0000 @@ -1,5 +1,5 @@ - + - + + + + @@ -448,5 +452,72 @@ - + schema="schema/org.eclipse.wst.sse.ui.sourcevalidation.exsd" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: plugin.properties =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/plugin.properties,v retrieving revision 1.19 diff -u -r1.19 plugin.properties --- plugin.properties 7 Feb 2008 07:46:35 -0000 1.19 +++ plugin.properties 21 Feb 2008 04:24:34 -0000 @@ -8,7 +8,7 @@ # Contributors: # IBM Corporation - initial API and implementation # Jens Lukowski/Innoopract - initial renaming/restructuring -# +# David Carver - bug 212330 - migrate to org.eclipse.ui.menus extension point ############################################################################### providerName=Eclipse.org pluginName=Structured Source Editor @@ -66,6 +66,7 @@ ########################################################################## Source=&Source FormatDocument=&Format +Refactor=Refac&tor ## Breakpoint_Extension_Point.name=Breakpoint Extension Point Source_Validation_Extension_Point.name=Reconcile Validator Extension Point Index: src/org/eclipse/wst/sse/ui/internal/actions/ActionContributor.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/actions/ActionContributor.java,v retrieving revision 1.5 diff -u -r1.5 ActionContributor.java --- src/org/eclipse/wst/sse/ui/internal/actions/ActionContributor.java 8 Nov 2006 21:02:43 -0000 1.5 +++ src/org/eclipse/wst/sse/ui/internal/actions/ActionContributor.java 21 Feb 2008 04:24:37 -0000 @@ -12,11 +12,11 @@ *******************************************************************************/ package org.eclipse.wst.sse.ui.internal.actions; -import java.util.ResourceBundle; +//import java.util.ResourceBundle; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.action.GroupMarker; -import org.eclipse.jface.action.IAction; +//import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.action.IToolBarManager; @@ -24,21 +24,21 @@ import org.eclipse.jface.action.Separator; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchActionConstants; +//import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.actions.ActionFactory; +//import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.editors.text.TextEditorActionContributor; -import org.eclipse.ui.ide.IDEActionFactory; +//import org.eclipse.ui.ide.IDEActionFactory; import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.texteditor.ITextEditorActionConstants; -import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; -import org.eclipse.ui.texteditor.ITextEditorExtension; +//import org.eclipse.ui.texteditor.ITextEditorActionConstants; +//import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; +//import org.eclipse.ui.texteditor.ITextEditorExtension; import org.eclipse.ui.texteditor.RetargetTextEditorAction; import org.eclipse.wst.sse.ui.internal.ExtendedEditorActionBuilder; import org.eclipse.wst.sse.ui.internal.GotoAnnotationAction; import org.eclipse.wst.sse.ui.internal.IExtendedContributor; import org.eclipse.wst.sse.ui.internal.ISourceViewerActionBarContributor; -import org.eclipse.wst.sse.ui.internal.SSEUIMessages; +//import org.eclipse.wst.sse.ui.internal.SSEUIMessages; import org.eclipse.wst.sse.ui.internal.ui.OffsetStatusLineContributionItem; /** @@ -85,7 +85,7 @@ public ActionContributor() { super(); - ResourceBundle resourceBundle = SSEUIMessages.getResourceBundle(); +/* ResourceBundle resourceBundle = SSEUIMessages.getResourceBundle(); fCommandsSeparator = new Separator(); @@ -131,18 +131,18 @@ fNextAnnotation = new GotoAnnotationAction("Next_annotation", true); //$NON-NLS-1$ fNextAnnotation.setActionDefinitionId("org.eclipse.ui.navigate.next"); //$NON-NLS-1$ - +*/ // Read action extensions. ExtendedEditorActionBuilder builder = new ExtendedEditorActionBuilder(); extendedContributor = builder.readActionExtensions(getExtensionIDs()); - +/* fMenuAdditionsGroupMarker = new GroupMarker(StructuredTextEditorActionConstants.GROUP_NAME_MENU_ADDITIONS); fToolbarSeparator = new Separator(); fToolbarAdditionsGroupMarker = new GroupMarker(StructuredTextEditorActionConstants.GROUP_NAME_TOOLBAR_ADDITIONS); fToggleInsertModeAction = new RetargetTextEditorAction(resourceBundle, "Editor.ToggleInsertMode.", IAction.AS_CHECK_BOX); //$NON-NLS-1$ fToggleInsertModeAction.setActionDefinitionId(ITextEditorActionDefinitionIds.TOGGLE_INSERT_MODE); - +*/ if (_showDebugStatus) { fDebugStatusOffset = new OffsetStatusLineContributionItem(StructuredTextEditorActionConstants.STATUS_CATEGORY_OFFSET, true, 20); } @@ -150,7 +150,7 @@ protected void addToMenu(IMenuManager menu) { // edit commands - IMenuManager editMenu = menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); +/* IMenuManager editMenu = menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); if (editMenu != null) { editMenu.add(fCommandsSeparator); editMenu.add(fToggleInsertModeAction); @@ -175,7 +175,7 @@ sourceMenu.add(fShiftRight); sourceMenu.add(fShiftLeft); } - } +*/ } protected void addToPopupMenu(IMenuManager menu) { // add nothing @@ -188,21 +188,22 @@ } protected void addToToolBar(IToolBarManager toolBarManager) { - toolBarManager.add(fToolbarSeparator); +/* toolBarManager.add(fToolbarSeparator); toolBarManager.add(fToolbarAdditionsGroupMarker); - } +*/ } /** * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(IMenuManager) */ public void contributeToMenu(IMenuManager menu) { super.contributeToMenu(menu); - +/* addToMenu(menu); if (extendedContributor != null) { extendedContributor.contributeToMenu(menu); } +*/ } /* @@ -211,12 +212,13 @@ * @see org.eclipse.wst.sse.ui.extension.IPopupMenuContributor#contributeToPopupMenu(org.eclipse.jface.action.IMenuManager) */ public void contributeToPopupMenu(IMenuManager menu) { - +/* addToPopupMenu(menu); if (extendedContributor != null) { extendedContributor.contributeToPopupMenu(menu); } +*/ } /* @@ -240,11 +242,12 @@ public void contributeToToolBar(IToolBarManager toolBarManager) { super.contributeToToolBar(toolBarManager); - addToToolBar(toolBarManager); +/* addToToolBar(toolBarManager); if (extendedContributor != null) { extendedContributor.contributeToToolBar(toolBarManager); } +*/ } /** @@ -300,9 +303,9 @@ return; super.setActiveEditor(activeEditor); - ITextEditor textEditor = getTextEditor(activeEditor); +// ITextEditor textEditor = getTextEditor(activeEditor); - IActionBars actionBars = getActionBars(); +/* IActionBars actionBars = getActionBars(); if (actionBars != null) { actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, fNextAnnotation); actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, fPreviousAnnotation); @@ -342,6 +345,7 @@ ((ITextEditorExtension) textEditor).setStatusField(fDebugStatusOffset, StructuredTextEditorActionConstants.STATUS_CATEGORY_OFFSET); fDebugStatusOffset.setActiveEditor(textEditor); } +*/ } /* @@ -350,18 +354,21 @@ * @see org.eclipse.wst.sse.ui.ISourceViewerActionBarContributor#setViewerSpecificContributionsEnabled(boolean) */ public void setViewerSpecificContributionsEnabled(boolean enabled) { - fShiftRight.setEnabled(enabled); +/* fShiftRight.setEnabled(enabled); fShiftLeft.setEnabled(enabled); fNextAnnotation.setEnabled(enabled); fPreviousAnnotation.setEnabled(enabled); - +*/ /* * fComment.setEnabled(enabled); fUncomment.setEnabled(enabled); */ +/* fToggleComment.setEnabled(enabled); fAddBlockComment.setEnabled(enabled); fRemoveBlockComment.setEnabled(enabled); +*/ // convert line delimiters are not source viewer-specific + } /* @@ -370,8 +377,9 @@ * @see org.eclipse.wst.sse.ui.extension.IExtendedContributor#updateToolbarActions() */ public void updateToolbarActions() { - if (extendedContributor != null) { +/* if (extendedContributor != null) { extendedContributor.updateToolbarActions(); } +*/ } } Index: src/org/eclipse/wst/sse/ui/StructuredTextEditor.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextEditor.java,v retrieving revision 1.86 diff -u -r1.86 StructuredTextEditor.java --- src/org/eclipse/wst/sse/ui/StructuredTextEditor.java 15 Jan 2008 23:40:17 -0000 1.86 +++ src/org/eclipse/wst/sse/ui/StructuredTextEditor.java 21 Feb 2008 04:24:37 -0000 @@ -103,6 +103,7 @@ import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.contexts.IContextService; import org.eclipse.ui.editors.text.EditorsUI; import org.eclipse.ui.editors.text.ITextEditorHelpContextIds; import org.eclipse.ui.editors.text.TextEditor; @@ -1128,16 +1129,16 @@ protected void addContextMenuActions(IMenuManager menu) { // Only offer actions that affect the text if the viewer allows // modification and supports any of these operations - IAction formatAll = getAction(StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_DOCUMENT); - IAction formatSelection = getAction(StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_ACTIVE_ELEMENTS); - IAction cleanupAll = getAction(StructuredTextEditorActionConstants.ACTION_NAME_CLEANUP_DOCUMENT); - boolean enableFormatMenu = (formatAll != null && formatAll.isEnabled()) || (formatSelection != null && formatSelection.isEnabled()) || (cleanupAll != null && cleanupAll.isEnabled()); - - if (getSourceViewer().isEditable() && enableFormatMenu) { - addAction(menu, ITextEditorActionConstants.GROUP_EDIT, StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_DOCUMENT); - addAction(menu, ITextEditorActionConstants.GROUP_EDIT, StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_ACTIVE_ELEMENTS); - addAction(menu, ITextEditorActionConstants.GROUP_EDIT, StructuredTextEditorActionConstants.ACTION_NAME_CLEANUP_DOCUMENT); - } +// IAction formatAll = getAction(StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_DOCUMENT); +// IAction formatSelection = getAction(StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_ACTIVE_ELEMENTS); +// IAction cleanupAll = getAction(StructuredTextEditorActionConstants.ACTION_NAME_CLEANUP_DOCUMENT); +// boolean enableFormatMenu = (formatAll != null && formatAll.isEnabled()) || (formatSelection != null && formatSelection.isEnabled()) || (cleanupAll != null && cleanupAll.isEnabled()); +// +// if (getSourceViewer().isEditable() && enableFormatMenu) { +// addAction(menu, ITextEditorActionConstants.GROUP_EDIT, StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_DOCUMENT); +// addAction(menu, ITextEditorActionConstants.GROUP_EDIT, StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_ACTIVE_ELEMENTS); +// addAction(menu, ITextEditorActionConstants.GROUP_EDIT, StructuredTextEditorActionConstants.ACTION_NAME_CLEANUP_DOCUMENT); +// } // Some Design editors (DTD) rely on this view for their own uses menu.appendToGroup(IWorkbenchActionConstants.GROUP_ADD, fShowPropertiesAction); @@ -1445,6 +1446,9 @@ * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createPartControl(org.eclipse.swt.widgets.Composite) */ public void createPartControl(Composite parent) { + IContextService contextService = (IContextService) getSite().getService(IContextService.class); + contextService.activateContext("org.eclipse.wst.sse.ui.structuredTextEditorScope"); + if (getSourceViewerConfiguration() == null) { ConfigurationAndTarget cat = createSourceViewerConfiguration(); fViewerConfigurationTargetId = cat.getTargetId(); Index: src/org/eclipse/wst/sse/ui/internal/handlers/FormatHandler.java =================================================================== RCS file: src/org/eclipse/wst/sse/ui/internal/handlers/FormatHandler.java diff -N src/org/eclipse/wst/sse/ui/internal/handlers/FormatHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/sse/ui/internal/handlers/FormatHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,266 @@ +/******************************************************************************* + * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Carver - initial API and implementation - bug 212330 - + * Based off FormatActionDelegate.java + *******************************************************************************/ + +package org.eclipse.wst.sse.ui.internal.handlers; + +import java.io.IOException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.content.IContentDescription; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.osgi.util.NLS; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.progress.IWorkbenchSiteProgressService; +import org.eclipse.wst.sse.core.internal.exceptions.MalformedInputExceptionWithDetail; +import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor; +import org.eclipse.wst.sse.ui.internal.FormatProcessorsExtensionReader; +import org.eclipse.wst.sse.ui.internal.Logger; +import org.eclipse.wst.sse.ui.internal.SSEUIMessages; +import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; + +public class FormatHandler extends AbstractHandler implements IHandler { + + protected IStructuredSelection fSelection; + + public void dispose() { + // nulling out just in case + } + + private IWorkbenchSiteProgressService getActiveProgressService() { + IWorkbenchSiteProgressService service = null; + if (PlatformUI.isWorkbenchRunning()) { + IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (activeWorkbenchWindow != null) { + IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); + if (activePage != null) { + IWorkbenchPart activePart = activePage.getActivePart(); + if (activePart != null) { + service = (IWorkbenchSiteProgressService) activePart.getSite().getAdapter(IWorkbenchSiteProgressService.class); + } + } + } + } + return service; + } + + + + + public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getSelectionService().getSelection(); + + if (selection instanceof IStructuredSelection) { + fSelection = (IStructuredSelection) selection; + boolean available = false; + + Object[] elements = fSelection.toArray(); + for (int i = 0; i < elements.length; i++) { + if (elements[i] instanceof IResource) { + available = processorAvailable((IResource) elements[i]); + + if (available) + break; + } + } + } + + if (fSelection != null && !fSelection.isEmpty()) { + Job job = getJob(); + if (job != null) { + IWorkbenchSiteProgressService progressService = getActiveProgressService(); + if (progressService != null) { + progressService.schedule(job); + } + else { + job.schedule(); + } + } + } + + return null; + } + + + class FormatJob extends Job { + + public FormatJob(String name) { + super(name); + } + + protected IStatus run(IProgressMonitor monitor) { + IStatus status = Status.OK_STATUS; + + Object[] elements = fSelection.toArray(); + monitor.beginTask("", elements.length); //$NON-NLS-1$ + for (int i = 0; i < elements.length; i++) { + if (elements[i] instanceof IResource) { + process(new SubProgressMonitor(monitor, 1), (IResource) elements[i]); + } + else { + monitor.worked(1); + } + } + monitor.done(); + + if (fErrorStatus.getChildren().length > 0) { + status = fErrorStatus; + fErrorStatus = new MultiStatus(SSEUIPlugin.ID, IStatus.ERROR, SSEUIMessages.FormatActionDelegate_errorStatusMessage, null); //$NON-NLS-1$ + } + + return status; + } + + } + + private MultiStatus fErrorStatus = new MultiStatus(SSEUIPlugin.ID, IStatus.ERROR, SSEUIMessages.FormatActionDelegate_errorStatusMessage, null); //$NON-NLS-1$ + + protected void format(IProgressMonitor monitor, IFile file) { + try { + monitor.beginTask("", 100); + IContentDescription contentDescription = file.getContentDescription(); + monitor.worked(5); + if (contentDescription != null) { + IContentType contentType = contentDescription.getContentType(); + IStructuredFormatProcessor formatProcessor = getFormatProcessor(contentType.getId()); + if (formatProcessor != null && (monitor == null || !monitor.isCanceled())) { + String message = NLS.bind(SSEUIMessages.FormatActionDelegate_3, new String[]{file.getFullPath().toString().substring(1)}); monitor.subTask(message); + formatProcessor.setProgressMonitor(monitor); + formatProcessor.formatFile(file); + } + } + monitor.worked(95); + monitor.done(); + } catch (MalformedInputExceptionWithDetail e) { + String message = NLS.bind(SSEUIMessages.FormatActionDelegate_5, new String[]{file.getFullPath().toString()}); + fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e)); + } catch (IOException e) { + String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[]{file.getFullPath().toString()}); + fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e)); + } catch (CoreException e) { + String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[]{file.getFullPath().toString()}); + fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e)); + } + } + + protected void format(IProgressMonitor monitor, IResource resource) { + if (resource instanceof IFile) { + IFile file = (IFile) resource; + + if (monitor == null || !monitor.isCanceled()) + format(monitor, file); + } else if (resource instanceof IContainer) { + IContainer container = (IContainer) resource; + + try { + IResource[] members = container.members(); + monitor.beginTask("", members.length); + for (int i = 0; i < members.length; i++) { + if (monitor == null || !monitor.isCanceled()) + format(new SubProgressMonitor(monitor, 1), members[i]); + } + monitor.done(); + } catch (CoreException e) { + String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[]{resource.getFullPath().toString()}); + fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e)); + } + } + } + + protected IStructuredFormatProcessor getFormatProcessor(String contentTypeId) { + return FormatProcessorsExtensionReader.getInstance().getFormatProcessor(contentTypeId); + } + + protected Job getJob() { + return new FormatJob(SSEUIMessages.FormatActionDelegate_jobName); //$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.sse.ui.edit.util.ResourceActionDelegate#process(org.eclipse.core.runtime.IProgressMonitor, + * org.eclipse.core.resources.IResource) + */ + protected void process(IProgressMonitor monitor, IResource resource) { + monitor.beginTask("", 100); + format(new SubProgressMonitor(monitor, 98), resource); + + try { + resource.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 2)); + } catch (CoreException e) { + String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[]{resource.getFullPath().toString()}); + fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e)); + } + monitor.done(); + } + + /* (non-Javadoc) + * @see org.eclipse.wst.sse.ui.internal.actions.ResourceActionDelegate#processorAvailable(org.eclipse.core.resources.IResource) + */ + protected boolean processorAvailable(IResource resource) { + boolean result = false; + if (resource.isAccessible()) { + try { + if (resource instanceof IFile) { + IFile file = (IFile) resource; + + IStructuredFormatProcessor formatProcessor = null; + IContentDescription contentDescription = file.getContentDescription(); + if (contentDescription != null) { + IContentType contentType = contentDescription.getContentType(); + formatProcessor = getFormatProcessor(contentType.getId()); + } + if (formatProcessor != null) + result = true; + } + else if (resource instanceof IContainer) { + IContainer container = (IContainer) resource; + IResource[] members; + members = container.members(); + for (int i = 0; i < members.length; i++) { + boolean available = processorAvailable(members[i]); + + if (available) { + result = true; + break; + } + } + } + } + catch (CoreException e) { + Logger.logException(e); + } + } + + return result; + } + +} #P org.eclipse.wst.xml.ui Index: plugin.properties =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.ui/plugin.properties,v retrieving revision 1.28 diff -u -r1.28 plugin.properties --- plugin.properties 31 Jan 2008 02:24:23 -0000 1.28 +++ plugin.properties 21 Feb 2008 04:24:38 -0000 @@ -10,7 +10,7 @@ # Jens Lukowski/Innoopract - initial renaming/restructuring # David Carver / STAR Standards - added XML Catalog Import/Export Wizard # bug 192568 -# +# David Carver / STAR Standards - bug 212330 - migrate to org.eclipse.ui.menus ############################################################################### providerName=Eclipse.org pluginName=XML UI Plugin @@ -75,6 +75,7 @@ StructureSelectPrevious_tooltip=Expand selection to include previous sibling StructureSelectHistory_label=Restore Last Selection StructureSelectHistory_tooltip=Restore last selection +SmartInsert_label=Sma&rt Auto Insert ## preferenceKeywords.files=editor xml creating saving files line delimiter suffix specified encoding iana validating warn grammar preferenceKeywords.source=editor xml source formatting line width split multiple attributes new clear blank indent tabs spaces size content assist automatically suggestions prompt characters inserted strategy lax strict grammar constraints inferred absence dtd schema @@ -83,4 +84,14 @@ preferenceKeywords.xmlcatalog=xml catalog entries ## XML_Source_target_name=XML Source -XML_hyperlink=Tags And Attributes \ No newline at end of file +XML_hyperlink=Tags And Attributes +## +DesignMenu_name=&Design +Format_mnemonic=F +FormatElements_mnemonic=i +ReloadDependencies_name=&Reload Dependencies +ReloadDependencies_description=Reload Dependencies +Constraints_name=&Turn off Grammar Constraints +Constraints_description=Turn off grammar Constraints +ExpandAll_name=Expand All +CollapseAll_name=Collapse All \ No newline at end of file Index: plugin.xml =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.ui/plugin.xml,v retrieving revision 1.77 diff -u -r1.77 plugin.xml --- plugin.xml 31 Jan 2008 02:24:23 -0000 1.77 +++ plugin.xml 21 Feb 2008 04:24:39 -0000 @@ -1,5 +1,5 @@ - + @@ -259,7 +259,8 @@ - + + - + + @@ -398,7 +402,7 @@ - + - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.ui/META-INF/MANIFEST.MF,v retrieving revision 1.27 diff -u -r1.27 MANIFEST.MF --- META-INF/MANIFEST.MF 30 Oct 2007 22:42:35 -0000 1.27 +++ META-INF/MANIFEST.MF 21 Feb 2008 04:24:39 -0000 @@ -54,6 +54,7 @@ org.eclipse.wst.xml.core;bundle-version="[1.1.0,1.2.0)", org.eclipse.wst.common.ui;bundle-version="[1.1.0,1.2.0)", org.eclipse.wst.validation;bundle-version="[1.1.0,1.2.0)", - com.ibm.icu;bundle-version="[3.4.4,4.0.0)" + com.ibm.icu;bundle-version="[3.4.4,4.0.0)", + org.eclipse.core.expressions;bundle-version="[3.3.0,4.0.0)" Eclipse-LazyStart: true Bundle-RequiredExecutionEnvironment: J2SE-1.4 Index: src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java,v retrieving revision 1.16 diff -u -r1.16 XMLTableTreeActionBarContributor.java --- src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java 10 Apr 2007 20:04:57 -0000 1.16 +++ src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java 21 Feb 2008 04:24:39 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * David Carver - bug 212330 - migrate to org.eclipse.ui.menus extension point *******************************************************************************/ package org.eclipse.wst.xml.ui.internal.tabletree; @@ -14,14 +15,14 @@ import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IContributionManager; import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; +//import org.eclipse.jface.action.IToolBarManager; +//import org.eclipse.jface.action.MenuManager; +//import org.eclipse.jface.action.Separator; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorSite; -import org.eclipse.ui.IWorkbenchActionConstants; +//import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.texteditor.ITextEditor; @@ -62,7 +63,7 @@ } protected void removeContributions(IContributionManager manager) { - try { +/* try { doRemove(manager, DESIGN_VIEWER_SEPARATOR_1_ID); doRemove(manager, DESIGN_VIEWER_SEPARATOR_2_ID); doRemove(manager, VALIDATE_XML_ID); @@ -73,26 +74,27 @@ } catch (Exception e) { } +*/ } protected void doRemove(IContributionManager manager, String id) { - try { +/* try { if (manager.find(id) != null) { manager.remove(id); } } catch (Exception e) { } - } +*/ } public void init(IActionBars bars, IWorkbenchPage page) { init(bars); } public void init(IActionBars bars) { - IToolBarManager tbm = bars.getToolBarManager(); +// IToolBarManager tbm = bars.getToolBarManager(); - IMenuManager xmlMenu = bars.getMenuManager().findMenuUsingPath("org.eclipse.core.runtime.xml.design.xmlmenu"); //$NON-NLS-1$ +/* IMenuManager xmlMenu = bars.getMenuManager().findMenuUsingPath("org.eclipse.core.runtime.xml.design.xmlmenu"); //$NON-NLS-1$ if (xmlMenu == null) { xmlMenu = new MenuManager(XMLEditorMessages.XMLTableTreeActionBarContributor_0, "org.eclipse.core.runtime.xml.design.xmlmenu"); //$NON-NLS-1$ @@ -103,7 +105,7 @@ } tbm.add(new Separator("DESIGN_VIEWER_SEPARATOR_1_ID")); //$NON-NLS-1$ - +*/ // ValidateXMLAction // // ugly hack ... we don't contribute the generic XML validator if we @@ -119,23 +121,23 @@ // ToggleEditModeAction // - toggleAction = new ToggleEditModeAction(); +/* toggleAction = new ToggleEditModeAction(); toggleAction.setId(TOGGLE_EDIT_MODE_ID); xmlMenu.add(toggleAction); tbm.add(toggleAction); - +*/ // ReloadGrammarAction // - reloadGrammarAction = new ReloadGrammarAction(); +/* reloadGrammarAction = new ReloadGrammarAction(); reloadGrammarAction.setId(RELOAD_GRAMMAR_ID); tbm.add(reloadGrammarAction); xmlMenu.add(reloadGrammarAction); xmlMenu.add(new Separator()); - +*/ // ExpandCollapseAction // - xmlMenuExpandAction = new ViewerExpandCollapseAction(true); +/* xmlMenuExpandAction = new ViewerExpandCollapseAction(true); xmlMenuExpandAction.setId(EXPAND_ALL_ID); xmlMenuExpandAction.setText(XMLEditorMessages.XMLTableTreeActionBarContributor_1); xmlMenu.add(xmlMenuExpandAction); @@ -145,6 +147,7 @@ xmlMenuCollapseAction.setId(EXPAND_ALL_ID); xmlMenuCollapseAction.setText(XMLEditorMessages.XMLTableTreeActionBarContributor_2); xmlMenu.add(xmlMenuCollapseAction); +*/ } protected void addActionWithId(IMenuManager menuManager, Action action, String id) { @@ -153,7 +156,7 @@ } public void initViewerSpecificContributions(IActionBars bars) { - IToolBarManager tbm = bars.getToolBarManager(); +/* IToolBarManager tbm = bars.getToolBarManager(); tbm.add(new Separator(DESIGN_VIEWER_SEPARATOR_2_ID)); expandAction = new ViewerExpandCollapseAction(true); @@ -163,10 +166,11 @@ collapseAction = new ViewerExpandCollapseAction(false); collapseAction.setId(COLLAPSE_ALL_ID); tbm.add(collapseAction); +*/ } public void setViewerSpecificContributionsEnabled(boolean enabled) { - if (expandAction != null) { +/* if (expandAction != null) { expandAction.setEnabled(enabled); xmlMenuExpandAction.setEnabled(enabled); } @@ -175,13 +179,14 @@ collapseAction.setEnabled(enabled); xmlMenuCollapseAction.setEnabled(enabled); } +*/ } public void setActiveEditor(IEditorPart targetEditor) { editorPart = targetEditor; - IStructuredModel model = getModelForEditorPart(targetEditor); - reloadGrammarAction.setModel(model); +// IStructuredModel model = getModelForEditorPart(targetEditor); +/* reloadGrammarAction.setModel(model); toggleAction.setModelQuery(ModelQueryUtil.getModelQuery(model)); XMLTableTreeViewer tableTreeViewer = getTableTreeViewerForEditorPart(editorPart); @@ -192,7 +197,7 @@ xmlMenuExpandAction.setViewer(tableTreeViewer); xmlMenuCollapseAction.setViewer(tableTreeViewer); } - +*/ if (editorPart instanceof XMLMultiPageEditorPart) { IWorkbenchPartSite site = editorPart.getSite(); if (site instanceof IEditorSite) { Index: src/org/eclipse/wst/xml/ui/internal/handlers/ExpandCollapseAllHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/ExpandCollapseAllHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/ExpandCollapseAllHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/ExpandCollapseAllHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Carver - initial API and implementation, bug 212330 + * + *******************************************************************************/ +package org.eclipse.wst.xml.ui.internal.handlers; + +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.commands.IElementUpdater; +import org.eclipse.ui.menus.UIElement; +import org.eclipse.wst.xml.ui.internal.tabletree.IDesignViewer; +import org.eclipse.wst.xml.ui.internal.tabletree.XMLTableTreeViewer; + +public class ExpandCollapseAllHandler extends AbstractHandler implements IElementUpdater { + + protected XMLTableTreeViewer viewer = null; + + /** + * Command handler for handling Expand and Collapse for Tree Viewer + */ + public ExpandCollapseAllHandler() { + super(); + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + // Implementors to put their code here. + + return null; + } + + protected XMLTableTreeViewer getTableTreeViewerForEditorPart(IEditorPart targetEditor) { + XMLTableTreeViewer result = null; + Object object = targetEditor.getAdapter(IDesignViewer.class); + if (object instanceof XMLTableTreeViewer) { + result = (XMLTableTreeViewer) object; + } + return result; + } + + public void updateElement(UIElement element, Map parameters) { + // TODO Auto-generated method stub + + } +} Index: src/org/eclipse/wst/xml/ui/internal/handlers/ReloadDependenciesHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/ReloadDependenciesHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/ReloadDependenciesHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/ReloadDependenciesHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Carver - initial API and implementation, bug 212330 + * + *******************************************************************************/ +package org.eclipse.wst.xml.ui.internal.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.sse.ui.StructuredTextEditor; +import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; +import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.CMDocumentLoader; +import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.InferredGrammarBuildingCMDocumentLoader; +import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; +import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart; +import org.w3c.dom.Document; + +public class ReloadDependenciesHandler extends AbstractHandler implements + IHandler { + protected IStructuredModel model; + + /** + * + */ + public ReloadDependenciesHandler() { + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + IEditorPart fEditor = HandlerUtil.getActiveEditor(event); + + if (fEditor instanceof XMLMultiPageEditorPart) { + StructuredTextEditor textEditor = (StructuredTextEditor) fEditor.getAdapter(ITextEditor.class); + model = (textEditor != null) ? textEditor.getModel() : null; + } + + if (model != null) { + ModelQuery modelQuery = ModelQueryUtil.getModelQuery(model); + Document document = ((IDOMModel) model).getDocument(); + if ((modelQuery != null) && (modelQuery.getCMDocumentManager() != null)) { + modelQuery.getCMDocumentManager().getCMDocumentCache().clear(); + // TODO... need to figure out how to access the + // DOMObserver via ModelQuery + // ...why? + CMDocumentLoader loader = new InferredGrammarBuildingCMDocumentLoader(document, modelQuery); + loader.loadCMDocuments(); + } + } + return null; + } +} Index: src/org/eclipse/wst/xml/ui/internal/handlers/RemoveBlockCommentHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/RemoveBlockCommentHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/RemoveBlockCommentHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/RemoveBlockCommentHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Carver - initial API and implementation, bug 212330 + * + *******************************************************************************/ +package org.eclipse.wst.xml.ui.internal.handlers; + +import org.eclipse.core.commands.IHandler; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.wst.sse.core.StructuredModelManager; +import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; +import org.eclipse.wst.xml.core.internal.document.CommentImpl; +import org.eclipse.wst.xml.ui.internal.Logger; +import org.eclipse.wst.xml.ui.internal.XMLUIMessages; + +/** + * @author dcarver + * + */ +public class RemoveBlockCommentHandler extends CommentHandler implements IHandler { + + public RemoveBlockCommentHandler() { + super(); + } + + void processAction(IDocument document, ITextSelection textSelection) { + IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); + if (model != null) { + try { + IndexedRegion selectionStartIndexedRegion = model.getIndexedRegion(textSelection.getOffset()); + IndexedRegion selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength()); + + if ((selectionStartIndexedRegion == null) || (selectionEndIndexedRegion == null)) { + return; + } + + int openCommentOffset = selectionStartIndexedRegion.getStartOffset(); + int closeCommentOffset = selectionEndIndexedRegion.getEndOffset() - OPEN_COMMENT.length() - CLOSE_COMMENT.length(); + + model.beginRecording(this, XMLUIMessages.RemoveBlockComment_tooltip); + model.aboutToChangeModel(); + + try { + if (textSelection.getLength() == 0) { + if (selectionStartIndexedRegion instanceof CommentImpl) { + document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ + document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ + } + } + else { + if (selectionStartIndexedRegion instanceof CommentImpl) { + document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ + } + + if (selectionEndIndexedRegion instanceof CommentImpl) { + document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ + } + } + removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); + } + catch (BadLocationException e) { + Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); + } + finally { + model.changedModel(); + model.endRecording(this); + } + } + finally { + model.releaseFromEdit(); + } + } + } +} Index: src/org/eclipse/wst/xml/ui/internal/handlers/CollapseAllHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/CollapseAllHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/CollapseAllHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/CollapseAllHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Carver - initial API and implementation, bug 212330 + * + *******************************************************************************/ + +package org.eclipse.wst.xml.ui.internal.handlers; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.handlers.HandlerUtil; + +public class CollapseAllHandler extends ExpandCollapseAllHandler implements IHandler { + + /** + * + */ + public CollapseAllHandler() { + super(); + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + IEditorPart editorPart = HandlerUtil.getActiveEditor(event); + + viewer = getTableTreeViewerForEditorPart(editorPart); + + if (viewer != null) { + // temporarily set the visibility to false + // this has a HUGE performance benefit + boolean isVisible = viewer.getControl().getVisible(); + viewer.getControl().setVisible(false); + viewer.collapseAll(); + + // restore the previous visibility state + // + viewer.getControl().setVisible(isVisible); + } + + return null; + } +} Index: src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLHandler.java =================================================================== RCS file: src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLHandler.java diff -N src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Carver - initial API and implementation, bug 212330 + * + *******************************************************************************/ +package org.eclipse.wst.xml.ui.internal.wizards; + +import java.util.Iterator; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.resources.IFile; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.handlers.HandlerUtil; + +public class NewXMLHandler extends AbstractHandler implements IHandler { + + /** + * + */ + public NewXMLHandler() { + super(); + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event); + ISelection selection = workbenchWindow.getSelectionService().getSelection(); + Object selectedObject = getSelection(selection); + + if ((selectedObject instanceof IFile) && (selection instanceof IStructuredSelection)) { + IFile file = (IFile) selectedObject; + IStructuredSelection structuredSelection = (IStructuredSelection) selection; + try { + NewXMLWizard.showDialog(workbenchWindow.getShell(), file, structuredSelection); + } + catch (Exception e) { + // XMLCorePlugin.getDefault().getLog().log(); + } + } + return null; + } + + public static Object getSelection(ISelection selection) { + if (selection == null) { + return null; + } + + Object result = null; + if (selection instanceof IStructuredSelection) { + IStructuredSelection es = (IStructuredSelection) selection; + Iterator i = es.iterator(); + if (i.hasNext()) { + result = i.next(); + } + } + return result; + } +} Index: src/org/eclipse/wst/xml/ui/internal/handlers/CleanupdocumentHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/CleanupdocumentHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/CleanupdocumentHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/CleanupdocumentHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Carver - initial API and implementation - bug 212330 - + * Based off CleanupActionXMLDelegate + *******************************************************************************/ + +package org.eclipse.wst.xml.ui.internal.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.wst.sse.core.StructuredModelManager; +import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupProcessor; +import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.sse.ui.internal.SSEUIMessages; +import org.eclipse.wst.xml.core.internal.cleanup.CleanupProcessorXML; +import org.eclipse.wst.xml.ui.internal.actions.CleanupDialogXML; +import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart; + +public class CleanupdocumentHandler extends AbstractHandler implements IHandler { + + private IEditorPart fEditor; + private IStructuredCleanupProcessor fCleanupProcessor; + + public void dispose() { + // nulling out just in case + fEditor = null; + fCleanupProcessor = null; + } + + public Object execute(ExecutionEvent event) throws ExecutionException { + fEditor = HandlerUtil.getActiveEditor(event); + + if (fEditor instanceof XMLMultiPageEditorPart) { + final ITextEditor editor = (ITextEditor) fEditor.getAdapter(ITextEditor.class); + Dialog cleanupDialog = new CleanupDialogXML(editor.getSite().getShell()); + if (cleanupDialog.open() == Window.OK) { + // setup runnable + Runnable runnable = new Runnable() { + public void run() { + IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor(); + if (cleanupProcessor != null) { + IStructuredModel model = null; + try { + model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput())); + if (model != null) { + cleanupProcessor.cleanupModel(model); + } + } + finally { + if (model != null) { + model.releaseFromEdit(); + } + } + } + } + }; + + // TODO: make independent of 'model'. + IStructuredModel model = null; + try { + model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput())); + if (model != null) { + // begin recording + ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); + model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_, SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength()); + + // tell the model that we are about to make a big + // model change + model.aboutToChangeModel(); + + // run + BusyIndicator.showWhile(fEditor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(), runnable); + } + } + finally { + if (model != null) { + // tell the model that we are done with the big + // model + // change + model.changedModel(); + + // end recording + ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); + model.endRecording(this, selection.getOffset(), selection.getLength()); + model.releaseFromEdit(); + } + } + } + } + + return null; + } + + IStructuredCleanupProcessor getCleanupProcessor() { + if (fCleanupProcessor == null) { + fCleanupProcessor = new CleanupProcessorXML(); + } + + return fCleanupProcessor; + } +} Index: src/org/eclipse/wst/xml/ui/internal/handlers/ToggleEditModeHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/ToggleEditModeHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/ToggleEditModeHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/ToggleEditModeHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Carver - initial API and implementation, bug 212330 + * + *******************************************************************************/ +package org.eclipse.wst.xml.ui.internal.handlers; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.commands.IElementUpdater; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.menus.UIElement; +import org.eclipse.ui.services.IServiceScopes; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.sse.ui.StructuredTextEditor; +import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; +import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; +import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; +import org.eclipse.wst.xml.ui.internal.tabletree.XMLEditorMessages; +import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart; +import org.eclipse.wst.xml.ui.internal.util.SharedXMLEditorPluginImageHelper; + +public class ToggleEditModeHandler extends AbstractHandler implements IElementUpdater { + protected ImageDescriptor onImage = SharedXMLEditorPluginImageHelper.getImageDescriptor(SharedXMLEditorPluginImageHelper.IMG_ETOOL_CONSTRAINON); + protected ImageDescriptor offImage = SharedXMLEditorPluginImageHelper.getImageDescriptor(SharedXMLEditorPluginImageHelper.IMG_ETOOL_CONSTRAINOFF); + protected ModelQuery modelQuery; + + public ToggleEditModeHandler() { + super(); + } + + public Object execute(ExecutionEvent event) throws ExecutionException { + IEditorPart editor = HandlerUtil.getActiveEditor(event); + IStructuredModel model = getModelForEditorPart(editor); + + modelQuery = ModelQueryUtil.getModelQuery(model); + + if (modelQuery != null) { + int newState = getNextState(modelQuery.getEditMode()); + modelQuery.setEditMode(newState); + + // Force a Refresh on this command so that the image can be updated. + ICommandService commandService = (ICommandService) HandlerUtil.getActiveWorkbenchWindow(event).getService(ICommandService.class); + Map filter = new HashMap(); + filter.put(IServiceScopes.WINDOW_SCOPE, HandlerUtil.getActiveWorkbenchWindow(event)); + commandService.refreshElements(event.getCommand().getId(), filter); + } + + return null; + } + + public int getNextState(int editMode) { + int result = -1; + if (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) { + result = ModelQuery.EDIT_MODE_UNCONSTRAINED; + } + else { + result = ModelQuery.EDIT_MODE_CONSTRAINED_STRICT; + } + return result; + } + + + // Handlers that need to interact with the ui that the command came from need to use implement this method. + public void updateElement(UIElement element, Map parameters) { + IEditorPart editor = XMLUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + IStructuredModel model = getModelForEditorPart(editor); + modelQuery = ModelQueryUtil.getModelQuery(model); + + if (modelQuery != null) { + setAppearanceForEditMode(modelQuery.getEditMode(), element); + } + + + } + + public void setAppearanceForEditMode(int editMode, UIElement element) { + if (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) { + element.setTooltip(XMLEditorMessages.XMLTableTreeActionBarContributor_3); + element.setText(XMLEditorMessages.XMLTableTreeActionBarContributor_4); + element.setIcon(onImage); + } + else { + element.setTooltip(XMLEditorMessages.XMLTableTreeActionBarContributor_5); + element.setText(XMLEditorMessages.XMLTableTreeActionBarContributor_6); + element.setIcon(offImage); + } + } + + protected IStructuredModel getModelForEditorPart(IEditorPart targetEditor) { + IStructuredModel result = null; + if (targetEditor instanceof XMLMultiPageEditorPart) { + StructuredTextEditor textEditor = (StructuredTextEditor) targetEditor.getAdapter(ITextEditor.class); + result = (textEditor != null) ? textEditor.getModel() : null; + } + return result; + } +} Index: src/org/eclipse/wst/xml/ui/internal/handlers/XMLFindOccurencesHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/XMLFindOccurencesHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/XMLFindOccurencesHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/XMLFindOccurencesHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2007 Standards for Technology in Automotive Retail and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Carver - initial API and implementation - bug 212330 - + * Based off CleanupActionXMLDelegate + *******************************************************************************/ + +package org.eclipse.wst.xml.ui.internal.handlers; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.resources.IFile; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.ITypedRegion; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.wst.sse.ui.internal.SSEUIMessages; +import org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor; +import org.eclipse.wst.sse.ui.internal.util.PlatformStatusLineUtil; +import org.eclipse.wst.xml.ui.internal.search.XMLFindOccurrencesProcessor; +import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart; + +public class XMLFindOccurencesHandler extends AbstractHandler implements IHandler { + + private IEditorPart fEditor; + private List fProcessors; + + public void dispose() { + // nulling out just in case + fEditor = null; + } + + public Object execute(ExecutionEvent event) throws ExecutionException { + fEditor = HandlerUtil.getActiveEditor(event); + boolean okay = false; + + if (fEditor instanceof XMLMultiPageEditorPart) { + final ITextEditor textEditor = (ITextEditor) fEditor.getAdapter(ITextEditor.class); + IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); + if (document != null) { + ITextSelection textSelection = getTextSelection(textEditor); + FindOccurrencesProcessor findOccurrenceProcessor = getProcessorForCurrentSelection(document, textSelection); + if (findOccurrenceProcessor != null) { + if (textEditor.getEditorInput() instanceof IFileEditorInput) { + IFile file = ((IFileEditorInput) textEditor.getEditorInput()).getFile(); + okay = findOccurrenceProcessor.findOccurrences(document, textSelection, file); + } + } + } + } + if (okay) { + // clear status message + PlatformStatusLineUtil.clearStatusLine(); + } + else { + String errorMessage = SSEUIMessages.FindOccurrencesActionProvider_0; //$NON-NLS-1$ + PlatformStatusLineUtil.displayErrorMessage(errorMessage); + PlatformStatusLineUtil.addOneTimeClearListener(); + } + + return null; + } + + /** + * Get the appropriate find occurrences processor + * + * @param document - + * assumes not null + * @param textSelection + * @return FindOccurrencesProcessor + */ + private FindOccurrencesProcessor getProcessorForCurrentSelection(IDocument document, ITextSelection textSelection) { + // check if we have an action that's enabled on the current partition + ITypedRegion tr = getPartition(document, textSelection); + String partition = tr != null ? tr.getType() : ""; //$NON-NLS-1$ + + Iterator it = getProcessors().iterator(); + FindOccurrencesProcessor action = null; + while (it.hasNext()) { + action = (FindOccurrencesProcessor) it.next(); + // we just choose the first action that can handle the partition + if (action.enabledForParitition(partition)) + return action; + } + return null; + } + + private ITypedRegion getPartition(IDocument document, ITextSelection textSelection) { + ITypedRegion region = null; + if (textSelection != null) { + try { + region = document.getPartition(textSelection.getOffset()); + } + catch (BadLocationException e) { + region = null; + } + } + return region; + } + + private ITextSelection getTextSelection(ITextEditor textEditor) { + ITextSelection textSelection = null; + ISelection selection = textEditor.getSelectionProvider().getSelection(); + if (selection instanceof ITextSelection && !selection.isEmpty()) { + textSelection = (ITextSelection) selection; + } + return textSelection; + } + + protected List getProcessors() { + if (fProcessors == null) { + fProcessors = new ArrayList(); + XMLFindOccurrencesProcessor htmlProcessor = new XMLFindOccurrencesProcessor(); + fProcessors.add(htmlProcessor); + } + return fProcessors; + } +} Index: src/org/eclipse/wst/xml/ui/internal/handlers/ExpandAllHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/ExpandAllHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/ExpandAllHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/ExpandAllHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Carver - initial API and implementation, bug 212330 + * + *******************************************************************************/ +package org.eclipse.wst.xml.ui.internal.handlers; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.wst.xml.ui.internal.tabletree.XMLTableTreeViewer; + +public class ExpandAllHandler extends ExpandCollapseAllHandler { + + protected XMLTableTreeViewer viewer = null; + + /** + * + */ + public ExpandAllHandler() { + super(); + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + + IEditorPart editorPart = HandlerUtil.getActiveEditor(event); + + viewer = getTableTreeViewerForEditorPart(editorPart); + + if (viewer != null) { + // temporarily set the visibility to false + // this has a HUGE performance benefit + boolean isVisible = viewer.getControl().getVisible(); + viewer.getControl().setVisible(false); + viewer.expandAll(); + + // restore the previous visibility state + // + viewer.getControl().setVisible(isVisible); + } + + return null; + } +} Index: src/org/eclipse/wst/xml/ui/internal/handlers/AddBlockCommentHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/AddBlockCommentHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/AddBlockCommentHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/AddBlockCommentHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Carver - initial API and implementation, bug 212330 + * + *******************************************************************************/ +package org.eclipse.wst.xml.ui.internal.handlers; + +import org.eclipse.core.commands.IHandler; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.wst.sse.core.StructuredModelManager; +import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; +import org.eclipse.wst.xml.core.internal.document.CommentImpl; +import org.eclipse.wst.xml.ui.internal.Logger; +import org.eclipse.wst.xml.ui.internal.XMLUIMessages; + +public class AddBlockCommentHandler extends CommentHandler implements IHandler { + + public AddBlockCommentHandler() { + super(); + } + + void processAction(IDocument document, ITextSelection textSelection) { + IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); + if (model != null) { + try { + IndexedRegion selectionStartIndexedRegion = model.getIndexedRegion(textSelection.getOffset()); + IndexedRegion selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength()); + + if (selectionStartIndexedRegion == null) { + return; + } + if ((selectionEndIndexedRegion == null) && (textSelection.getLength() > 0)) { + selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength() - 1); + } + if (selectionEndIndexedRegion == null) { + return; + } + + int openCommentOffset = selectionStartIndexedRegion.getStartOffset(); + int closeCommentOffset = selectionEndIndexedRegion.getEndOffset() + OPEN_COMMENT.length(); + + if ((textSelection.getLength() == 0) && (selectionStartIndexedRegion instanceof CommentImpl)) { + return; + } + + model.beginRecording(this, XMLUIMessages.AddBlockComment_tooltip); + model.aboutToChangeModel(); + + try { + document.replace(openCommentOffset, 0, OPEN_COMMENT); + document.replace(closeCommentOffset, 0, CLOSE_COMMENT); + super.removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); + } + catch (BadLocationException e) { + Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); + } + finally { + model.changedModel(); + model.endRecording(this); + } + } + finally { + model.releaseFromEdit(); + } + } + } +} Index: src/org/eclipse/wst/xml/ui/internal/handlers/ToggleCommentHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/ToggleCommentHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/ToggleCommentHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/ToggleCommentHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,193 @@ +/******************************************************************************* + * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Carver - initial API and implementation, bug 212330 + * + *******************************************************************************/ +package org.eclipse.wst.xml.ui.internal.handlers; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.TextSelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.wst.sse.core.StructuredModelManager; +import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.xml.ui.internal.Logger; +import org.eclipse.wst.xml.ui.internal.XMLUIMessages; +import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart; + +public class ToggleCommentHandler extends CommentHandler implements IHandler { + + public ToggleCommentHandler() { + // TODO Auto-generated constructor stub + super(); + } + + public Object execute(ExecutionEvent event) throws ExecutionException { + + fEditor = HandlerUtil.getActiveEditor(event); + + if (fEditor instanceof XMLMultiPageEditorPart) { + final ITextEditor textEditor = (ITextEditor) fEditor.getAdapter(ITextEditor.class); + fEditor = textEditor; + IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); + if (document != null) { + // get current text selection + ITextSelection textSelection = getCurrentSelection(); + if (textSelection.isEmpty()) { + return null; + } + + processAction(document, textSelection); + } + } + return null; + } + + void processAction(IDocument document, ITextSelection textSelection) { + // get text selection lines info + int selectionStartLine = textSelection.getStartLine(); + int selectionEndLine = textSelection.getEndLine(); + try { + int selectionEndLineOffset = document.getLineOffset(selectionEndLine); + int selectionEndOffset = textSelection.getOffset() + textSelection.getLength(); + + // adjust selection end line + if ((selectionEndLine > selectionStartLine) && (selectionEndLineOffset == selectionEndOffset)) { + selectionEndLine--; + } + + } + catch (BadLocationException e) { + Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); + } + + // save the selection position since it will be changing + Position selectionPosition = null; + boolean updateStartOffset = false; + try { + selectionPosition = new Position(textSelection.getOffset(), textSelection.getLength()); + document.addPosition(selectionPosition); + + // extra check if commenting from beginning of line + int selectionStartLineOffset = document.getLineOffset(selectionStartLine); + if ((textSelection.getLength() > 0) && (selectionStartLineOffset == textSelection.getOffset()) && !isCommentLine(document, selectionStartLine)) { + updateStartOffset = true; + } + } + catch (BadLocationException e) { + Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); + } + + processAction(document, selectionStartLine, selectionEndLine); + + updateCurrentSelection(selectionPosition, document, updateStartOffset); + } + + private void processAction(IDocument document, int selectionStartLine, int selectionEndLine) { + IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); + if (model != null) { + try { + model.beginRecording(this, XMLUIMessages.ToggleComment_tooltip); + model.aboutToChangeModel(); + + for (int i = selectionStartLine; i <= selectionEndLine; i++) { + try { + if (document.getLineLength(i) > 0) { + if (isCommentLine(document, i)) { + int lineOffset = document.getLineOffset(i); + IRegion region = document.getLineInformation(i); + String string = document.get(region.getOffset(), region.getLength()); + int openCommentOffset = lineOffset + string.indexOf(OPEN_COMMENT); + int closeCommentOffset = lineOffset + string.indexOf(CLOSE_COMMENT) - OPEN_COMMENT.length(); + uncomment(document, openCommentOffset, closeCommentOffset); + } + else { + int openCommentOffset = document.getLineOffset(i); + int lineDelimiterLength = document.getLineDelimiter(i) == null ? 0 : document.getLineDelimiter(i).length(); + int closeCommentOffset = openCommentOffset + document.getLineLength(i) - lineDelimiterLength + OPEN_COMMENT.length(); + comment(document, openCommentOffset, closeCommentOffset); + } + } + } + catch (BadLocationException e) { + Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); + } + } + } + finally { + model.changedModel(); + model.endRecording(this); + model.releaseFromEdit(); + } + } + } + + private boolean isCommentLine(IDocument document, int line) { + boolean isComment = false; + + try { + IRegion region = document.getLineInformation(line); + String string = document.get(region.getOffset(), region.getLength()).trim(); + isComment = (string.length() >= OPEN_COMMENT.length() + CLOSE_COMMENT.length()) && string.startsWith(OPEN_COMMENT) && string.endsWith(CLOSE_COMMENT); + } + catch (BadLocationException e) { + Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); + } + return isComment; + } + + private void comment(IDocument document, int openCommentOffset, int closeCommentOffset) { + try { + document.replace(openCommentOffset, 0, OPEN_COMMENT); + document.replace(closeCommentOffset, 0, CLOSE_COMMENT); + removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); + } + catch (BadLocationException e) { + Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); + } + } + + private void uncomment(IDocument document, int openCommentOffset, int closeCommentOffset) { + try { + document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ + document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ + } + catch (BadLocationException e) { + Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); + } + } + + private void updateCurrentSelection(Position selectionPosition, IDocument document, boolean updateStartOffset) { + if (fEditor instanceof ITextEditor) { + // update the selection if text selection changed + if (selectionPosition != null) { + ITextSelection selection = null; + if (updateStartOffset) { + selection = new TextSelection(document, selectionPosition.getOffset() - OPEN_COMMENT.length(), selectionPosition.getLength() + OPEN_COMMENT.length()); + } + else { + selection = new TextSelection(document, selectionPosition.getOffset(), selectionPosition.getLength()); + } + ISelectionProvider provider = ((ITextEditor) fEditor).getSelectionProvider(); + if (provider != null) { + provider.setSelection(selection); + } + document.removePosition(selectionPosition); + } + } + } +} Index: src/org/eclipse/wst/xml/ui/internal/handlers/CommentHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/CommentHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/CommentHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/CommentHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Carver - initial API and implementation, bug 212330 + * + *******************************************************************************/ +package org.eclipse.wst.xml.ui.internal.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.TextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.wst.xml.ui.internal.Logger; +import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart; + +public class CommentHandler extends AbstractHandler implements IHandler { + + + static final String CLOSE_COMMENT = "-->"; //$NON-NLS-1$ + static final String OPEN_COMMENT = "