You are viewing a plain text version of this content. The canonical link for it is here.
Posted to doxia-commits@maven.apache.org by vs...@apache.org on 2008/04/07 15:18:37 UTC
svn commit: r645502 [3/4] - in
/maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui:
./ icons/ icons/dtool16/ icons/etool16/ lib/ src/ src/main/ src/main/java/
src/main/java/org/ src/main/java/org/apache...
Added: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/dialogs/AddTableDialog.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/dialogs/AddTableDialog.java?rev=645502&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/dialogs/AddTableDialog.java (added)
+++ maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/dialogs/AddTableDialog.java Mon Apr 7 06:18:18 2008
@@ -0,0 +1,304 @@
+package org.apache.maven.doxia.ide.eclipse.common.ui.dialogs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.ide.eclipse.common.ui.CommonPluginMessages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Dialog to add a table in a Doxia document.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.0
+ */
+public class AddTableDialog
+ extends AbstractDialog
+{
+ private static final String[] TABLE_STYLE_LABELS = {
+ getString( "style.centered.label" ),
+ getString( "style.leftAligned.label" ),
+ getString( "style.rightAligned.label" ) };
+
+ /** Default rows number */
+ private static final int DEFAULT_ROWS = 2;
+
+ /** Default columns number */
+ private static final int DEFAULT_COLUMNS = 2;
+
+ private Table table = new Table();
+
+ private Text rowsText;
+
+ private Text colsText;
+
+ private Combo tableTypeCombo;
+
+ private Text captionText;
+
+ private ModifyListener modifyListener = new ModifyListener()
+ {
+ /** {@inheritDoc} */
+ public void modifyText( ModifyEvent event )
+ {
+ if ( okButton != null )
+ {
+ try
+ {
+ int rows = Integer.parseInt( rowsText.getText().trim() );
+ int cols = Integer.parseInt( colsText.getText().trim() );
+
+ okButton.setEnabled( rows > 0 && cols > 0 );
+ }
+ catch ( Exception e )
+ {
+ okButton.setEnabled( false );
+ }
+ }
+ }
+ };
+
+ /**
+ * Default constructor.
+ *
+ * @param parent
+ */
+ public AddTableDialog( Shell parent )
+ {
+ super( parent );
+ }
+
+ // ----------------------------------------------------------------------
+ // Public methods
+ // ----------------------------------------------------------------------
+
+ /**
+ * Gets the user specified table.
+ *
+ * @return an <code>Table</code> object
+ */
+ public Table getTable()
+ {
+ return table;
+ }
+
+ // ----------------------------------------------------------------------
+ // Protected methods
+ // ----------------------------------------------------------------------
+
+ @Override
+ protected Control createDialogArea( Composite parent )
+ {
+ Composite composite = (Composite) super.createDialogArea( parent );
+
+ Label rowsLabel = new Label( composite, SWT.NONE );
+ rowsLabel.setText( getString( "rows.label" ) );
+
+ rowsText = new Text( composite, SWT.BORDER );
+ rowsText.setTextLimit( 2 );
+ rowsText.setText( String.valueOf( DEFAULT_ROWS ) );
+ {
+ GridData gridData = new GridData( GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL );
+ rowsText.setLayoutData( gridData );
+ }
+ rowsText.addModifyListener( modifyListener );
+
+ Label colsLabel = new Label( composite, SWT.NONE );
+ colsLabel.setText( getString( "columns.label" ) );
+
+ colsText = new Text( composite, SWT.BORDER );
+ colsText.setTextLimit( 2 );
+ colsText.setText( String.valueOf( DEFAULT_COLUMNS ) );
+ {
+ GridData gridData = new GridData( GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL );
+ colsText.setLayoutData( gridData );
+ }
+ colsText.addModifyListener( modifyListener );
+
+ Label headerTypeLabel = new Label( composite, SWT.NONE );
+ headerTypeLabel.setText( getString( "style.label" ) );
+
+ tableTypeCombo = new Combo( composite, SWT.BORDER | SWT.READ_ONLY );
+ tableTypeCombo.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+ tableTypeCombo.setItems( TABLE_STYLE_LABELS );
+ tableTypeCombo.setText( TABLE_STYLE_LABELS[1] );
+
+ Label captionLabel = new Label( composite, SWT.NONE );
+ captionLabel.setText( getString( "caption.label" ) );
+ captionText = new Text( composite, SWT.BORDER );
+ {
+ GridData gridData = new GridData( GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL );
+ captionText.setLayoutData( gridData );
+ }
+
+ super.getShell().setText( getString( "title.label" ) );
+
+ return composite;
+ }
+
+ @Override
+ protected void createButtonsForButtonBar( Composite parent )
+ {
+ super.createButtonsForButtonBar( parent );
+ }
+
+ @Override
+ protected void okPressed()
+ {
+ String rowsValue = rowsText.getText();
+ if ( rowsValue != null && rowsValue.length() > 0 )
+ {
+ try
+ {
+ int rows = Integer.parseInt( rowsValue );
+ table.setRows( rows );
+ }
+ catch ( Exception e )
+ {
+ table.setRows( DEFAULT_ROWS );
+ }
+ }
+
+ String colsValue = colsText.getText();
+ if ( colsValue != null && colsValue.length() > 0 )
+ {
+ try
+ {
+ int cols = Integer.parseInt( colsValue );
+ table.setColumns( cols );
+ }
+ catch ( Exception e )
+ {
+ table.setColumns( DEFAULT_COLUMNS );
+ }
+ }
+
+ table.setCaption( captionText.getText().trim() );
+ table.setTableStyle( tableTypeCombo.getSelectionIndex() );
+
+ super.okPressed();
+ }
+
+ /**
+ * Table bean.
+ */
+ public class Table
+ {
+ public static final int TABLE_STYLE_CENTERED = 0;
+
+ public static final int TABLE_STYLE_LEFTALIGNED = 1;
+
+ public static final int TABLE_STYLE_RIGHTALIGNED = 2;
+
+ private int rows = 2;
+
+ private int columns = 2;
+
+ private int tableStyle = 0;
+
+ private String caption;
+
+ public Table()
+ {
+ }
+
+ /**
+ * @return the number of rows
+ */
+ public int getRows()
+ {
+ return rows;
+ }
+
+ /**
+ * @param rows the number of rows
+ */
+ public void setRows( int rows )
+ {
+ this.rows = rows;
+ }
+
+ /**
+ * @return the number of columns
+ */
+ public int getColumns()
+ {
+ return columns;
+ }
+
+ /**
+ * @param cols the number of columns
+ */
+ public void setColumns( int cols )
+ {
+ this.columns = cols;
+ }
+
+ /**
+ * @return the table caption
+ */
+ public String getCaption()
+ {
+ return caption;
+ }
+
+ /**
+ * @param caption the table caption
+ */
+ public void setCaption( String caption )
+ {
+ this.caption = caption;
+ }
+
+ /**
+ * @return the table style.
+ */
+ public int getTableStyle()
+ {
+ return tableStyle;
+ }
+
+ /**
+ * @param tableStyle
+ */
+ public void setTableStyle( int tableStyle )
+ {
+ this.tableStyle = tableStyle;
+ }
+ }
+
+ // ----------------------------------------------------------------------
+ // Private methods
+ // ----------------------------------------------------------------------
+
+ private static String getString( String subkey )
+ {
+ return CommonPluginMessages.getString( "AddTableDialog." + subkey );
+ }
+}
\ No newline at end of file
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/dialogs/AddTableDialog.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/dialogs/AddTableDialog.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractEditorContributor.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractEditorContributor.java?rev=645502&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractEditorContributor.java (added)
+++ maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractEditorContributor.java Mon Apr 7 06:18:18 2008
@@ -0,0 +1,137 @@
+package org.apache.maven.doxia.ide.eclipse.common.ui.editors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.ide.eclipse.common.ui.actions.IActionConstants;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.ide.IDEActionFactory;
+import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+
+/**
+ * Manages the installation/deinstallation of global actions for multi-page editors.
+ * Responsible for the redirection of global actions to the active editor.
+ * Multi-page contributor replaces the contributors for the individual editors in the multi-page editor.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.0
+ */
+public abstract class AbstractEditorContributor
+ extends MultiPageEditorActionBarContributor
+{
+ private IEditorPart activeEditorPart;
+
+ /**
+ * Creates a multi-page contributor.
+ */
+ public AbstractEditorContributor()
+ {
+ super();
+ }
+
+ /**
+ * Returns the action registed with the given text editor.
+ * @return IAction or null if editor is null.
+ */
+ protected IAction getAction( ITextEditor editor, String actionID )
+ {
+ return ( editor == null ? null : editor.getAction( actionID ) );
+ }
+
+ @Override
+ public void setActivePage( IEditorPart part )
+ {
+ if ( activeEditorPart == part )
+ {
+ return;
+ }
+
+ activeEditorPart = part;
+
+ IActionBars actionBars = getActionBars();
+ if ( actionBars != null )
+ {
+ ITextEditor editor = ( part instanceof ITextEditor ) ? (ITextEditor) part : null;
+
+ // Generic
+ actionBars.setGlobalActionHandler( ActionFactory.DELETE.getId(),
+ getAction( editor, ITextEditorActionConstants.DELETE ) );
+ actionBars
+ .setGlobalActionHandler( ActionFactory.UNDO.getId(),
+ getAction( editor, ITextEditorActionConstants.UNDO ) );
+ actionBars
+ .setGlobalActionHandler( ActionFactory.REDO.getId(),
+ getAction( editor, ITextEditorActionConstants.REDO ) );
+ actionBars.setGlobalActionHandler( ActionFactory.CUT.getId(), getAction( editor,
+ ITextEditorActionConstants.CUT ) );
+ actionBars
+ .setGlobalActionHandler( ActionFactory.COPY.getId(),
+ getAction( editor, ITextEditorActionConstants.COPY ) );
+ actionBars.setGlobalActionHandler( ActionFactory.PASTE.getId(),
+ getAction( editor, ITextEditorActionConstants.PASTE ) );
+ actionBars.setGlobalActionHandler( ActionFactory.SELECT_ALL.getId(),
+ getAction( editor, ITextEditorActionConstants.SELECT_ALL ) );
+ actionBars
+ .setGlobalActionHandler( ActionFactory.FIND.getId(),
+ getAction( editor, ITextEditorActionConstants.FIND ) );
+ actionBars.setGlobalActionHandler( IDEActionFactory.BOOKMARK.getId(), getAction( editor,
+ IDEActionFactory.BOOKMARK
+ .getId() ) );
+
+ // Doxia Specific actions
+ actionBars.setGlobalActionHandler( IActionConstants.BOLD_ACTION, getAction( editor,
+ IActionConstants.BOLD_ACTION ) );
+ actionBars.setGlobalActionHandler( IActionConstants.ITALIC_ACTION,
+ getAction( editor, IActionConstants.ITALIC_ACTION ) );
+ actionBars.setGlobalActionHandler( IActionConstants.MONOSPACED_ACTION,
+ getAction( editor, IActionConstants.MONOSPACED_ACTION ) );
+ actionBars.setGlobalActionHandler( IActionConstants.LINK_ACTION, getAction( editor,
+ IActionConstants.LINK_ACTION ) );
+ actionBars
+ .setGlobalActionHandler( IActionConstants.TABLE_ACTION, getAction( editor,
+ IActionConstants.TABLE_ACTION ) );
+
+ actionBars.updateActionBars();
+ }
+ }
+
+ @Override
+ public void contributeToMenu( IMenuManager menuManager )
+ {
+ super.contributeToMenu( menuManager );
+
+ // Using extensions in plugin.xml instead of
+ }
+
+ @Override
+ public void contributeToToolBar( IToolBarManager toolBarManager )
+ {
+ super.contributeToToolBar( toolBarManager );
+
+ // Using extensions in plugin.xml instead of
+ }
+}
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractEditorContributor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractEditorContributor.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractMultiPageEditorPart.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractMultiPageEditorPart.java?rev=645502&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractMultiPageEditorPart.java (added)
+++ maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractMultiPageEditorPart.java Mon Apr 7 06:18:18 2008
@@ -0,0 +1,521 @@
+package org.apache.maven.doxia.ide.eclipse.common.ui.editors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.ide.eclipse.common.ui.CommonPlugin;
+import org.apache.maven.doxia.ide.eclipse.common.ui.CommonPluginMessages;
+import org.apache.maven.doxia.ide.eclipse.common.ui.DoxiaWrapper;
+import org.apache.maven.doxia.ide.eclipse.common.ui.composites.BrowserComposite;
+import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.SubContributionItem;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IPropertyListener;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPartConstants;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.ide.IGotoMarker;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.part.MultiPageEditorPart;
+
+/**
+ * Abstract Doxia multipage editor.
+ * <br/>
+ * Doxia editor has 2 pages:
+ * <dl>
+ * <dt>Page 0: edit</dt>
+ * <dd>Nested text editor.</dd>
+ * <dt>page 1: view</dt>
+ * <dd>Nested browser.</dd>
+ * </dl>
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.0
+ */
+public abstract class AbstractMultiPageEditorPart
+ extends MultiPageEditorPart
+ implements IResourceChangeListener, IPropertyListener
+{
+ /** The nested text editor used in page 0. */
+ private TextEditor textEditor;
+
+ /** The editor page id, should be 0. */
+ private int editorPageId;
+
+ /** The nested browser used in page 1. */
+ private BrowserComposite browser;
+
+ /** The browser page id, should be 1. */
+ private int browserPageId;
+
+ /**
+ * Creates a multi-page editor.
+ */
+ public AbstractMultiPageEditorPart()
+ {
+ super();
+
+ ResourcesPlugin.getWorkspace().addResourceChangeListener( this );
+
+ Assert.isNotNull( getFormat(), "getFormat() should be defined" );
+ Assert.isNotNull( getTextEditor(), "getTextEditor() should be defined" );
+ }
+
+ @Override
+ protected void createPages()
+ {
+ try
+ {
+ setPartName( getEditorInput().getName() );
+
+ createEditPage();
+ createBrowserPage();
+
+ // TODO add a design page
+ }
+ catch ( PartInitException e )
+ {
+ String msg = ( StringUtils.isEmpty( e.getMessage() ) ? e.getClass().getName() : e.getMessage() );
+ ErrorDialog.openError( getSite().getShell(), getString( "PartInitException.text" ), msg, e.getStatus() );
+
+ throw new RuntimeException( e );
+ }
+
+ try
+ {
+ browser.convert();
+ }
+ catch ( Throwable e )
+ {
+ String msg = ( StringUtils.isEmpty( e.getMessage() ) ? e.getClass().getName() : e.getMessage() );
+ ErrorDialog.openError( getSite().getShell(), getString( "ConverterThrowable.message.text" ), msg, null );
+
+ throw new RuntimeException( e );
+ }
+ }
+
+ @Override
+ public void init( IEditorSite site, IEditorInput editorInput )
+ throws PartInitException
+ {
+ if ( !( editorInput instanceof IFileEditorInput ) )
+ {
+ throw new PartInitException( "Invalid Input: Must be IFileEditorInput" );
+ }
+
+ super.init( site, editorInput );
+ }
+
+ @Override
+ public void dispose()
+ {
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener( this );
+
+ super.dispose();
+ }
+
+ @Override
+ public void doSave( IProgressMonitor monitor )
+ {
+ if ( !isSaveAsAllowed() )
+ {
+ boolean okToSave = MessageDialog.openConfirm( getSite().getShell(),
+ getString( "doSave.openConfirm.title.text" ),
+ getString( "doSave.openConfirm.message.text" ) );
+ if ( !okToSave )
+ {
+ return;
+ }
+ }
+
+ getEditor( editorPageId ).doSave( monitor );
+
+ try
+ {
+ browser.convert();
+ }
+ catch ( Throwable e )
+ {
+ String msg = ( StringUtils.isEmpty( e.getMessage() ) ? e.getClass().getName() : e.getMessage() );
+ ErrorDialog.openError( getSite().getShell(), getString( "ConverterThrowable.message.text" ), msg, null );
+
+ throw new RuntimeException( e );
+ }
+ }
+
+ @Override
+ public void doSaveAs()
+ {
+ if ( !isSaveAsAllowed() )
+ {
+ boolean okToSave = MessageDialog.openConfirm( getSite().getShell(),
+ getString( "doSave.openConfirm.title.text" ),
+ getString( "doSave.openConfirm.message.text" ) );
+ if ( !okToSave )
+ {
+ return;
+ }
+ }
+
+ IEditorPart editor = getEditor( editorPageId );
+ editor.doSaveAs();
+ setPageText( editorPageId, editor.getTitle() );
+ setInput( editor.getEditorInput() );
+
+ try
+ {
+ browser.convert();
+ }
+ catch ( Throwable e )
+ {
+ String msg = ( StringUtils.isEmpty( e.getMessage() ) ? e.getClass().getName() : e.getMessage() );
+ ErrorDialog.openError( getSite().getShell(), getString( "ConverterThrowable.message.text" ), msg, null );
+
+ throw new RuntimeException( e );
+ }
+ }
+
+ @Override
+ public boolean isSaveAsAllowed()
+ {
+ try
+ {
+ return getDoxiaFile().findMarkers( null, true, IResource.DEPTH_ZERO ).length == 0;
+ }
+ catch ( CoreException ce )
+ {
+ String msg = ( StringUtils.isEmpty( ce.getMessage() ) ? ce.getClass().getName() : ce.getMessage() );
+ ErrorDialog
+ .openError( getSite().getShell(), getString( "CoreException.message.text" ), msg, ce.getStatus() );
+
+ return false;
+ }
+ }
+
+ @Override
+ protected void pageChange( int newPageIndex )
+ {
+ IMarker[] markers = null;
+ try
+ {
+ markers = getDoxiaFile().findMarkers( IMarker.PROBLEM, true, IResource.DEPTH_INFINITE );
+ }
+ catch ( CoreException ce )
+ {
+ String msg = ( StringUtils.isEmpty( ce.getMessage() ) ? ce.getClass().getName() : ce.getMessage() );
+ ErrorDialog
+ .openError( getSite().getShell(), getString( "CoreException.message.text" ), msg, ce.getStatus() );
+ }
+
+ if ( newPageIndex == browserPageId )
+ {
+ updateToolbar( false );
+ updateEditMenu( false );
+ }
+ else
+ {
+ updateToolbar( true );
+ updateEditMenu( true );
+ }
+
+ if ( newPageIndex == browserPageId && isDirty() )
+ {
+ boolean okToSave = MessageDialog.openConfirm( getSite().getShell(),
+ getString( "pageChange.openConfirm.title.text" ),
+ getString( "pageChange.openConfirm.message.text" ) );
+ if ( okToSave )
+ {
+ IProgressMonitor monitor = null;
+ try
+ {
+ if ( monitor == null )
+ {
+ monitor = new NullProgressMonitor();
+ monitor.beginTask( "Save content...", 1 );
+ }
+ doSave( monitor );
+ monitor.worked( 1 );
+ }
+ finally
+ {
+ monitor.done();
+ }
+ }
+ else
+ {
+ setActivePage( editorPageId );
+ }
+ }
+ else if ( newPageIndex == browserPageId && markers != null && markers.length > 0 )
+ {
+ MessageDialog.openError( getSite().getShell(), getString( "pageChange.openConfirm.title.text" ),
+ getString( "pageChange.openConfirm.message.text" ) );
+
+ setActivePage( editorPageId );
+
+ try
+ {
+ Object owner;
+ for ( int i = markers.length - 1; i >= 0; i-- )
+ {
+ IMarker marker = markers[i];
+ owner = marker.getAttribute( CommonPlugin.PLUGIN_ID );
+
+ if ( owner != null && owner instanceof String )
+ {
+ if ( owner.equals( CommonPlugin.PLUGIN_ID ) )
+ {
+ IGotoMarker gotoMarkerAdapter = (IGotoMarker) textEditor.getAdapter( IGotoMarker.class );
+ if ( gotoMarkerAdapter != null )
+ {
+ gotoMarkerAdapter.gotoMarker( marker );
+ return;
+ }
+ }
+ }
+ }
+ }
+ catch ( CoreException ce )
+ {
+ String msg = ( StringUtils.isEmpty( ce.getMessage() ) ? ce.getClass().getName() : ce.getMessage() );
+ ErrorDialog.openError( getSite().getShell(), getString( "CoreException.message.text" ), msg, ce
+ .getStatus() );
+ }
+ }
+ else
+ {
+ if ( newPageIndex != browserPageId )
+ {
+ super.pageChange( newPageIndex );
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void resourceChanged( final IResourceChangeEvent event )
+ {
+ if ( event.getType() == IResourceChangeEvent.PRE_CLOSE )
+ {
+ Display.getDefault().asyncExec( new Runnable()
+ {
+ /** {@inheritDoc} */
+ public void run()
+ {
+ IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages();
+ for ( int i = 0; i < pages.length; i++ )
+ {
+ if ( ( (FileEditorInput) getEditorInput() ).getFile().getProject().equals( event.getResource() ) )
+ {
+ IEditorPart editorPart = pages[i].findEditor( getEditorInput() );
+ pages[i].closeEditor( editorPart, true );
+ }
+ }
+ }
+ } );
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void propertyChanged( Object source, int propId )
+ {
+ if ( propId == IWorkbenchPartConstants.PROP_PART_NAME )
+ {
+ if ( source instanceof TextEditor )
+ {
+ TextEditor te = (TextEditor) source;
+ setPartName( te.getPartName() );
+ }
+ }
+ }
+
+ /**
+ * @return the browser page
+ */
+ public BrowserComposite getBrowser()
+ {
+ return browser;
+ }
+
+ /**
+ * @return the Doxia implementation used for the Text editor page.
+ */
+ public abstract TextEditor getTextEditor();
+
+ /**
+ * @return the Doxia format for the given Text editor page, i.e. <code>apt</code>.
+ */
+ public abstract String getFormat();
+
+ // ----------------------------------------------------------------------
+ // Private methods
+ // ----------------------------------------------------------------------
+
+ /**
+ * Contains a text editor.
+ */
+ private void createEditPage()
+ throws PartInitException
+ {
+ textEditor = getTextEditor();
+ editorPageId = addPage( textEditor, getEditorInput() );
+ setPageText( editorPageId, getString( "edit.label" ) );
+ textEditor.addPropertyListener( this );
+
+ IDocument document = textEditor.getDocumentProvider().getDocument( getEditorInput() );
+ document.addDocumentListener( new DoxiaDocumentListener( document ) );
+ }
+
+ /**
+ * Contains the generated page from the editor.
+ */
+ private void createBrowserPage()
+ throws PartInitException
+ {
+ browser = new BrowserComposite( getContainer(), SWT.NONE, getEditorSite().getActionBars(), getDoxiaFile(),
+ getFormat() );
+ browserPageId = addPage( browser );
+ setPageText( browserPageId, getString( "view.label" ) );
+ }
+
+ /**
+ * @return IFile from the editorInput
+ * @see #init(IEditorSite, IEditorInput)
+ */
+ private IFile getDoxiaFile()
+ {
+ return ( (FileEditorInput) getEditorInput() ).getFile();
+ }
+
+ /**
+ * Enabled or disabled action in the toolbar
+ *
+ * @param enabled
+ */
+ private void updateToolbar( boolean enabled )
+ {
+ for ( int i = 0; i < textEditor.getEditorSite().getActionBars().getToolBarManager().getItems().length; i++ )
+ {
+ IContributionItem item = textEditor.getEditorSite().getActionBars().getToolBarManager().getItems()[i];
+
+ if ( item.isSeparator() )
+ {
+ continue;
+ }
+
+ if ( ActionContributionItem.class.isAssignableFrom( item.getClass() ) )
+ {
+ ActionContributionItem action = (ActionContributionItem) item;
+ action.getAction().setEnabled( enabled );
+ }
+ }
+ }
+
+ /**
+ * Enabled or disabled action in the toolbar
+ *
+ * @param enabled
+ */
+ private void updateEditMenu( boolean enabled )
+ {
+ IMenuManager editMenu = getEditorSite().getActionBars().getMenuManager()
+ .findMenuUsingPath( IWorkbenchActionConstants.M_EDIT );
+
+ for ( int i = 0; i < editMenu.getItems().length; i++ )
+ {
+ IContributionItem item = editMenu.getItems()[i];
+
+ if ( item.isSeparator() )
+ {
+ continue;
+ }
+
+ if ( ActionContributionItem.class.isAssignableFrom( item.getClass() ) )
+ {
+ ActionContributionItem actionContributionItem = (ActionContributionItem) item;
+ actionContributionItem.getAction().setEnabled( enabled );
+ }
+
+ if ( SubContributionItem.class.isAssignableFrom( item.getClass() ) )
+ {
+ // TODO don't work
+ SubContributionItem subContributionItem = (SubContributionItem) item;
+ subContributionItem.getInnerItem().setVisible( enabled );
+ }
+ }
+ }
+
+ private static String getString( String subkey )
+ {
+ return CommonPluginMessages.getString( "AbstractMultiPageEditorPart." + subkey );
+ }
+
+ /**
+ * This document listener converts the content of the input text editor.
+ *
+ * @see DoxiaWrapper#convert(String, IFile, String)
+ */
+ class DoxiaDocumentListener
+ implements IDocumentListener
+ {
+ private IDocument document;
+
+ public DoxiaDocumentListener( IDocument document )
+ {
+ this.document = document;
+ }
+
+ /** {@inheritDoc} */
+ public void documentChanged( DocumentEvent event )
+ {
+ DoxiaWrapper.convert( document.get(), getDoxiaFile(), getFormat() );
+ }
+
+ /** {@inheritDoc} */
+ public void documentAboutToBeChanged( DocumentEvent event )
+ {
+ DoxiaWrapper.convert( document.get(), getDoxiaFile(), getFormat() );
+ }
+ }
+}
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractMultiPageEditorPart.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractMultiPageEditorPart.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractTextMultiPageEditorPart.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractTextMultiPageEditorPart.java?rev=645502&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractTextMultiPageEditorPart.java (added)
+++ maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractTextMultiPageEditorPart.java Mon Apr 7 06:18:18 2008
@@ -0,0 +1,33 @@
+package org.apache.maven.doxia.ide.eclipse.common.ui.editors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Abstract multipage editor for Doxia text files.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.0
+ */
+public abstract class AbstractTextMultiPageEditorPart
+ extends AbstractMultiPageEditorPart
+{
+ // nop
+}
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractTextMultiPageEditorPart.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractTextMultiPageEditorPart.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractXmlMultiPageEditorPart.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractXmlMultiPageEditorPart.java?rev=645502&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractXmlMultiPageEditorPart.java (added)
+++ maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractXmlMultiPageEditorPart.java Mon Apr 7 06:18:18 2008
@@ -0,0 +1,204 @@
+package org.apache.maven.doxia.ide.eclipse.common.ui.editors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.ide.eclipse.common.ui.actions.AbstractBoldAction;
+import org.apache.maven.doxia.ide.eclipse.common.ui.actions.AbstractItalicAction;
+import org.apache.maven.doxia.ide.eclipse.common.ui.actions.AbstractLinkAction;
+import org.apache.maven.doxia.ide.eclipse.common.ui.actions.AbstractMonospacedAction;
+import org.apache.maven.doxia.ide.eclipse.common.ui.actions.AbstractTableAction;
+import org.apache.maven.doxia.ide.eclipse.common.ui.actions.IActionConstants;
+import org.apache.maven.doxia.ide.eclipse.common.ui.dialogs.AddLinkDialog.Link;
+import org.apache.maven.doxia.ide.eclipse.common.ui.dialogs.AddTableDialog.Table;
+import org.apache.maven.doxia.ide.eclipse.common.ui.editors.xml.AbstractXmlEditor;
+import org.apache.maven.doxia.markup.Markup;
+import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.part.MultiPageEditorSite;
+import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML;
+
+/**
+ * Abstract multipage editor for Doxia xml files.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.0
+ */
+public abstract class AbstractXmlMultiPageEditorPart
+ extends AbstractMultiPageEditorPart
+{
+ private XmlEditor editor;
+
+ @Override
+ public TextEditor getTextEditor()
+ {
+ if ( editor != null )
+ {
+ return editor;
+ }
+
+ editor = new XmlEditor();
+ editor.setAction( IActionConstants.BOLD_ACTION, new AbstractBoldAction( editor )
+ {
+ @Override
+ public String getStartMarkup()
+ {
+ return "<b>";
+ }
+
+ @Override
+ public String getEndMarkup()
+ {
+ return "</b>";
+ }
+ } );
+ editor.setAction( IActionConstants.ITALIC_ACTION, new AbstractItalicAction( editor )
+ {
+ @Override
+ public String getStartMarkup()
+ {
+ return "<i>";
+ }
+
+ @Override
+ public String getEndMarkup()
+ {
+ return "</i>";
+ }
+ } );
+ editor.setAction( IActionConstants.MONOSPACED_ACTION, new AbstractMonospacedAction( editor )
+ {
+ @Override
+ public String getStartMarkup()
+ {
+ return "<tt>";
+ }
+
+ @Override
+ public String getEndMarkup()
+ {
+ return "</tt>";
+ }
+ } );
+ editor.setAction( IActionConstants.LINK_ACTION, new AbstractLinkAction( editor )
+ {
+ @Override
+ protected String generateLink( Link link )
+ {
+ if ( StringUtils.isEmpty( link.getName() ) )
+ {
+ return "<a href=\"" + link.getURL() + "\">" + link.getURL() + "</a>";
+ }
+
+ return "<a href=\"" + link.getURL() + "\" name=\"" + link.getName() + "\">" + link.getName() + "</a>";
+ }
+ } );
+ editor.setAction( IActionConstants.TABLE_ACTION, new AbstractTableAction( editor )
+ {
+ @Override
+ protected String generateTable( Table table )
+ {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( "<table>" );
+ sb.append( Markup.EOL );
+ for ( int i = 0; i < table.getRows(); i++ )
+ {
+ sb.append( "<tr>" );
+ sb.append( Markup.EOL );
+
+ for ( int j = 0; j < table.getColumns(); j++ )
+ {
+ String align;
+ switch ( table.getTableStyle() )
+ {
+ case Table.TABLE_STYLE_CENTERED:
+ align = "center";
+ break;
+
+ case Table.TABLE_STYLE_LEFTALIGNED:
+ align = "left";
+ break;
+
+ case Table.TABLE_STYLE_RIGHTALIGNED:
+ align = "right";
+ break;
+
+ default:
+ align = "right";
+ break;
+ }
+ sb.append( "<td align=\"" ).append( align ).append( "\">" );
+ sb.append( DEFAULT_CELL_TEXT );
+ sb.append( "</td>" );
+ sb.append( Markup.EOL );
+ }
+ sb.append( "</tr>" );
+ sb.append( Markup.EOL );
+ }
+ sb.append( "</table>" );
+ sb.append( Markup.EOL );
+
+ return sb.toString();
+ }
+ } );
+
+ return editor;
+ }
+
+ protected abstract String getEditorId();
+
+ @Override
+ protected IEditorSite createSite( IEditorPart page )
+ {
+ // see http://www.eclipse.org/webtools/wst/components/sse/tutorials/multipage-editor-tutorial.html
+ IEditorSite site = null;
+ if ( page == getTextEditor() )
+ {
+ site = new MultiPageEditorSite( this, page )
+ {
+ @Override
+ public String getId()
+ {
+ // Sets this ID so nested editor is configured for XML source
+ return ContentTypeIdForXML.ContentTypeID_XML + ".source";
+ }
+ };
+ }
+ else
+ {
+ site = super.createSite( page );
+ }
+
+ return site;
+ }
+
+ class XmlEditor
+ extends AbstractXmlEditor
+ {
+ @Override
+ public String getEditorId()
+ {
+ return AbstractXmlMultiPageEditorPart.this.getEditorId();
+ }
+ }
+}
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractXmlMultiPageEditorPart.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/AbstractXmlMultiPageEditorPart.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextDocumentProvider.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextDocumentProvider.java?rev=645502&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextDocumentProvider.java (added)
+++ maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextDocumentProvider.java Mon Apr 7 06:18:18 2008
@@ -0,0 +1,67 @@
+package org.apache.maven.doxia.ide.eclipse.common.ui.editors.text;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.ide.eclipse.common.ui.rules.AbstractTextPartitionScanner;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.rules.FastPartitioner;
+import org.eclipse.jface.text.rules.IPartitionTokenScanner;
+import org.eclipse.ui.editors.text.TextFileDocumentProvider;
+
+/**
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.0
+ */
+public abstract class AbstractTextDocumentProvider
+ extends TextFileDocumentProvider
+{
+ /**
+ * Default constructor.
+ */
+ public AbstractTextDocumentProvider()
+ {
+ Assert.isNotNull( getScanner(), "getScanner() should be defined" );
+ }
+
+ @Override
+ public IDocument getDocument( final Object element )
+ {
+ final IDocument document = getParentDocument( element );
+ if ( document != null )
+ {
+ IDocumentPartitioner partitioner = new FastPartitioner(
+ getScanner(),
+ AbstractTextPartitionScanner.DOXIA_LEGAL_CONTENT_TYPES );
+ partitioner.connect( document );
+ document.setDocumentPartitioner( partitioner );
+ }
+ return document;
+ }
+
+ protected IDocument getParentDocument( Object element )
+ {
+ return super.getDocument( element );
+ }
+
+ public abstract IPartitionTokenScanner getScanner();
+}
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextDocumentProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextDocumentProvider.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextEditor.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextEditor.java?rev=645502&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextEditor.java (added)
+++ maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextEditor.java Mon Apr 7 06:18:18 2008
@@ -0,0 +1,109 @@
+package org.apache.maven.doxia.ide.eclipse.common.ui.editors.text;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.ide.eclipse.common.ui.CommonPluginMessages;
+import org.apache.maven.doxia.ide.eclipse.common.ui.actions.IActionConstants;
+import org.apache.maven.doxia.ide.eclipse.common.ui.editors.text.source.TextPairMatcher;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
+import org.eclipse.ui.texteditor.ContentAssistAction;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
+import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
+
+/**
+ * Doxia editor for text file resources.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.0
+ */
+public abstract class AbstractTextEditor
+ extends TextEditor
+{
+ private TextPairMatcher doxiaTextPairMatcher;
+
+ /**
+ * Default constructor.
+ */
+ public AbstractTextEditor()
+ {
+ super();
+
+ Assert.isNotNull( getEditorId(), "getEditorId() should be defined" );
+ Assert.isNotNull( getTextSourceViewerConfiguration(), "getTextSourceViewerConfiguration() should be defined" );
+ Assert.isNotNull( getTextSourceViewerConfiguration(), "getTextSourceViewerConfiguration() should be defined" );
+
+ doxiaTextPairMatcher = new TextPairMatcher();
+
+ setSourceViewerConfiguration( getTextSourceViewerConfiguration() );
+ setDocumentProvider( getFileDocumentProvider() );
+ }
+
+ @Override
+ protected void initializeEditor()
+ {
+ super.initializeEditor();
+
+ // see http://www.eclipse.org/articles/article.php?file=Article-action-contribution/index.html
+ setEditorContextMenuId( getEditorId() + ".EditorContext" );
+ setRulerContextMenuId( getEditorId() + ".RulerContext" );
+ }
+
+ /**
+ * @return The ID of this editor like should be defined in plugin.xml
+ */
+ public abstract String getEditorId();
+
+ /**
+ * @return the implementation of the document provider for this editor.
+ */
+ public abstract IDocumentProvider getFileDocumentProvider();
+
+ /**
+ * @return the implementation of the source viewer configuration for this editor.
+ */
+ public abstract TextSourceViewerConfiguration getTextSourceViewerConfiguration();
+
+ @Override
+ protected void createActions()
+ {
+ super.createActions();
+
+ // TODO create TextOperationAction?
+
+ IAction action = new ContentAssistAction( CommonPluginMessages.getResourceBundle(), AbstractTextEditor.class
+ .getName()
+ + ".contentAssist.", this );
+ action.setActionDefinitionId( ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS );
+ setAction( IActionConstants.CONTENT_ASSIST_ACTION, action );
+ }
+
+ @Override
+ protected void configureSourceViewerDecorationSupport( SourceViewerDecorationSupport support )
+ {
+ support.setCharacterPairMatcher( doxiaTextPairMatcher );
+
+ super.configureSourceViewerDecorationSupport( support );
+ }
+}
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextEditor.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextSourceViewerConfiguration.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextSourceViewerConfiguration.java?rev=645502&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextSourceViewerConfiguration.java (added)
+++ maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextSourceViewerConfiguration.java Mon Apr 7 06:18:18 2008
@@ -0,0 +1,97 @@
+package org.apache.maven.doxia.ide.eclipse.common.ui.editors.text;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.ide.eclipse.common.ui.ColorManager;
+import org.apache.maven.doxia.ide.eclipse.common.ui.rules.AbstractTextPartitionScanner;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
+
+/**
+ * Abstract class for the source viewer configuration.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.0
+ */
+public abstract class AbstractTextSourceViewerConfiguration
+ extends TextSourceViewerConfiguration
+{
+ /**
+ * Default constructor.
+ */
+ public AbstractTextSourceViewerConfiguration()
+ {
+ Assert.isNotNull( getScanner(), "getScanner() should be defined" );
+ }
+
+ @Override
+ public String[] getConfiguredContentTypes( ISourceViewer sourceViewer )
+ {
+ return AbstractTextPartitionScanner.DOXIA_LEGAL_CONTENT_TYPES;
+ }
+
+ @Override
+ public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer )
+ {
+ PresentationReconciler reconciler = new PresentationReconciler();
+
+ DefaultDamagerRepairer dr = new DefaultDamagerRepairer( getScanner() );
+ reconciler.setDamager( dr, IDocument.DEFAULT_CONTENT_TYPE );
+ reconciler.setRepairer( dr, IDocument.DEFAULT_CONTENT_TYPE );
+
+ dr = new DefaultDamagerRepairer( getScanner() );
+ reconciler.setDamager( dr, AbstractTextPartitionScanner.DOXIA_PARTITION_CONTENT );
+ reconciler.setRepairer( dr, AbstractTextPartitionScanner.DOXIA_PARTITION_CONTENT );
+
+ dr = new DefaultDamagerRepairer( new SingleTokenScanner( new TextAttribute( ColorManager.getInstance()
+ .getColor( ColorManager.COMMENT ) ) ) );
+ reconciler.setDamager( dr, AbstractTextPartitionScanner.DOXIA_PARTITION_COMMENT );
+ reconciler.setRepairer( dr, AbstractTextPartitionScanner.DOXIA_PARTITION_COMMENT );
+
+ return reconciler;
+ }
+
+ /**
+ * @return the Doxia implementation scanner.
+ */
+ protected abstract RuleBasedScanner getScanner();
+
+ /**
+ * Single token scanner, used for scanning for multiline comments mainly.
+ */
+ static class SingleTokenScanner
+ extends BufferedRuleBasedScanner
+ {
+ public SingleTokenScanner( TextAttribute attribute )
+ {
+ setDefaultReturnToken( new Token( attribute ) );
+ }
+ }
+}
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextSourceViewerConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/AbstractTextSourceViewerConfiguration.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/source/TextPairMatcher.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/source/TextPairMatcher.java?rev=645502&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/source/TextPairMatcher.java (added)
+++ maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/source/TextPairMatcher.java Mon Apr 7 06:18:18 2008
@@ -0,0 +1,38 @@
+package org.apache.maven.doxia.ide.eclipse.common.ui.editors.text.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.jface.text.source.DefaultCharacterPairMatcher;
+
+/**
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.0
+ */
+public class TextPairMatcher
+ extends DefaultCharacterPairMatcher
+{
+ private static final String DOXIA_PARTITIONING = "___doxia_partitioning";
+
+ public TextPairMatcher()
+ {
+ super( new char[] { '{', '}', '[', ']' }, DOXIA_PARTITIONING );
+ }
+}
\ No newline at end of file
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/source/TextPairMatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/text/source/TextPairMatcher.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/xml/AbstractXmlEditor.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/xml/AbstractXmlEditor.java?rev=645502&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/xml/AbstractXmlEditor.java (added)
+++ maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/xml/AbstractXmlEditor.java Mon Apr 7 06:18:18 2008
@@ -0,0 +1,61 @@
+package org.apache.maven.doxia.ide.eclipse.common.ui.editors.xml;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+
+/**
+ * Doxia editor for xml file resources.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.0
+ */
+public abstract class AbstractXmlEditor
+ extends StructuredTextEditor
+{
+ /**
+ * Default constructor.
+ */
+ public AbstractXmlEditor()
+ {
+ super();
+
+ Assert.isNotNull( getEditorId(), "getEditorId() should be defined" );
+ }
+
+ @Override
+ protected void initializeEditor()
+ {
+ super.initializeEditor();
+
+ // TODO Doesn't work yet: needs WSTP M6
+ // see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=212330
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=224040
+ setEditorContextMenuId( getEditorId() + ".EditorContext" );
+ setRulerContextMenuId( getEditorId() + ".RulerContext" );
+ }
+
+ /**
+ * @return The ID of this editor like should be defined in plugin.xml
+ */
+ public abstract String getEditorId();
+}
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/xml/AbstractXmlEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/editors/xml/AbstractXmlEditor.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/rules/AbstractTextPartitionScanner.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/rules/AbstractTextPartitionScanner.java?rev=645502&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/rules/AbstractTextPartitionScanner.java (added)
+++ maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/rules/AbstractTextPartitionScanner.java Mon Apr 7 06:18:18 2008
@@ -0,0 +1,94 @@
+package org.apache.maven.doxia.ide.eclipse.common.ui.rules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.maven.doxia.ide.eclipse.common.ui.editors.text.AbstractTextEditor;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.rules.IPredicateRule;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
+import org.eclipse.jface.text.rules.Token;
+
+/**
+ * Doxia scanner for text file resources.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.0
+ * @see AbstractTextEditor
+ */
+public abstract class AbstractTextPartitionScanner
+ extends RuleBasedPartitionScanner
+{
+ /** Doxia partition content */
+ public static final String DOXIA_PARTITION_CONTENT = "__partition_content";
+
+ /** Doxia partition comment */
+ public static final String DOXIA_PARTITION_COMMENT = "__partition_comment";
+
+ /** Doxia legal content types of this partitioner */
+ public static final String[] DOXIA_LEGAL_CONTENT_TYPES = {
+ IDocument.DEFAULT_CONTENT_TYPE,
+ DOXIA_PARTITION_CONTENT,
+ DOXIA_PARTITION_COMMENT };
+
+ /** Partition token */
+ protected static final IToken PARTITION_CONTENT_TOKEN = new Token( DOXIA_PARTITION_CONTENT );
+
+ /** Comment token */
+ protected static final IToken PARTITION_COMMENT_TOKEN = new Token( DOXIA_PARTITION_COMMENT );
+
+ /**
+ * Default constructor.
+ *
+ * @see #initialise()
+ */
+ public AbstractTextPartitionScanner()
+ {
+ Assert.isNotNull( getRules(), "getRules() should be initialized" );
+ initialise();
+ }
+
+ /**
+ * @return the rules implementation.
+ */
+ public abstract List<IRule> getRules();
+
+ // ----------------------------------------------------------------------
+ // Protected methods
+ // ----------------------------------------------------------------------
+
+ protected void initialise()
+ {
+ List<IRule> rules = new LinkedList<IRule>();
+
+ if ( getRules() != null )
+ {
+ rules.addAll( getRules() );
+ }
+
+ setPredicateRules( (IPredicateRule[]) rules.toArray( new IPredicateRule[rules.size()] ) );
+ }
+}
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/rules/AbstractTextPartitionScanner.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/rules/AbstractTextPartitionScanner.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/rules/AbstractTextScanner.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/rules/AbstractTextScanner.java?rev=645502&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/rules/AbstractTextScanner.java (added)
+++ maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/rules/AbstractTextScanner.java Mon Apr 7 06:18:18 2008
@@ -0,0 +1,103 @@
+package org.apache.maven.doxia.ide.eclipse.common.ui.rules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.doxia.ide.eclipse.common.ui.ColorManager;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.0
+ */
+public abstract class AbstractTextScanner
+ extends BufferedRuleBasedScanner
+{
+ protected static final Color KEYWORD_COLOR = ColorManager.getInstance().getColor( ColorManager.KEYWORD );
+
+ protected static final Color COMMENT_COLOR = ColorManager.getInstance().getColor( ColorManager.COMMENT );
+
+ protected static final Color STRING_COLOR = ColorManager.getInstance().getColor( ColorManager.STRING );
+
+ protected static final IToken keywordToken = new Token( new TextAttribute( KEYWORD_COLOR, null, SWT.BOLD ) );
+
+ protected static final IToken commentToken = new Token( new TextAttribute( COMMENT_COLOR ) );
+
+ protected static final IToken stringToken = new Token( new TextAttribute( STRING_COLOR ) );
+
+ protected static final IToken linkToken = new Token( new TextAttribute( ColorManager.getInstance()
+ .getColor( ColorManager.LINK ) ) );
+
+ protected static final IToken monospacedToken = new Token( new TextAttribute( ColorManager.getInstance()
+ .getColor( ColorManager.STRING ), null, SWT.NORMAL, new Font( Display.getDefault(), "Courier", Display
+ .getDefault().getSystemFont().getFontData()[0].getHeight(), SWT.NORMAL ) ) );
+
+ protected static final IToken boldToken = new Token( new TextAttribute( ColorManager.getInstance()
+ .getColor( ColorManager.STRING ), null, SWT.BOLD ) );
+
+ protected static final IToken italicToken = new Token( new TextAttribute( ColorManager.getInstance()
+ .getColor( ColorManager.STRING ), null, SWT.ITALIC ) );
+
+ protected static final Token otherToken = new Token( null );
+
+ /**
+ * Default constructor.
+ */
+ public AbstractTextScanner()
+ {
+ Assert.isNotNull( getRules(), "getRules() should be initialized" );
+
+ initialise();
+ }
+
+ /**
+ * @return the rules implementations.
+ */
+ public abstract List<IRule> getRules();
+
+ // ----------------------------------------------------------------------
+ // Protected methods
+ // ----------------------------------------------------------------------
+
+ protected void initialise()
+ {
+ List<IRule> rules = new ArrayList<IRule>();
+
+ if ( getRules() != null )
+ {
+ rules.addAll( getRules() );
+ }
+
+ setRules( (IRule[]) rules.toArray( new IRule[rules.size()] ) );
+ setDefaultReturnToken( new Token( new TextAttribute( STRING_COLOR ) ) );
+ }
+}
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/rules/AbstractTextScanner.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia-tools/trunk/doxia-ide/eclipse/plugins/org.apache.maven.doxia.ide.eclipse.common.ui/src/main/java/org/apache/maven/doxia/ide/eclipse/common/ui/rules/AbstractTextScanner.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision