KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > propertiesfileeditor > PropertiesFileEditor


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.ui.propertiesfileeditor;
12
13 import org.eclipse.swt.SWT;
14
15 import org.eclipse.jface.preference.IPreferenceStore;
16 import org.eclipse.jface.util.PropertyChangeEvent;
17
18 import org.eclipse.jface.text.source.ISourceViewer;
19
20 import org.eclipse.ui.IPageLayout;
21 import org.eclipse.ui.part.IShowInTargetList;
22
23 import org.eclipse.ui.editors.text.TextEditor;
24
25 import org.eclipse.jdt.ui.JavaUI;
26 import org.eclipse.jdt.ui.actions.IJavaEditorActionDefinitionIds;
27 import org.eclipse.jdt.ui.actions.JdtActionConstants;
28 import org.eclipse.jdt.ui.text.JavaTextTools;
29
30 import org.eclipse.jdt.internal.ui.JavaPlugin;
31
32 /**
33  * Properties file editor.
34  *
35  * @since 3.1
36  */

37 public class PropertiesFileEditor extends TextEditor {
38
39
40     /** Open action. */
41     protected OpenAction fOpenAction;
42
43
44     /**
45      * Creates a new properties file editor.
46      */

47     public PropertiesFileEditor() {
48         setDocumentProvider(JavaPlugin.getDefault().getPropertiesFileDocumentProvider());
49         IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore();
50         setPreferenceStore(store);
51         JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools();
52         setSourceViewerConfiguration(new PropertiesFileSourceViewerConfiguration(textTools.getColorManager(), store, this, IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING));
53     }
54
55
56     /*
57      * @see org.eclipse.ui.editors.text.TextEditor#createActions()
58      */

59     protected void createActions() {
60         super.createActions();
61
62         fOpenAction= new OpenAction(this);
63         fOpenAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EDITOR);
64         setAction(JdtActionConstants.OPEN, fOpenAction);
65     }
66
67     /*
68      * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
69      */

70     protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
71
72         try {
73
74             ISourceViewer sourceViewer= getSourceViewer();
75             if (sourceViewer == null)
76                 return;
77
78             ((PropertiesFileSourceViewerConfiguration) getSourceViewerConfiguration()).handlePropertyChangeEvent(event);
79
80         } finally {
81             super.handlePreferenceStoreChanged(event);
82         }
83     }
84
85     /*
86      * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
87      */

88     protected boolean affectsTextPresentation(PropertyChangeEvent event) {
89         return ((PropertiesFileSourceViewerConfiguration)getSourceViewerConfiguration()).affectsTextPresentation(event) || super.affectsTextPresentation(event);
90     }
91
92
93     /*
94      * @see org.eclipse.ui.editors.text.TextEditor#getAdapter(java.lang.Class)
95      */

96     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
97         if (adapter == IShowInTargetList.class) {
98             return new IShowInTargetList() {
99                 public String JavaDoc[] getShowInTargetIds() {
100                     return new String JavaDoc[] { JavaUI.ID_PACKAGES, IPageLayout.ID_RES_NAV };
101                 }
102
103             };
104         }
105         return super.getAdapter(adapter);
106     }
107     
108     /*
109      * @see org.eclipse.ui.part.WorkbenchPart#getOrientation()
110      * @since 3.2
111      */

112     public int getOrientation() {
113         return SWT.LEFT_TO_RIGHT; // properties editors are always left to right by default (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=110986)
114
}
115
116     /*
117      * @see org.eclipse.ui.texteditor.StatusTextEditor#updateStatusField(java.lang.String)
118      */

119     protected void updateStatusField(String JavaDoc category) {
120         super.updateStatusField(category);
121         if (getEditorSite() != null) {
122             getEditorSite().getActionBars().getStatusLineManager().setMessage(null);
123             getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
124         }
125     }
126
127     /*
128      * @see org.eclipse.ui.texteditor.AbstractTextEditor#getSourceViewer()
129      */

130     ISourceViewer internalGetSourceViewer() {
131         return getSourceViewer();
132     }
133
134     /*
135      * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#collectContextMenuPreferencePages()
136      * @since 3.1
137      */

138     protected String JavaDoc[] collectContextMenuPreferencePages() {
139         String JavaDoc[] ids= super.collectContextMenuPreferencePages();
140         String JavaDoc[] more= new String JavaDoc[ids.length + 1];
141         more[0]= "org.eclipse.jdt.ui.preferences.PropertiesFileEditorPreferencePage"; //$NON-NLS-1$
142
System.arraycopy(ids, 0, more, 1, ids.length);
143         return more;
144     }
145 }
146
Popular Tags