Update of /cvsroot/smartfrog/core/extras/eclipse/smartfrog-plugin/smartfrog-plugin-project/src/org/smartfrog/tools/eclipse/ui/editor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2581/smartfrog-plugin/smartfrog-plugin-project/src/org/smartfrog/tools/eclipse/ui/editor Added Files: DefineFoldingRegionAction.java DescriptionWhitespaceDetector.java DescriptionSourceViewerConfiguration.java DescriptionMessages.java DescriptionMessages.properties DescriptionPartitionScanner.java DescriptionEditor.java DescriptionDocumentSetupParticipant.java Log Message: Plug-in project, init check-in --- NEW FILE: DescriptionPartitionScanner.java --- /** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more information: www.smartfrog.org */ package org.smartfrog.tools.eclipse.ui.editor; import org.eclipse.jface.text.rules.EndOfLineRule; import org.eclipse.jface.text.rules.ICharacterScanner; import org.eclipse.jface.text.rules.IPredicateRule; import org.eclipse.jface.text.rules.IToken; import org.eclipse.jface.text.rules.IWordDetector; import org.eclipse.jface.text.rules.MultiLineRule; import org.eclipse.jface.text.rules.RuleBasedPartitionScanner; import org.eclipse.jface.text.rules.SingleLineRule; import org.eclipse.jface.text.rules.Token; import org.eclipse.jface.text.rules.WordRule; import java.util.ArrayList; import java.util.List; /** * Description partition scanner */ public class DescriptionPartitionScanner extends RuleBasedPartitionScanner { private static final String STAR_COMMENT_END = "*/"; //$NON-NLS-1$ private static final String STAR_COMMENT_BEGIN = "/*"; //$NON-NLS-1$ private static final String SINGLE_QUOTE = "'"; //$NON-NLS-1$ private static final String DOUBLE_QUOTE = "\""; //$NON-NLS-1$ private static final String BACK_SLASH = "//"; //$NON-NLS-1$ public final static String SMARTFROG_MULTILINE_COMMENT = "__smartFrog_multiline_comment"; //$NON-NLS-1$ public final static String SMARTFROG_MULTILINE_STRING = "__smartFrog_multiline_string"; //$NON-NLS-1$ public final static String[] SMARTFROG_PARTITION_TYPES = new String[] { SMARTFROG_MULTILINE_COMMENT, SMARTFROG_MULTILINE_STRING }; private static DescriptionPartitionScanner INSTANCE; public static DescriptionPartitionScanner getInstance() { if (null == INSTANCE) { INSTANCE = new DescriptionPartitionScanner(); } return INSTANCE; } /** * Create the partition based on comments or not */ private DescriptionPartitionScanner() { super(); IToken comment = new Token(SMARTFROG_MULTILINE_COMMENT); List rules = new ArrayList(); rules.add(new EndOfLineRule(BACK_SLASH, Token.UNDEFINED)); //$NON-NLS-1$ rules.add(new SingleLineRule(DOUBLE_QUOTE, DOUBLE_QUOTE, Token.UNDEFINED, '\\')); //$NON-NLS-2$ //$NON-NLS-1$ rules.add(new SingleLineRule(SINGLE_QUOTE, SINGLE_QUOTE, Token.UNDEFINED, '\\')); //$NON-NLS-2$ //$NON-NLS-1$ rules.add(new MultiLineRule("##", "#", //$NON-NLS-1$ //$NON-NLS-2$ new Token(SMARTFROG_MULTILINE_STRING), (char)0, true)); //$NON-NLS-1$ //$NON-NLS-2$ rules.add(new CommentPredicateRule(comment)); rules.add(new MultiLineRule(STAR_COMMENT_BEGIN, STAR_COMMENT_END, comment, (char)0, true)); //$NON-NLS-1$ //$NON-NLS-2$ IPredicateRule[] result = new IPredicateRule[ rules.size() ]; rules.toArray(result); setPredicateRules(result); } /** * Detector for empty comments. */ static class EmptyCommentDetector implements IWordDetector { //Comments start char public boolean isWordStart(char c) { return ( c == '/' ); } //Comments char // or /* public boolean isWordPart(char c) { return ( ( c == '*' ) || ( c == '/' ) ); } } /** * Detect comments */ static class CommentPredicateRule extends WordRule implements IPredicateRule { private IToken fSuccessToken; public CommentPredicateRule(IToken successToken) { super(new EmptyCommentDetector()); fSuccessToken = successToken; addWord("/**/", fSuccessToken); //$NON-NLS-1$ } /* * @see org.eclipse.jface.text.rules.IPredicateRule#evaluate(ICharacterScanner, boolean) */ public IToken evaluate(ICharacterScanner scanner, boolean resume) { return super.evaluate(scanner); } /* * @see org.eclipse.jface.text.rules.IPredicateRule#getSuccessToken() */ public IToken getSuccessToken() { return fSuccessToken; } } } --- NEW FILE: DescriptionMessages.properties --- DescriptionEditor.ErrorType=Error DescriptionEditor.WarningType=Warning DescriptionEditor.ContentAssist.label=Content Assist DescriptionEditor.DefineFoldingRegion.label=Define Folding Region --- NEW FILE: DescriptionEditor.java --- /** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more information: www.smartfrog.org */ package org.smartfrog.tools.eclipse.ui.editor; import org.smartfrog.tools.eclipse.model.IHelpContextIds; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.text.ITextViewerExtension5; import org.eclipse.jface.text.Region; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.IVerticalRuler; import org.eclipse.jface.text.source.projection.ProjectionSupport; import org.eclipse.jface.text.source.projection.ProjectionViewer; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.editors.text.TextEditor; import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.ui.texteditor.TextOperationAction; /** * SmartFrog description editor. */ public class DescriptionEditor extends TextEditor { private ProjectionSupport mProjectionSupport; /* (non-Javadoc) * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) */ public Object getAdapter(Class required) { if (mProjectionSupport != null) { Object adapter = mProjectionSupport.getAdapter(getSourceViewer(), required); if (adapter != null) { return adapter; } } return super.getAdapter(required); } protected void initializeEditor() { super.initializeEditor(); setSourceViewerConfiguration( new DescriptionSourceViewerConfiguration()); setHelpContextId(IHelpContextIds.DESCRIPTION_EDITOR_HELP_ID); } /* * @see org.eclipse.ui.texteditor.ExtendedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, int) */ protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) { fAnnotationAccess = createAnnotationAccess(); fOverviewRuler = createOverviewRuler(getSharedColors()); ISourceViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles); getSourceViewerDecorationSupport(viewer); return viewer; } /* * @see org.eclipse.ui.texteditor.ExtendedTextEditor#createPartControl(org.eclipse.swt.widgets.Composite) */ public void createPartControl(Composite parent) { super.createPartControl(parent); ProjectionViewer viewer = (ProjectionViewer)getSourceViewer(); mProjectionSupport = new ProjectionSupport(viewer, getAnnotationAccess(), getSharedColors()); mProjectionSupport.addSummarizableAnnotationType(DescriptionMessages .getString("DescriptionEditor.ErrorType")); //$NON-NLS-1$ mProjectionSupport.addSummarizableAnnotationType(DescriptionMessages .getString("DescriptionEditor.WarningType")); //$NON-NLS-1$ mProjectionSupport.install(); viewer.doOperation(ProjectionViewer.TOGGLE); } /* * @see org.eclipse.ui.texteditor.AbstractTextEditor#adjustHighlightRange(int, int) */ protected void adjustHighlightRange(int offset, int length) { ISourceViewer viewer = getSourceViewer(); if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5)viewer; extension.exposeModelRange(new Region(offset, length)); } } /** The <code>SmartFrogEditor</code> implementation of this * <code>AbstractTextEditor</code> method extend the * actions to add those specific to the receiver */ protected void createActions() { super.createActions(); IAction action = new TextOperationAction(DescriptionMessages .getResourceBundle(), "DescriptionEditor.ContentAssist.", this, //$NON-NLS-1$ ISourceViewer.CONTENTASSIST_PROPOSALS); //$NON-NLS-1$ action.setActionDefinitionId( ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); setAction("SmartFrog.ContentAssistProposalID", action); //$NON-NLS-1$ action = new DefineFoldingRegionAction(DescriptionMessages .getResourceBundle(), "DescriptionEditor.DefineFoldingRegion.", //$NON-NLS-1$ this); //$NON-NLS-1$ setAction("SmartFrog.DefineFoldingRegionID", action); //$NON-NLS-1$ } /* * @see org.eclipse.ui.texteditor.ExtendedTextEditor#editorContextMenuAboutToShow(org.eclipse.jface.action.IMenuManager) */ protected void editorContextMenuAboutToShow(IMenuManager menu) { super.editorContextMenuAboutToShow(menu); addAction(menu, "SmartFrog.ContentAssistProposalID"); //$NON-NLS-1$ addAction(menu, "SmartFrog.DefineFoldingRegionID"); //$NON-NLS-1$ } } --- NEW FILE: DescriptionWhitespaceDetector.java --- /** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more information: www.smartfrog.org */ package org.smartfrog.tools.eclipse.ui.editor; import org.eclipse.jface.text.rules.IWhitespaceDetector; /** * A white space detector. */ public class DescriptionWhitespaceDetector implements IWhitespaceDetector { /* (non-Javadoc) * Method declared on IWhitespaceDetector */ public boolean isWhitespace(char character) { //(c == ' ' || c == '\t' || c == '\n' || c == '\r') return Character.isWhitespace(character); } } --- NEW FILE: DefineFoldingRegionAction.java --- /** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more information: www.smartfrog.org */ package org.smartfrog.tools.eclipse.ui.editor; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.projection.ProjectionAnnotation; import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.TextEditorAction; import java.util.ResourceBundle; /** * Support source code folding */ class DefineFoldingRegionAction extends TextEditorAction { public DefineFoldingRegionAction(ResourceBundle bundle, String prefix, ITextEditor editor) { super(bundle, prefix, editor); } private IAnnotationModel getAnnotationModel(ITextEditor editor) { return (IAnnotationModel)editor.getAdapter( ProjectionAnnotationModel.class); } /* * @see org.eclipse.jface.action.Action#run() */ public void run() { ITextEditor editor = getTextEditor(); ISelection selection = editor.getSelectionProvider().getSelection(); if (selection instanceof ITextSelection) { ITextSelection textSelection = (ITextSelection)selection; if (!textSelection.isEmpty()) { IAnnotationModel model = getAnnotationModel(editor); if (model != null) { int start = textSelection.getStartLine(); int end = textSelection.getEndLine(); try { IDocument document = editor.getDocumentProvider() .getDocument(editor .getEditorInput()); int offset = document.getLineOffset(start); int endOffset = document.getLineOffset(end + 1); Position position = new Position(offset, endOffset - offset); model.addAnnotation(new ProjectionAnnotation(), position); } catch (BadLocationException ignore) { } } } } } } --- NEW FILE: DescriptionMessages.java --- /** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more information: www.smartfrog.org */ package org.smartfrog.tools.eclipse.ui.editor; import java.util.MissingResourceException; import java.util.ResourceBundle; public class DescriptionMessages { private static final String RESOURCE_BUNDLE = "org.smartfrog.tools.eclipse.ui.editor.DescriptionMessages"; //$NON-NLS-1$ private static ResourceBundle fgResourceBundle = ResourceBundle.getBundle( RESOURCE_BUNDLE); private DescriptionMessages() { } public static String getString(String key) { try { return fgResourceBundle.getString(key); } catch (MissingResourceException e) { return "!" + key + "!"; //$NON-NLS-2$ //$NON-NLS-1$ } } public static ResourceBundle getResourceBundle() { return fgResourceBundle; } } --- NEW FILE: DescriptionDocumentSetupParticipant.java --- /** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more information: www.smartfrog.org */ package org.smartfrog.tools.eclipse.ui.editor; import org.eclipse.core.filebuffers.IDocumentSetupParticipant; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentExtension3; import org.eclipse.jface.text.IDocumentPartitioner; import org.eclipse.jface.text.rules.DefaultPartitioner; import org.smartfrog.tools.eclipse.SmartFrogPlugin; /** * Link document to the editor */ public class DescriptionDocumentSetupParticipant implements IDocumentSetupParticipant { /* * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument) */ public void setup(IDocument document) { if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension3 = (IDocumentExtension3)document; IDocumentPartitioner partitioner = new DefaultPartitioner( DescriptionPartitionScanner.getInstance(), DescriptionPartitionScanner.SMARTFROG_PARTITION_TYPES); extension3.setDocumentPartitioner( SmartFrogPlugin.SMARTFROG_PARTITIONING, partitioner); partitioner.connect(document); } } } --- NEW FILE: DescriptionSourceViewerConfiguration.java --- /** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more information: www.smartfrog.org */ package org.smartfrog.tools.eclipse.ui.editor; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.TextAttribute; import org.eclipse.jface.text.contentassist.ContentAssistant; import org.eclipse.jface.text.contentassist.IContentAssistant; 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.Token; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.swt.graphics.RGB; import org.smartfrog.tools.eclipse.SmartFrogPlugin; import org.smartfrog.tools.eclipse.ui.editor.sf2.DescriptionColorProvider; import org.smartfrog.tools.eclipse.ui.editor.sf2.DescriptionCompletionProcessor; import org.smartfrog.tools.eclipse.ui.editor.sf2.DescriptionScanner; /** * You can configure the description behavior in this class, partioner, code assistance ... */ public class DescriptionSourceViewerConfiguration extends SourceViewerConfiguration { private static final int DELAY_TIME = 500; /** * Single token scanner. */ static class SingleTokenScanner extends BufferedRuleBasedScanner { public SingleTokenScanner(TextAttribute attribute) { setDefaultReturnToken(new Token(attribute)); } } /* * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer) */ public String getConfiguredDocumentPartitioning( ISourceViewer sourceViewer) { return SmartFrogPlugin.SMARTFROG_PARTITIONING; } /* (non-Javadoc) * Method declared on SourceViewerConfiguration */ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { return new String[] { IDocument.DEFAULT_CONTENT_TYPE, DescriptionPartitionScanner.SMARTFROG_MULTILINE_COMMENT }; } /* (non-Javadoc) * Method declared on SourceViewerConfiguration */ public String getDefaultPrefix(ISourceViewer sourceViewer, String contentType) { return ( IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" //$NON-NLS-1$ : null ); //$NON-NLS-1$ } /* (non-Javadoc) * Method declared on SourceViewerConfiguration */ public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { return new String[] { "\t", " " }; //$NON-NLS-1$ //$NON-NLS-2$ } /* (non-Javadoc) * Method declared on SourceViewerConfiguration */ public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer) { DescriptionColorProvider provider = DescriptionColorProvider .getInstance(); PresentationReconciler reconciler = new PresentationReconciler(); reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning( sourceViewer)); DefaultDamagerRepairer dr = new DefaultDamagerRepairer( DescriptionScanner.getInstance()); reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); dr = new DefaultDamagerRepairer(new SingleTokenScanner( new TextAttribute( provider.getColor( DescriptionColorProvider.MULTI_LINE_COMMENT)))); reconciler.setDamager(dr, DescriptionPartitionScanner.SMARTFROG_MULTILINE_COMMENT); reconciler.setRepairer(dr, DescriptionPartitionScanner.SMARTFROG_MULTILINE_COMMENT); dr = new DefaultDamagerRepairer(new SingleTokenScanner( new TextAttribute( provider.getColor(DescriptionColorProvider.STRING)))); reconciler.setDamager(dr, DescriptionPartitionScanner.SMARTFROG_MULTILINE_STRING); reconciler.setRepairer(dr, DescriptionPartitionScanner.SMARTFROG_MULTILINE_STRING); return reconciler; } /* (non-Javadoc) * Method declared on SourceViewerConfiguration */ public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { ContentAssistant assistant = new ContentAssistant(); assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning( sourceViewer)); assistant.setContentAssistProcessor( new DescriptionCompletionProcessor(), IDocument.DEFAULT_CONTENT_TYPE); assistant.enableAutoActivation(true); assistant.setAutoActivationDelay(DELAY_TIME); assistant.setProposalPopupOrientation( IContentAssistant.PROPOSAL_OVERLAY); assistant.setContextInformationPopupOrientation( IContentAssistant.CONTEXT_INFO_ABOVE); assistant.setContextInformationPopupBackground(DescriptionColorProvider .getInstance().getColor(new RGB(150, 150, 0))); return assistant; } } |