diff options
author | Michael Valenta | 2007-04-17 16:12:56 +0000 |
---|---|---|
committer | Michael Valenta | 2007-04-17 16:12:56 +0000 |
commit | ef8d6160070ed63da6e3888518ac9538f18ccd8a (patch) | |
tree | d4eca0d32ff1969a54a08537977c074ebef78d35 /bundles/org.eclipse.team.cvs.ui | |
parent | 47cc6ee0716cd5a1db8b4ddc5a90c9d645e133f7 (diff) | |
download | eclipse.platform.team-ef8d6160070ed63da6e3888518ac9538f18ccd8a.tar.gz eclipse.platform.team-ef8d6160070ed63da6e3888518ac9538f18ccd8a.tar.xz eclipse.platform.team-ef8d6160070ed63da6e3888518ac9538f18ccd8a.zip |
Bug 173959 add mechanism for navigating from team annotation to corresponding task
Diffstat (limited to 'bundles/org.eclipse.team.cvs.ui')
2 files changed, 385 insertions, 3 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java index e6192c1ec..3e0e3ebf0 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java @@ -7,8 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Eugene Kuleshov <eu@md.pp.ru> - Bug 173959 add mechanism for navigating from team annotation to corresponding task *******************************************************************************/ - package org.eclipse.team.internal.ccvs.ui.operations; import java.io.*; @@ -19,12 +19,17 @@ import org.eclipse.core.runtime.*; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.text.IInformationControl; +import org.eclipse.jface.text.IInformationControlCreator; import org.eclipse.jface.text.revisions.Revision; import org.eclipse.jface.text.revisions.RevisionInformation; import org.eclipse.jface.text.source.LineRange; import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; import org.eclipse.team.core.TeamException; import org.eclipse.team.core.variants.IResourceVariant; import org.eclipse.team.internal.ccvs.core.*; @@ -42,6 +47,7 @@ import org.eclipse.team.internal.ui.Utils; import org.eclipse.team.ui.TeamUI; import org.eclipse.team.ui.history.*; import org.eclipse.ui.*; +import org.eclipse.ui.editors.text.EditorsUI; import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor; import com.ibm.icu.text.DateFormat; @@ -253,6 +259,23 @@ public class ShowAnnotationOperation extends CVSOperation { final CommitterColors colors= CommitterColors.getDefault(); RevisionInformation info= new RevisionInformation(); + + class AnnotationControlCreator implements IInformationControlCreator { + private final String statusFieldText; + + public AnnotationControlCreator(String statusFieldText) { + this.statusFieldText = statusFieldText; + } + + public IInformationControl createInformationControl(Shell parent) { + return new SourceViewerInformationControl(parent, SWT.TOOL, + SWT.NONE, JFaceResources.DEFAULT_FONT, statusFieldText); + } + } + + info.setHoverControlCreator(new AnnotationControlCreator(EditorsUI.getTooltipAffordanceString())); + info.setInformationPresenterControlCreator(new AnnotationControlCreator(null)); + HashMap sets= new HashMap(); List annotateBlocks= listener.getCvsAnnotateBlocks(); for (Iterator blocks= annotateBlocks.iterator(); blocks.hasNext();) { @@ -269,8 +292,9 @@ public class ShowAnnotationOperation extends CVSOperation { public Object getHoverInfo() { if (entry != null) - return "<b>" + entry.getAuthor() + " " + entry.getRevision() + " " + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(entry.getDate()) + "</b><p>" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - entry.getComment() + "</p>"; //$NON-NLS-1$ + return entry.getAuthor() + " " + entry.getRevision() + " " + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(entry.getDate()) //$NON-NLS-1$ //$NON-NLS-2$ + + "\n\n" + entry.getComment(); //$NON-NLS-1$ + return block.toString().substring(0, block.toString().indexOf(" (")); //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/SourceViewerInformationControl.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/SourceViewerInformationControl.java new file mode 100644 index 000000000..9611f31fb --- /dev/null +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/SourceViewerInformationControl.java @@ -0,0 +1,358 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Eugene Kuleshov <eu@md.pp.ru> - Bug 173959 add mechanism for navigating from team annotation to corresponding task + *******************************************************************************/ +package org.eclipse.team.internal.ccvs.ui.operations; + +import java.util.Collections; +import java.util.Map; + +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.text.*; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.*; +import org.eclipse.ui.editors.text.EditorsUI; +import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; + +/** + * Source viewer based implementation of {@link org.eclipse.jface.text.IInformationControl}. + * Displays information in a source viewer. + * + * @since 3.0 + * + * This class is copied from org.eclipse.jface.text.source.projection.SourceViewerInformationControl + * Several changes are made in order to handle hover for CVS annotations + */ +class SourceViewerInformationControl implements IInformationControl, IInformationControlExtension, DisposeListener { + + /** Border thickness in pixels. */ + private static final int BORDER= 1; + + + /** The control's shell */ + private Shell fShell; + /** The control's text widget */ + private StyledText fText; + /** The control's source viewer */ + private SourceViewer fViewer; + /** The optional status field. */ + private Label fStatusField; + /** The separator for the optional status field. */ + private Label fSeparator; + /** The font of the optional status text label.*/ + private Font fStatusTextFont; + /** The maximal widget width. */ + private int fMaxWidth; + /** The maximal widget height. */ + private int fMaxHeight; + + + /** + * Creates a source viewer information control with the given shell as + * parent and the given font. + * + * @param parent the parent shell + * @param symbolicFontName the symbolic font name + */ + public SourceViewerInformationControl(Shell parent, String symbolicFontName) { + this(parent, SWT.NO_TRIM | SWT.TOOL, SWT.NONE, symbolicFontName, null); + } + + /** + * Creates a source viewer information control with the given shell as + * parent. The given shell styles are applied to the created shell. The + * given styles are applied to the created styled text widget. The text + * widget will be initialized with the given font. The status field will + * contain the given text or be hidden. + * + * @param parent the parent shell + * @param shellStyle the additional styles for the shell + * @param style the additional styles for the styled text widget + * @param symbolicFontName the symbolic font name + * @param statusFieldText the text to be used in the optional status field + * or <code>null</code> if the status field should be hidden + */ + public SourceViewerInformationControl(Shell parent, int shellStyle, int style, String symbolicFontName, String statusFieldText) { + GridLayout layout; + GridData gd; + + fShell= new Shell(parent, SWT.NO_FOCUS | SWT.ON_TOP | shellStyle); + Display display= fShell.getDisplay(); + fShell.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); + + Composite composite= fShell; + layout= new GridLayout(1, false); + int border= ((shellStyle & SWT.NO_TRIM) == 0) ? 0 : BORDER; + layout.marginHeight= border; + layout.marginWidth= border; + composite.setLayout(layout); + gd= new GridData(GridData.FILL_HORIZONTAL); + composite.setLayoutData(gd); + + if (statusFieldText != null) { + composite= new Composite(composite, SWT.NONE); + layout= new GridLayout(1, false); + layout.marginHeight= 0; + layout.marginWidth= 0; + composite.setLayout(layout); + gd= new GridData(GridData.FILL_BOTH); + composite.setLayoutData(gd); + composite.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); + composite.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + } + + // Source viewer + fViewer= new SourceViewer(composite, null, style); + fViewer.setEditable(false); + + // configure hyperlink detectors + // fViewer.configure(new SourceViewerConfiguration()); + fViewer.configure(new TextSourceViewerConfiguration(EditorsUI.getPreferenceStore()) { + protected Map getHyperlinkDetectorTargets(ISourceViewer sourceViewer) { + return Collections.singletonMap("org.eclipse.ui.DefaultTextEditor", //$NON-NLS-1$ + null); +// new IAdaptable() { +// public Object getAdapter(Class adapter) { +// // return Platform.getAdapterManager().getAdapter(CVSHistoryPage.this, adapter); +// return null; +// } +// }); + } + }); + + fText= fViewer.getTextWidget(); + gd= new GridData(GridData.BEGINNING | GridData.FILL_BOTH); + fText.setLayoutData(gd); + fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); + fText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + fText.setFont(JFaceResources.getFont(symbolicFontName)); + + fText.addKeyListener(new KeyListener() { + + public void keyPressed(KeyEvent e) { + if (e.character == 0x1B) // ESC + fShell.dispose(); + } + + public void keyReleased(KeyEvent e) {} + }); + + // Status field + if (statusFieldText != null) { + + // Horizontal separator line + fSeparator= new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT); + fSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + // Status field label + fStatusField= new Label(composite, SWT.RIGHT); + fStatusField.setText(statusFieldText); + Font font= fStatusField.getFont(); + FontData[] fontDatas= font.getFontData(); + for (int i= 0; i < fontDatas.length; i++) + fontDatas[i].setHeight(fontDatas[i].getHeight() * 9 / 10); + fStatusTextFont= new Font(fStatusField.getDisplay(), fontDatas); + fStatusField.setFont(fStatusTextFont); + GridData gd2= new GridData(GridData.FILL_VERTICAL | GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING); + fStatusField.setLayoutData(gd2); + + // Regarding the color see bug 41128 + fStatusField.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); + + fStatusField.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + } + + addDisposeListener(this); + } + + /** + * @see org.eclipse.jface.text.IInformationControlExtension2#setInput(java.lang.Object) + * @param input the input object + */ + public void setInput(Object input) { + if (input instanceof String) + setInformation((String)input); + else + setInformation(null); + } + + /* + * @see IInformationControl#setInformation(String) + */ + public void setInformation(String content) { + if (content == null) { + fViewer.setInput(null); + return; + } + + IDocument doc= new Document(content); + fViewer.setInput(doc); + + // decorate text + StyleRange styleRange = new StyleRange(); + styleRange.start = 0; + styleRange.length = content.indexOf('\n'); + styleRange.fontStyle = SWT.BOLD; + fViewer.getTextWidget().setStyleRange(styleRange); + } + + /* + * @see IInformationControl#setVisible(boolean) + */ + public void setVisible(boolean visible) { + fShell.setVisible(visible); + } + + /* + * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) + */ + public void widgetDisposed(DisposeEvent event) { + if (fStatusTextFont != null && !fStatusTextFont.isDisposed()) + fStatusTextFont.dispose(); + + fStatusTextFont= null; + fShell= null; + fText= null; + } + + /* + * @see org.eclipse.jface.text.IInformationControl#dispose() + */ + public final void dispose() { + if (fShell != null && !fShell.isDisposed()) + fShell.dispose(); + else + widgetDisposed(null); + } + + /* + * @see IInformationControl#setSize(int, int) + */ + public void setSize(int width, int height) { + + if (fStatusField != null) { + GridData gd= (GridData)fViewer.getTextWidget().getLayoutData(); + Point statusSize= fStatusField.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); + Point separatorSize= fSeparator.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); + gd.heightHint= height - statusSize.y - separatorSize.y; + } + fShell.setSize(width, height); + + if (fStatusField != null) + fShell.pack(true); + } + + /* + * @see IInformationControl#setLocation(Point) + */ + public void setLocation(Point location) { + fShell.setLocation(location); + } + + /* + * @see IInformationControl#setSizeConstraints(int, int) + */ + public void setSizeConstraints(int maxWidth, int maxHeight) { + fMaxWidth= maxWidth; + fMaxHeight= maxHeight; + } + + /* + * @see IInformationControl#computeSizeHint() + */ + public Point computeSizeHint() { + // compute the preferred size + int x= SWT.DEFAULT; + int y= SWT.DEFAULT; + Point size= fShell.computeSize(x, y); + if (size.x > fMaxWidth) + x= fMaxWidth; + if (size.y > fMaxHeight) + y= fMaxHeight; + + // recompute using the constraints if the preferred size is larger than the constraints + if (x != SWT.DEFAULT || y != SWT.DEFAULT) + size= fShell.computeSize(x, y, false); + + return size; + } + + /* + * @see IInformationControl#addDisposeListener(DisposeListener) + */ + public void addDisposeListener(DisposeListener listener) { + fShell.addDisposeListener(listener); + } + + /* + * @see IInformationControl#removeDisposeListener(DisposeListener) + */ + public void removeDisposeListener(DisposeListener listener) { + fShell.removeDisposeListener(listener); + } + + /* + * @see IInformationControl#setForegroundColor(Color) + */ + public void setForegroundColor(Color foreground) { + fText.setForeground(foreground); + } + + /* + * @see IInformationControl#setBackgroundColor(Color) + */ + public void setBackgroundColor(Color background) { + fText.setBackground(background); + } + + /* + * @see IInformationControl#isFocusControl() + */ + public boolean isFocusControl() { + return fText.isFocusControl(); + } + + /* + * @see IInformationControl#setFocus() + */ + public void setFocus() { + fShell.forceFocus(); + fText.setFocus(); + } + + /* + * @see IInformationControl#addFocusListener(FocusListener) + */ + public void addFocusListener(FocusListener listener) { + fText.addFocusListener(listener); + } + + /* + * @see IInformationControl#removeFocusListener(FocusListener) + */ + public void removeFocusListener(FocusListener listener) { + fText.removeFocusListener(listener); + } + + /* + * @see IInformationControlExtension#hasContents() + */ + public boolean hasContents() { + return fText.getCharCount() > 0; + } +}
\ No newline at end of file |