KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > display > DisplayViewerConfiguration


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.display;
12
13
14 import org.eclipse.jdt.internal.debug.ui.JDIContentAssistPreference;
15 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
16 import org.eclipse.jdt.internal.debug.ui.contentassist.CurrentFrameContext;
17 import org.eclipse.jdt.internal.debug.ui.contentassist.JavaDebugContentAssistProcessor;
18 import org.eclipse.jdt.ui.PreferenceConstants;
19 import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 import org.eclipse.jface.text.BadLocationException;
22 import org.eclipse.jface.text.IDocument;
23 import org.eclipse.jface.text.ITextDoubleClickStrategy;
24 import org.eclipse.jface.text.ITextViewer;
25 import org.eclipse.jface.text.contentassist.ContentAssistant;
26 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
27 import org.eclipse.jface.text.contentassist.IContentAssistant;
28 import org.eclipse.jface.text.source.ISourceViewer;
29 import org.eclipse.ui.editors.text.EditorsUI;
30 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
31
32 /**
33  * The source viewer configuration for the Display view
34  */

35 public class DisplayViewerConfiguration extends JavaSourceViewerConfiguration {
36         
37     public DisplayViewerConfiguration() {
38         super(JDIDebugUIPlugin.getDefault().getJavaTextTools().getColorManager(),
39                 new ChainedPreferenceStore(new IPreferenceStore[] {
40                         PreferenceConstants.getPreferenceStore(),
41                         EditorsUI.getPreferenceStore()}),
42                 null, null);
43     }
44     
45     /**
46      * Returns the preference store this source viewer configuration is associated with.
47      *
48      * @return
49      */

50     public IPreferenceStore getTextPreferenceStore() {
51         return fPreferenceStore;
52     }
53
54     public IContentAssistProcessor getContentAssistantProcessor() {
55         return new JavaDebugContentAssistProcessor(new CurrentFrameContext());
56     }
57     
58     /* (non-Javadoc)
59      * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentAssistant(org.eclipse.jface.text.source.ISourceViewer)
60      */

61     public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
62
63         ContentAssistant assistant = new ContentAssistant();
64         assistant.setContentAssistProcessor(
65             getContentAssistantProcessor(),
66             IDocument.DEFAULT_CONTENT_TYPE);
67
68         JDIContentAssistPreference.configure(assistant, getColorManager());
69
70         assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
71         assistant.setInformationControlCreator(
72             getInformationControlCreator(sourceViewer));
73
74         return assistant;
75     }
76     
77     /* (non-Javadoc)
78      * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getDoubleClickStrategy(org.eclipse.jface.text.source.ISourceViewer, java.lang.String)
79      */

80     public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String JavaDoc contentType) {
81         ITextDoubleClickStrategy clickStrat = new ITextDoubleClickStrategy() {
82             // Highlight the whole line when double clicked. See Bug#45481
83
public void doubleClicked(ITextViewer viewer) {
84                 try {
85                     IDocument doc = viewer.getDocument();
86                     int caretOffset = viewer.getSelectedRange().x;
87                     int lineNum = doc.getLineOfOffset(caretOffset);
88                     int start = doc.getLineOffset(lineNum);
89                     int length = doc.getLineLength(lineNum);
90                     viewer.setSelectedRange(start, length);
91                 } catch (BadLocationException e) {
92                     JDIDebugUIPlugin.log(e);
93                 }
94             }
95         };
96         return clickStrat;
97     }
98 }
99
Popular Tags