修订版 | 181 (tree) |
---|---|
时间 | 2009-05-16 16:37:47 |
作者 | chomakichi |
ぷリファレンスのエンコード設定を除去
@@ -4,7 +4,6 @@ | ||
4 | 4 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.resources.Messages; |
5 | 5 | |
6 | 6 | import org.eclipse.core.resources.IProject; |
7 | -import org.eclipse.core.resources.ResourcesPlugin; | |
8 | 7 | import org.eclipse.core.runtime.CoreException; |
9 | 8 | import org.eclipse.core.runtime.IAdaptable; |
10 | 9 | import org.eclipse.core.runtime.ILog; |
@@ -29,8 +28,6 @@ | ||
29 | 28 | |
30 | 29 | public class PropertiesProperty extends PropertyPage { |
31 | 30 | |
32 | - public static final String P_ENCODE = "readEncode"; //$NON-NLS-1$ | |
33 | - | |
34 | 31 | public static final String P_NOT_CONVERT_COMMENT = "notConvertComment"; //$NON-NLS-1$ |
35 | 32 | |
36 | 33 | public static final String P_NOT_ALL_CONVERT = "notConvert"; //$NON-NLS-1$ |
@@ -40,15 +37,11 @@ | ||
40 | 37 | public static final String P_CONVERT_CHAR_CASE = "convertCharCase"; //$NON-NLS-1$ |
41 | 38 | |
42 | 39 | public static final String P_ORIGINAL_SETTINGS = "originalSettings"; //$NON-NLS-1$ |
43 | - | |
44 | - private String[] items = new String[] { System.getProperty("file.encoding"), "US-ASCII", "UTF-8", "UTF-16" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ | |
45 | 40 | |
46 | 41 | private String[] charCaseItems = new String[] { Messages.getString("eclipse.propertieseditor.preference.convert.char.uppercase"), Messages.getString("eclipse.propertieseditor.preference.convert.char.lowercase") }; //$NON-NLS-1$ //$NON-NLS-2$ |
47 | 42 | |
48 | 43 | private Button orgCheckBox = null; |
49 | 44 | |
50 | - private Combo encodeCombo = null; | |
51 | - | |
52 | 45 | private Text commentText = null; |
53 | 46 | |
54 | 47 | private Combo convertCharCaseCombo = null; |
@@ -73,7 +66,6 @@ | ||
73 | 66 | orgCheckBox.addSelectionListener(new SelectionAdapter() { |
74 | 67 | public void widgetSelected(SelectionEvent e) { |
75 | 68 | if (orgCheckBox.getSelection()) { |
76 | - encodeCombo.setEnabled(true); | |
77 | 69 | commentText.setEnabled(true); |
78 | 70 | convertCharCaseCombo.setEnabled(true); |
79 | 71 | notAllConvertCheckBox.setEnabled(true); |
@@ -83,7 +75,6 @@ | ||
83 | 75 | notConvertCommentCheckBox.setEnabled(true); |
84 | 76 | } |
85 | 77 | } else { |
86 | - encodeCombo.setEnabled(false); | |
87 | 78 | commentText.setEnabled(false); |
88 | 79 | convertCharCaseCombo.setEnabled(false); |
89 | 80 | notAllConvertCheckBox.setEnabled(false); |
@@ -97,13 +88,7 @@ | ||
97 | 88 | gd.horizontalSpan = 2; |
98 | 89 | separator.setLayoutData(gd); |
99 | 90 | |
100 | - Label label= new Label(composite, SWT.NONE); | |
101 | - label.setText(Messages.getString("eclipse.propertieseditor.preference.read.encode")); //$NON-NLS-1$ | |
102 | - | |
103 | - encodeCombo = new Combo(composite, SWT.DROP_DOWN); | |
104 | - encodeCombo.setItems(items); | |
105 | - | |
106 | - label = new Label(composite, SWT.NONE); | |
91 | + Label label = new Label(composite, SWT.NONE); | |
107 | 92 | label.setText(Messages.getString("eclipse.propertieseditor.preference.comment.character")); //$NON-NLS-1$ |
108 | 93 | |
109 | 94 | commentText = new Text(composite, SWT.BORDER); |
@@ -144,7 +129,6 @@ | ||
144 | 129 | |
145 | 130 | private void initialize() { |
146 | 131 | String org = null; |
147 | - String encode = null; | |
148 | 132 | String commentChar = null; |
149 | 133 | String charcase = null; |
150 | 134 | String notAllConvert = null; |
@@ -158,7 +142,6 @@ | ||
158 | 142 | project = (IProject)adaptable; |
159 | 143 | } |
160 | 144 | org = project.getPersistentProperty(new QualifiedName(PropertiesEditorPlugin.PLUGIN_ID, P_ORIGINAL_SETTINGS)); |
161 | - encode = project.getPersistentProperty(new QualifiedName(PropertiesEditorPlugin.PLUGIN_ID, P_ENCODE)); | |
162 | 145 | commentChar = project.getPersistentProperty(new QualifiedName(PropertiesEditorPlugin.PLUGIN_ID, P_COMMENT_CHARACTER)); |
163 | 146 | charcase = project.getPersistentProperty(new QualifiedName(PropertiesEditorPlugin.PLUGIN_ID, P_CONVERT_CHAR_CASE)); |
164 | 147 | notAllConvert = project.getPersistentProperty(new QualifiedName(PropertiesEditorPlugin.PLUGIN_ID, P_NOT_ALL_CONVERT)); |
@@ -170,11 +153,6 @@ | ||
170 | 153 | ErrorDialog.openError(null, Messages.getString("eclipse.propertieseditor.property.error_title"), Messages.getString("eclipse.propertieseditor.property.get.settings.error"), status); //$NON-NLS-1$ //$NON-NLS-2$ |
171 | 154 | } |
172 | 155 | |
173 | - if (encode != null) { | |
174 | - encodeCombo.setText(encode); | |
175 | - } else { | |
176 | - encodeCombo.setText(ResourcesPlugin.getEncoding()); | |
177 | - } | |
178 | 156 | if (commentChar != null) { |
179 | 157 | commentText.setText(commentChar); |
180 | 158 | } else { |
@@ -205,7 +183,6 @@ | ||
205 | 183 | if (org != null) { |
206 | 184 | orgCheckBox.setSelection(Boolean.valueOf(org).booleanValue()); |
207 | 185 | if (orgCheckBox.getSelection()) { |
208 | - encodeCombo.setEnabled(true); | |
209 | 186 | commentText.setEnabled(true); |
210 | 187 | convertCharCaseCombo.setEnabled(true); |
211 | 188 | notAllConvertCheckBox.setEnabled(true); |
@@ -215,7 +192,6 @@ | ||
215 | 192 | notConvertCommentCheckBox.setEnabled(true); |
216 | 193 | } |
217 | 194 | } else { |
218 | - encodeCombo.setEnabled(false); | |
219 | 195 | commentText.setEnabled(false); |
220 | 196 | convertCharCaseCombo.setEnabled(false); |
221 | 197 | notAllConvertCheckBox.setEnabled(false); |
@@ -223,7 +199,6 @@ | ||
223 | 199 | } |
224 | 200 | } else { |
225 | 201 | orgCheckBox.setSelection(false); |
226 | - encodeCombo.setEnabled(false); | |
227 | 202 | commentText.setEnabled(false); |
228 | 203 | convertCharCaseCombo.setEnabled(false); |
229 | 204 | notAllConvertCheckBox.setEnabled(false); |
@@ -237,9 +212,15 @@ | ||
237 | 212 | */ |
238 | 213 | protected void performApply() { |
239 | 214 | try { |
240 | - IProject project = (IProject)getElement(); | |
215 | + IAdaptable adapter = getElement(); | |
216 | + IProject project = null; | |
217 | + if (adapter instanceof IJavaProject) { | |
218 | + IJavaProject jp = (IJavaProject)adapter; | |
219 | + project = jp.getProject(); | |
220 | + } else { | |
221 | + project = (IProject)adapter; | |
222 | + } | |
241 | 223 | project.setPersistentProperty(new QualifiedName(PropertiesEditorPlugin.PLUGIN_ID, P_ORIGINAL_SETTINGS), Boolean.toString(orgCheckBox.getSelection())); |
242 | - project.setPersistentProperty(new QualifiedName(PropertiesEditorPlugin.PLUGIN_ID, P_ENCODE), encodeCombo.getText()); | |
243 | 224 | project.setPersistentProperty(new QualifiedName(PropertiesEditorPlugin.PLUGIN_ID, P_COMMENT_CHARACTER), commentText.getText()); |
244 | 225 | project.setPersistentProperty(new QualifiedName(PropertiesEditorPlugin.PLUGIN_ID, P_CONVERT_CHAR_CASE), convertCharCaseCombo.getText()); |
245 | 226 | project.setPersistentProperty(new QualifiedName(PropertiesEditorPlugin.PLUGIN_ID, P_NOT_ALL_CONVERT), Boolean.toString(notAllConvertCheckBox.getSelection())); |
@@ -248,12 +229,11 @@ | ||
248 | 229 | IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e); |
249 | 230 | ILog log = PropertiesEditorPlugin.getDefault().getLog(); |
250 | 231 | log.log(status); |
251 | - ErrorDialog.openError(null, Messages.getString("eclipse.propertieseditor.property.error_title"), Messages.getString("eclipse.propertieseditor.property.save.settings.error"), status); //$NON-NLS-1$ //$NON-NLS-2$ | |
232 | + ErrorDialog.openError(getShell(), Messages.getString("eclipse.propertieseditor.property.error_title"), Messages.getString("eclipse.propertieseditor.property.save.settings.error"), status); //$NON-NLS-1$ //$NON-NLS-2$ | |
252 | 233 | } |
253 | 234 | } |
254 | 235 | |
255 | 236 | protected void performDefaults() { |
256 | - encodeCombo.setText(ResourcesPlugin.getEncoding()); | |
257 | 237 | commentText.setText("#"); //$NON-NLS-1$ |
258 | 238 | convertCharCaseCombo.setText(Messages.getString("eclipse.propertieseditor.preference.convert.char.lowercase")); |
259 | 239 | notAllConvertCheckBox.setSelection(false); |
@@ -260,7 +240,6 @@ | ||
260 | 240 | notConvertCommentCheckBox.setEnabled(false); |
261 | 241 | notConvertCommentCheckBox.setSelection(false); |
262 | 242 | orgCheckBox.setSelection(false); |
263 | - encodeCombo.setEnabled(false); | |
264 | 243 | commentText.setEnabled(false); |
265 | 244 | convertCharCaseCombo.setEnabled(false); |
266 | 245 | notAllConvertCheckBox.setEnabled(false); |
@@ -12,30 +12,6 @@ | ||
12 | 12 | import org.eclipse.jface.dialogs.ErrorDialog; |
13 | 13 | |
14 | 14 | public class PropertyUtil { |
15 | - | |
16 | - public static String getEncode(IProject project, String preference) { | |
17 | - String org = null; | |
18 | - String encode = null; | |
19 | - try { | |
20 | - org = project.getPersistentProperty(new QualifiedName(PropertiesEditorPlugin.PLUGIN_ID, PropertiesProperty.P_ORIGINAL_SETTINGS)); | |
21 | - encode = project.getPersistentProperty(new QualifiedName(PropertiesEditorPlugin.PLUGIN_ID, PropertiesProperty.P_ENCODE)); | |
22 | - } catch (CoreException e) { | |
23 | - IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e); | |
24 | - ILog log = PropertiesEditorPlugin.getDefault().getLog(); | |
25 | - log.log(status); | |
26 | - ErrorDialog.openError(null, Messages.getString("eclipse.propertieseditor.property.error_title"), Messages.getString("eclipse.propertieseditor.property.get.settings.error"), status); //$NON-NLS-1$ //$NON-NLS-2$ | |
27 | - } | |
28 | - if (org != null) { | |
29 | - if (Boolean.valueOf(org).booleanValue()) { | |
30 | - if (encode == null || encode.equals("")) { //$NON-NLS-1$ | |
31 | - return preference; | |
32 | - } else { | |
33 | - return encode; | |
34 | - } | |
35 | - } | |
36 | - } | |
37 | - return preference; | |
38 | - } | |
39 | 15 | |
40 | 16 | public static String getCommentChar(IProject project, String preference) { |
41 | 17 | String org = null; |
@@ -1,252 +0,0 @@ | ||
1 | -package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors; | |
2 | - | |
3 | -import java.net.MalformedURLException; | |
4 | -import java.net.URL; | |
5 | - | |
6 | -import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin; | |
7 | -import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.preference.PropertiesEditorPreference; | |
8 | -import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.preference.PropertiesPreference; | |
9 | -import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.property.PropertyUtil; | |
10 | -import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.resources.Messages; | |
11 | -import jp.gr.java_conf.ussiy.app.propedit.util.EncodeChanger; | |
12 | - | |
13 | -import org.eclipse.core.resources.IMarker; | |
14 | -import org.eclipse.core.resources.IProject; | |
15 | -import org.eclipse.core.runtime.ILog; | |
16 | -import org.eclipse.core.runtime.IProgressMonitor; | |
17 | -import org.eclipse.core.runtime.IStatus; | |
18 | -import org.eclipse.core.runtime.Status; | |
19 | -import org.eclipse.jface.dialogs.ErrorDialog; | |
20 | -import org.eclipse.jface.preference.IPreferenceStore; | |
21 | -import org.eclipse.jface.preference.PreferenceConverter; | |
22 | -import org.eclipse.jface.resource.ImageDescriptor; | |
23 | -import org.eclipse.jface.util.IPropertyChangeListener; | |
24 | -import org.eclipse.jface.util.PropertyChangeEvent; | |
25 | -import org.eclipse.swt.SWT; | |
26 | -import org.eclipse.swt.custom.CTabFolder; | |
27 | -import org.eclipse.swt.custom.StyledText; | |
28 | -import org.eclipse.swt.graphics.Color; | |
29 | -import org.eclipse.swt.graphics.Image; | |
30 | -import org.eclipse.swt.graphics.RGB; | |
31 | -import org.eclipse.swt.layout.FillLayout; | |
32 | -import org.eclipse.swt.widgets.Composite; | |
33 | -import org.eclipse.swt.widgets.Display; | |
34 | -import org.eclipse.ui.IEditorInput; | |
35 | -import org.eclipse.ui.IEditorPart; | |
36 | -import org.eclipse.ui.IEditorSite; | |
37 | -import org.eclipse.ui.IFileEditorInput; | |
38 | -import org.eclipse.ui.IWorkbenchPreferenceConstants; | |
39 | -import org.eclipse.ui.PartInitException; | |
40 | -import org.eclipse.ui.ide.IDE; | |
41 | -import org.eclipse.ui.ide.IGotoMarker; | |
42 | -import org.eclipse.ui.part.MultiPageEditorPart; | |
43 | - | |
44 | -/** | |
45 | - * An example showing how to create a multi-page editor. This example has 2 pages: | |
46 | - */ | |
47 | -public class MultiPagePropertiesEditor extends MultiPageEditorPart implements IGotoMarker { | |
48 | - | |
49 | - /** The text editor used in page 0. */ | |
50 | - private PropertiesEditor editor; | |
51 | - | |
52 | - /** The text widget used in page 1. */ | |
53 | - private StyledText text; | |
54 | - | |
55 | - /** | |
56 | - * Creates a multi-page editor example. | |
57 | - */ | |
58 | - public MultiPagePropertiesEditor() { | |
59 | - super(); | |
60 | - } | |
61 | - | |
62 | - /** | |
63 | - * Creates page 0 of the multi-page editor, which contains a text editor. | |
64 | - */ | |
65 | - void createPage0() { | |
66 | - URL url = PropertiesEditorPlugin.getDefault().getBundle().getEntry("/"); //$NON-NLS-1$ | |
67 | - String path = "icons/editPage.gif"; //$NON-NLS-1$ | |
68 | - ImageDescriptor descriptor = null; | |
69 | - try { | |
70 | - descriptor = ImageDescriptor.createFromURL(new URL(url, path)); | |
71 | - } catch (MalformedURLException e) { | |
72 | - descriptor = ImageDescriptor.getMissingImageDescriptor(); | |
73 | - } | |
74 | - Image image = descriptor.createImage(); | |
75 | - try { | |
76 | - editor = new PropertiesEditor(); | |
77 | - int index = addPage(editor, getEditorInput()); | |
78 | - setPageText(index, Messages.getString("eclipse.tabname.edit")); //$NON-NLS-1$ | |
79 | - setPartName(editor.getTitle()); | |
80 | - setPageImage(index, image); | |
81 | - IPreferenceStore pStore = PropertiesEditorPlugin.getDefault().getPreferenceStore(); | |
82 | - RGB rgb = PreferenceConverter.getColor(pStore, PropertiesEditorPreference.P_BACKGROUND_COLOR); | |
83 | - Color color = new ColorManager().getColor(rgb); | |
84 | - editor.setBackground(color); | |
85 | - } catch (PartInitException e) { | |
86 | - ErrorDialog.openError(getSite().getShell(), "Error creating nested text editor", null, e.getStatus()); //$NON-NLS-1$ | |
87 | - } | |
88 | - } | |
89 | - | |
90 | - /** | |
91 | - * Creates page 1 of the multi-page editor. | |
92 | - */ | |
93 | - void createPage1() { | |
94 | - URL url = PropertiesEditorPlugin.getDefault().getBundle().getEntry("/"); //$NON-NLS-1$ | |
95 | - String path = "icons/previewPage.gif"; //$NON-NLS-1$ | |
96 | - ImageDescriptor descriptor = null; | |
97 | - try { | |
98 | - descriptor = ImageDescriptor.createFromURL(new URL(url, path)); | |
99 | - } catch (MalformedURLException e) { | |
100 | - descriptor = ImageDescriptor.getMissingImageDescriptor(); | |
101 | - } | |
102 | - Image image = descriptor.createImage(); | |
103 | - | |
104 | - Composite composite = new Composite(getContainer(), SWT.NONE); | |
105 | - FillLayout layout = new FillLayout(); | |
106 | - composite.setLayout(layout); | |
107 | - text = new StyledText(composite, SWT.H_SCROLL | SWT.V_SCROLL); | |
108 | - text.setEditable(false); | |
109 | - Display display = Display.getCurrent(); | |
110 | - RGB rgb = new RGB(240, 240, 240); | |
111 | - Color color = new Color(display, rgb); | |
112 | - text.setBackground(color); | |
113 | - | |
114 | - int index = addPage(composite); | |
115 | - setPageText(index, Messages.getString("eclipse.tabname.preview")); //$NON-NLS-1$ | |
116 | - setPageImage(index, image); | |
117 | - } | |
118 | - | |
119 | - /** | |
120 | - * Creates the pages of the multi-page editor. | |
121 | - */ | |
122 | - protected void createPages() { | |
123 | - | |
124 | - createPage0(); | |
125 | - createPage1(); | |
126 | - | |
127 | - IPreferenceStore apiStore = PropertiesEditorPlugin.getDefault().getPreferenceStore(); | |
128 | - | |
129 | - Composite container = getContainer(); | |
130 | - if (container != null && container instanceof CTabFolder) { | |
131 | - apiStore.addPropertyChangeListener( | |
132 | - new IPropertyChangeListener() { | |
133 | - public void propertyChange(PropertyChangeEvent event) { | |
134 | - if (IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS.equals(event.getProperty())) { | |
135 | - setTabStyle(); | |
136 | - } | |
137 | - } | |
138 | - } | |
139 | - ); | |
140 | - CTabFolder tabFolder = (CTabFolder)getContainer(); | |
141 | - | |
142 | - Display display = Display.getCurrent(); | |
143 | - Color titleForeColor = display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND); | |
144 | - Color titleBackColor1 = display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND); | |
145 | - Color titleBackColor2 = display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT); | |
146 | - | |
147 | - tabFolder.setSelectionForeground(titleForeColor); | |
148 | - tabFolder.setSelectionBackground( | |
149 | - new Color[] {titleBackColor1, titleBackColor2}, | |
150 | - new int[] {100}, | |
151 | - true | |
152 | - ); | |
153 | - setTabStyle(); | |
154 | - } | |
155 | - } | |
156 | - | |
157 | - protected void setTabStyle() { | |
158 | - IPreferenceStore apiStore = PropertiesEditorPlugin.getDefault().getPreferenceStore(); | |
159 | - boolean simple = apiStore.getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS); | |
160 | - | |
161 | - Composite container = getContainer(); | |
162 | - if (container != null && container instanceof CTabFolder) { | |
163 | - CTabFolder tabFolder = (CTabFolder)getContainer(); | |
164 | - tabFolder.setSimple(simple); | |
165 | - } | |
166 | - | |
167 | - } | |
168 | - | |
169 | - /** | |
170 | - * Saves the multi-page editor's document. | |
171 | - */ | |
172 | - public void doSave(IProgressMonitor monitor) { | |
173 | - | |
174 | - getEditor(0).doSave(monitor); | |
175 | - } | |
176 | - | |
177 | - /** | |
178 | - * Saves the multi-page editor's document as another file. Also updates the text for page 0's tab, and updates this multi-page editor's input to correspond to the nested editor's. | |
179 | - */ | |
180 | - public void doSaveAs() { | |
181 | - | |
182 | - IEditorPart editor = getEditor(0); | |
183 | - editor.doSaveAs(); | |
184 | - setPageText(0, editor.getTitle()); | |
185 | - setInput(editor.getEditorInput()); | |
186 | - } | |
187 | - | |
188 | - public void gotoMarker(IMarker marker) { | |
189 | - | |
190 | - setActivePage(0); | |
191 | - IDE.gotoMarker(getEditor(0), marker); | |
192 | - } | |
193 | - | |
194 | - public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException { | |
195 | - | |
196 | - // if (!(editorInput instanceof IFileEditorInput)) { | |
197 | - // throw new PartInitException( | |
198 | - // "Invalid Input: Must be IFileEditorInput"); | |
199 | - // } | |
200 | - super.init(site, editorInput); | |
201 | - } | |
202 | - | |
203 | - public boolean isSaveAsAllowed() { | |
204 | - | |
205 | - return true; | |
206 | - } | |
207 | - | |
208 | - protected void pageChange(int newPageIndex) { | |
209 | - | |
210 | - super.pageChange(newPageIndex); | |
211 | - String editorText = editor.getDocumentProvider().getDocument(editor.getEditorInput()).get(); | |
212 | - IProject project = ((IFileEditorInput)editor.getEditorInput()).getFile().getProject(); | |
213 | - if (PropertyUtil.getNotConvertComment(project, PropertiesEditorPlugin.getDefault().getPreferenceStore().getBoolean(PropertiesPreference.P_NOT_CONVERT_COMMENT))) { | |
214 | - String charcase = PropertyUtil.getCharCase(project, PropertiesEditorPlugin.getDefault().getPreferenceStore().getString(PropertiesPreference.P_CONVERT_CHAR_CASE)); | |
215 | - try { | |
216 | - if (Messages.getString("eclipse.propertieseditor.preference.convert.char.uppercase").equals(charcase)) { //$NON-NLS-1$ | |
217 | - text.setText(EncodeChanger.unicode2UnicodeEscWithoutComment(editorText, EncodeChanger.UPPERCASE)); | |
218 | - } else { | |
219 | - text.setText(EncodeChanger.unicode2UnicodeEscWithoutComment(editorText, EncodeChanger.LOWERCASE)); | |
220 | - } | |
221 | - } catch (Exception e) { | |
222 | - IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e); | |
223 | - ILog log = PropertiesEditorPlugin.getDefault().getLog(); | |
224 | - log.log(status); | |
225 | - ErrorDialog.openError(null, Messages.getString("eclipse.propertieseditor.convert.error"), Messages.getString("eclipse.propertieseditor.property.get.settings.error"), status); //$NON-NLS-1$ //$NON-NLS-2$ | |
226 | - } | |
227 | - } else { | |
228 | - text.setText(EncodeChanger.unicode2UnicodeEsc(editorText)); | |
229 | - } | |
230 | - } | |
231 | - | |
232 | - public PropertiesEditor getEditor() { | |
233 | - | |
234 | - return editor; | |
235 | - } | |
236 | - | |
237 | - /** | |
238 | - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) | |
239 | - */ | |
240 | - public Object getAdapter(Class adapter) { | |
241 | - return getEditor().getAdapter(adapter); | |
242 | - } | |
243 | - | |
244 | - /** | |
245 | - * @see org.eclipse.ui.IWorkbenchPart#dispose() | |
246 | - */ | |
247 | - public void dispose() { | |
248 | - editor.dispose(); | |
249 | - text.dispose(); | |
250 | - super.dispose(); | |
251 | - } | |
252 | -} | |
\ No newline at end of file |
@@ -1,238 +0,0 @@ | ||
1 | -package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors; | |
2 | - | |
3 | -import java.io.BufferedReader; | |
4 | -import java.io.IOException; | |
5 | -import java.io.StringReader; | |
6 | -import java.util.ArrayList; | |
7 | -import java.util.List; | |
8 | - | |
9 | -import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.PropertiesContentOutlinePage.Segment; | |
10 | - | |
11 | -import org.eclipse.jface.text.BadPositionCategoryException; | |
12 | -import org.eclipse.jface.text.DefaultPositionUpdater; | |
13 | -import org.eclipse.jface.text.DocumentEvent; | |
14 | -import org.eclipse.jface.text.IDocument; | |
15 | -import org.eclipse.jface.text.IDocumentListener; | |
16 | -import org.eclipse.jface.text.IPositionUpdater; | |
17 | -import org.eclipse.jface.text.Position; | |
18 | -import org.eclipse.jface.viewers.ITreeContentProvider; | |
19 | -import org.eclipse.jface.viewers.Viewer; | |
20 | - | |
21 | -/** | |
22 | - * Divides the editor's document into ten segments and provides elements for | |
23 | - * them. | |
24 | - */ | |
25 | -class PropertiesOutlineContentProvider implements ITreeContentProvider, IDocumentListener { | |
26 | - | |
27 | - private final PropertiesContentOutlinePage fContentOutlinePage; | |
28 | - | |
29 | - /** | |
30 | - * @param page | |
31 | - */ | |
32 | - PropertiesOutlineContentProvider(PropertiesContentOutlinePage page) { | |
33 | - this.fContentOutlinePage = page; | |
34 | - } | |
35 | - | |
36 | - protected final static String SEGMENTS = "__properties_segments"; //$NON-NLS-1$ | |
37 | - | |
38 | - protected IPositionUpdater fPositionUpdater = new DefaultPositionUpdater( | |
39 | - SEGMENTS); | |
40 | - | |
41 | - protected List fContent = new ArrayList(10); | |
42 | - | |
43 | - protected void parse(IDocument document) { | |
44 | - String line = null; | |
45 | - int cntLine = 0; | |
46 | - boolean multipleValueFlg = false; | |
47 | - | |
48 | - BufferedReader reader = null; | |
49 | - try { | |
50 | - reader = new BufferedReader(new StringReader(document.get())); | |
51 | - while ((line = reader.readLine()) != null) { | |
52 | - cntLine++; | |
53 | - if (multipleValueFlg) { | |
54 | - if (line.endsWith("\\")) { //$NON-NLS-1$ | |
55 | - multipleValueFlg = true; | |
56 | - } else { | |
57 | - multipleValueFlg = false; | |
58 | - } | |
59 | - continue; | |
60 | - } else { | |
61 | - if (line.trim().equals("") || line.trim().startsWith("#") || line.trim().startsWith("!")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
62 | - continue; | |
63 | - } | |
64 | - } | |
65 | - line = line.trim(); | |
66 | - boolean escapeFlg = false; | |
67 | - boolean nonSeparate = true; | |
68 | - for (int i = 0; i < line.length(); i++) { | |
69 | - char achar = line.charAt(i); | |
70 | - if (achar == '\\') { | |
71 | - if (escapeFlg) { | |
72 | - String tmp = line; | |
73 | - line = ""; //$NON-NLS-1$ | |
74 | - line = tmp.substring(0, i); | |
75 | - line += tmp.substring(i + 1, tmp.length()); | |
76 | - escapeFlg = false; | |
77 | - i--; | |
78 | - } else { | |
79 | - escapeFlg = true; | |
80 | - } | |
81 | - } else if (achar == '=' || achar == '\t' || achar == ':' || achar == ' ') { | |
82 | - if (escapeFlg) { | |
83 | - String tmp = line; | |
84 | - line = ""; //$NON-NLS-1$ | |
85 | - line = tmp.substring(0, i - 1); | |
86 | - line += tmp.substring(i, tmp.length()); | |
87 | - escapeFlg = false; | |
88 | - i--; | |
89 | - continue; | |
90 | - } else { | |
91 | - int offset = document.getLineOffset(cntLine - 1); | |
92 | - Position p = new Position(offset, i); | |
93 | - document.addPosition(SEGMENTS, p); | |
94 | - | |
95 | - fContent.add(new Segment(line.substring(0, i).trim(), p)); //$NON-NLS-1$ | |
96 | - | |
97 | - nonSeparate = false; | |
98 | - escapeFlg = false; | |
99 | - break; | |
100 | - } | |
101 | - } else { | |
102 | - if (escapeFlg) { | |
103 | - String tmp = line; | |
104 | - line = ""; //$NON-NLS-1$ | |
105 | - line = tmp.substring(0, i - 1); | |
106 | - line += tmp.substring(i, tmp.length()); | |
107 | - i--; | |
108 | - } | |
109 | - escapeFlg = false; | |
110 | - } | |
111 | - } | |
112 | - if (nonSeparate) { | |
113 | - if (line.endsWith("\\")) { //$NON-NLS-1$ | |
114 | - continue; | |
115 | - } | |
116 | - } | |
117 | - if (line.endsWith("\\")) { //$NON-NLS-1$ | |
118 | - multipleValueFlg = true; | |
119 | - } else { | |
120 | - multipleValueFlg = false; | |
121 | - } | |
122 | - } | |
123 | - | |
124 | - } catch (Exception e) { | |
125 | - e.printStackTrace(); | |
126 | - } finally { | |
127 | - try { | |
128 | - if (reader != null) { | |
129 | - reader.close(); | |
130 | - } | |
131 | - } catch (IOException e) { | |
132 | - } | |
133 | - } | |
134 | - | |
135 | - } | |
136 | - | |
137 | - /* | |
138 | - * @see IContentProvider#inputChanged(Viewer, Object, Object) | |
139 | - */ | |
140 | - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | |
141 | - if (oldInput != null) { | |
142 | - IDocument document = this.fContentOutlinePage.fDocumentProvider | |
143 | - .getDocument(oldInput); | |
144 | - if (document != null) { | |
145 | - try { | |
146 | - document.removePositionCategory(SEGMENTS); | |
147 | - } catch (BadPositionCategoryException x) { | |
148 | - } | |
149 | - document.removePositionUpdater(fPositionUpdater); | |
150 | - } | |
151 | - } | |
152 | - | |
153 | - fContent.clear(); | |
154 | - | |
155 | - if (newInput != null) { | |
156 | - IDocument document = this.fContentOutlinePage.fDocumentProvider | |
157 | - .getDocument(newInput); | |
158 | - if (document != null) { | |
159 | - document.addPositionCategory(SEGMENTS); | |
160 | - document.addPositionUpdater(fPositionUpdater); | |
161 | - | |
162 | - parse(document); | |
163 | - } | |
164 | - } | |
165 | - } | |
166 | - | |
167 | - /* | |
168 | - * @see IContentProvider#dispose | |
169 | - */ | |
170 | - public void dispose() { | |
171 | - if (fContent != null) { | |
172 | - fContent.clear(); | |
173 | - fContent = null; | |
174 | - } | |
175 | - } | |
176 | - | |
177 | - /* | |
178 | - * @see IContentProvider#isDeleted(Object) | |
179 | - */ | |
180 | - public boolean isDeleted(Object element) { | |
181 | - return false; | |
182 | - } | |
183 | - | |
184 | - /* | |
185 | - * @see IStructuredContentProvider#getElements(Object) | |
186 | - */ | |
187 | - public Object[] getElements(Object element) { | |
188 | - return fContent.toArray(); | |
189 | - } | |
190 | - | |
191 | - /* | |
192 | - * @see ITreeContentProvider#hasChildren(Object) | |
193 | - */ | |
194 | - public boolean hasChildren(Object element) { | |
195 | - return element == this.fContentOutlinePage.fInput; | |
196 | - } | |
197 | - | |
198 | - /* | |
199 | - * @see ITreeContentProvider#getParent(Object) | |
200 | - */ | |
201 | - public Object getParent(Object element) { | |
202 | - if (element instanceof Segment) | |
203 | - return this.fContentOutlinePage.fInput; | |
204 | - return null; | |
205 | - } | |
206 | - | |
207 | - /* | |
208 | - * @see ITreeContentProvider#getChildren(Object) | |
209 | - */ | |
210 | - public Object[] getChildren(Object element) { | |
211 | - if (element == this.fContentOutlinePage.fInput) | |
212 | - return fContent.toArray(); | |
213 | - return new Object[0]; | |
214 | - } | |
215 | - | |
216 | - /** | |
217 | - * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent) | |
218 | - */ | |
219 | - public void documentAboutToBeChanged(DocumentEvent event) { | |
220 | - } | |
221 | - | |
222 | - /** | |
223 | - * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent) | |
224 | - */ | |
225 | - public void documentChanged(DocumentEvent event) { | |
226 | -// try { | |
227 | -// event.getDocument().removePositionCategory(SEGMENTS); | |
228 | -// } catch (BadPositionCategoryException x) { | |
229 | -// } | |
230 | -// event.getDocument().removePositionUpdater(fPositionUpdater); | |
231 | -// fContent.clear(); | |
232 | -// event.getDocument().addPositionCategory(SEGMENTS); | |
233 | -// event.getDocument().addPositionUpdater(fPositionUpdater); | |
234 | -// parse(event.getDocument()); | |
235 | -// fContentOutlinePage.update(); | |
236 | - } | |
237 | - | |
238 | -} | |
\ No newline at end of file |
@@ -1,43 +0,0 @@ | ||
1 | -package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors; | |
2 | - | |
3 | -import java.net.MalformedURLException; | |
4 | -import java.net.URL; | |
5 | - | |
6 | -import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin; | |
7 | - | |
8 | -import org.eclipse.jface.resource.ImageDescriptor; | |
9 | -import org.eclipse.jface.viewers.LabelProvider; | |
10 | -import org.eclipse.swt.graphics.Image; | |
11 | - | |
12 | -public class PropertiesOutlineLabelProvider extends LabelProvider { | |
13 | - protected static Image markerImage; | |
14 | - | |
15 | - /** | |
16 | - * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) | |
17 | - */ | |
18 | - public Image getImage(Object element) { | |
19 | - if (markerImage != null && !markerImage.isDisposed()) { | |
20 | - return markerImage; | |
21 | - } | |
22 | - URL url = PropertiesEditorPlugin.getDefault().getBundle().getEntry("/"); //$NON-NLS-1$ | |
23 | - String path = "icons/outlineMarker.gif"; //$NON-NLS-1$ | |
24 | - ImageDescriptor descriptor = null; | |
25 | - try { | |
26 | - descriptor = ImageDescriptor.createFromURL(new URL(url, path)); | |
27 | - } catch (MalformedURLException e) { | |
28 | - descriptor = ImageDescriptor.getMissingImageDescriptor(); | |
29 | - } | |
30 | - markerImage = descriptor.createImage(); | |
31 | - return markerImage; | |
32 | - } | |
33 | - | |
34 | - /** | |
35 | - * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() | |
36 | - */ | |
37 | - public void dispose() { | |
38 | - super.dispose(); | |
39 | - if (markerImage != null) { | |
40 | - markerImage.dispose(); | |
41 | - } | |
42 | - } | |
43 | -} |
@@ -1,186 +0,0 @@ | ||
1 | -package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors; | |
2 | - | |
3 | -import java.net.MalformedURLException; | |
4 | -import java.net.URL; | |
5 | - | |
6 | -import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin; | |
7 | -import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.resources.Messages; | |
8 | - | |
9 | -import org.eclipse.jface.action.Action; | |
10 | -import org.eclipse.jface.action.IToolBarManager; | |
11 | -import org.eclipse.jface.resource.ImageDescriptor; | |
12 | -import org.eclipse.jface.text.Position; | |
13 | -import org.eclipse.jface.viewers.ISelection; | |
14 | -import org.eclipse.jface.viewers.IStructuredSelection; | |
15 | -import org.eclipse.jface.viewers.SelectionChangedEvent; | |
16 | -import org.eclipse.jface.viewers.TreeViewer; | |
17 | -import org.eclipse.jface.viewers.ViewerSorter; | |
18 | -import org.eclipse.swt.widgets.Composite; | |
19 | -import org.eclipse.swt.widgets.Control; | |
20 | -import org.eclipse.ui.texteditor.IDocumentProvider; | |
21 | -import org.eclipse.ui.texteditor.ITextEditor; | |
22 | -import org.eclipse.ui.views.contentoutline.ContentOutlinePage; | |
23 | - | |
24 | -public class PropertiesContentOutlinePage extends ContentOutlinePage { | |
25 | - protected static String ALPHA_SORT_BTN_CHECK_KEY = "jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.alphaSortCheckKey"; //$NON-NLS-1$ | |
26 | - | |
27 | - /** | |
28 | - * A segment element. | |
29 | - */ | |
30 | - protected static class Segment { | |
31 | - public String name; | |
32 | - public Position position; | |
33 | - | |
34 | - public Segment(String name, Position position) { | |
35 | - this.name= name; | |
36 | - this.position= position; | |
37 | - } | |
38 | - | |
39 | - public String toString() { | |
40 | - return name; | |
41 | - } | |
42 | - } | |
43 | - | |
44 | - protected Object fInput; | |
45 | - protected IDocumentProvider fDocumentProvider; | |
46 | - protected ITextEditor fTextEditor; | |
47 | - protected PropertiesOutlineContentProvider contentProvider; | |
48 | - | |
49 | - protected static ImageDescriptor sortImageDescriptor; | |
50 | - | |
51 | - /** | |
52 | - * Creates a content outline page using the given provider and the given editor. | |
53 | - */ | |
54 | - public PropertiesContentOutlinePage(IDocumentProvider provider, ITextEditor editor) { | |
55 | - super(); | |
56 | - fDocumentProvider= provider; | |
57 | - fTextEditor= editor; | |
58 | - fDocumentProvider.getDocument(fTextEditor.getEditorInput()).addDocumentListener(getContentProvider()); | |
59 | - } | |
60 | - | |
61 | - protected PropertiesOutlineContentProvider getContentProvider() { | |
62 | - if (contentProvider == null) { | |
63 | - contentProvider = new PropertiesOutlineContentProvider(this); | |
64 | - } | |
65 | - return contentProvider; | |
66 | - } | |
67 | - | |
68 | - /** | |
69 | - * Method declared on ContentOutlinePage | |
70 | - */ | |
71 | - public void createControl(Composite parent) { | |
72 | - | |
73 | - super.createControl(parent); | |
74 | - | |
75 | - // create tree viewer | |
76 | - TreeViewer viewer= getTreeViewer(); | |
77 | - viewer.setContentProvider(getContentProvider()); | |
78 | - viewer.setLabelProvider(new PropertiesOutlineLabelProvider()); | |
79 | - viewer.addSelectionChangedListener(this); | |
80 | - | |
81 | - if (fInput != null) | |
82 | - viewer.setInput(fInput); | |
83 | - | |
84 | - // create toolbar action | |
85 | - PropertiesEditorPlugin.getDefault().getPluginPreferences().setDefault(ALPHA_SORT_BTN_CHECK_KEY, false); | |
86 | - IToolBarManager toolbar = getSite().getActionBars().getToolBarManager(); | |
87 | - String label = Messages.getString("eclipse.contentoutline.sort.label"); //$NON-NLS-1$ | |
88 | - Action action = new Action(label, Action.AS_CHECK_BOX) { | |
89 | - public void run() { | |
90 | - PropertiesEditorPlugin.getDefault().getPluginPreferences().setValue(ALPHA_SORT_BTN_CHECK_KEY, isChecked()); | |
91 | - if (isChecked()) { | |
92 | - TreeViewer v = getTreeViewer(); | |
93 | - v.setSorter(new ViewerSorter()); | |
94 | - v.setInput(v.getInput()); | |
95 | - } else { | |
96 | - getTreeViewer().setSorter(null); | |
97 | - redraw(); | |
98 | - } | |
99 | - } | |
100 | - }; | |
101 | - action.setToolTipText(action.getText()); | |
102 | - if (sortImageDescriptor == null) { | |
103 | - URL url = PropertiesEditorPlugin.getDefault().getBundle().getEntry("/"); //$NON-NLS-1$ | |
104 | - String path = "icons/alphab_sort_co.gif"; //$NON-NLS-1$ | |
105 | - try { | |
106 | - sortImageDescriptor = ImageDescriptor.createFromURL(new URL(url, path)); | |
107 | - } catch (MalformedURLException e) { | |
108 | - sortImageDescriptor = ImageDescriptor.getMissingImageDescriptor(); | |
109 | - } | |
110 | - } | |
111 | - action.setImageDescriptor(sortImageDescriptor); | |
112 | - toolbar.add(action); | |
113 | - | |
114 | - action.setChecked(PropertiesEditorPlugin.getDefault().getPluginPreferences().getBoolean(ALPHA_SORT_BTN_CHECK_KEY)); | |
115 | - action.run(); | |
116 | - } | |
117 | - | |
118 | - /* (non-Javadoc) | |
119 | - * Method declared on ContentOutlinePage | |
120 | - */ | |
121 | - public void selectionChanged(SelectionChangedEvent event) { | |
122 | - | |
123 | - super.selectionChanged(event); | |
124 | - | |
125 | - ISelection selection= event.getSelection(); | |
126 | - if (selection.isEmpty()) | |
127 | - fTextEditor.resetHighlightRange(); | |
128 | - else { | |
129 | - Segment segment= (Segment) ((IStructuredSelection) selection).getFirstElement(); | |
130 | - int start= segment.position.getOffset(); | |
131 | - int length= segment.position.getLength(); | |
132 | - try { | |
133 | - fTextEditor.setHighlightRange(start, length, true); | |
134 | - } catch (IllegalArgumentException x) { | |
135 | - fTextEditor.resetHighlightRange(); | |
136 | - } | |
137 | - } | |
138 | - } | |
139 | - | |
140 | - /** | |
141 | - * Sets the input of the outline page | |
142 | - */ | |
143 | - public void setInput(Object input) { | |
144 | - fInput= input; | |
145 | - update(); | |
146 | - } | |
147 | - | |
148 | - /** | |
149 | - * Updates the outline page. | |
150 | - */ | |
151 | - protected void update() { | |
152 | - TreeViewer viewer= getTreeViewer(); | |
153 | - if (viewer != null) { | |
154 | - Control control= viewer.getControl(); | |
155 | - if (control != null && !control.isDisposed()) { | |
156 | - control.setRedraw(false); | |
157 | - viewer.setInput(fInput); | |
158 | - viewer.expandAll(); | |
159 | - control.setRedraw(true); | |
160 | - } | |
161 | - } | |
162 | - } | |
163 | - | |
164 | - /** | |
165 | - * Redraw the outline page. | |
166 | - */ | |
167 | - public void redraw() { | |
168 | - TreeViewer viewer= getTreeViewer(); | |
169 | - | |
170 | - if (viewer != null) { | |
171 | - Control control= viewer.getControl(); | |
172 | - if (control != null && !control.isDisposed()) { | |
173 | - control.setRedraw(false); | |
174 | - viewer.expandAll(); | |
175 | - control.setRedraw(true); | |
176 | - } | |
177 | - } | |
178 | - } | |
179 | - | |
180 | - /** | |
181 | - * @see org.eclipse.ui.part.IPage#dispose() | |
182 | - */ | |
183 | - public void dispose() { | |
184 | - super.dispose(); | |
185 | - } | |
186 | -} |
@@ -4,6 +4,7 @@ | ||
4 | 4 | import java.util.Iterator; |
5 | 5 | |
6 | 6 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin; |
7 | +import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.view.outline.PropertiesContentOutlinePage; | |
7 | 8 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.preference.PropertiesEditorPreference; |
8 | 9 | |
9 | 10 | import org.eclipse.core.runtime.CoreException; |
@@ -96,6 +97,8 @@ | ||
96 | 97 | |
97 | 98 | //turn projection mode on |
98 | 99 | viewer.doOperation(ProjectionViewer.TOGGLE); |
100 | + | |
101 | + getSite().setSelectionProvider(viewer); | |
99 | 102 | |
100 | 103 | annotationModel = viewer |
101 | 104 | .getProjectionAnnotationModel(); |
@@ -1,8 +1,5 @@ | ||
1 | 1 | package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors; |
2 | 2 | |
3 | -import java.io.ByteArrayInputStream; | |
4 | -import java.io.IOException; | |
5 | -import java.io.InputStream; | |
6 | 3 | import java.util.ArrayList; |
7 | 4 | import java.util.List; |
8 | 5 |
@@ -13,7 +10,6 @@ | ||
13 | 10 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.resources.Messages; |
14 | 11 | import jp.gr.java_conf.ussiy.app.propedit.util.EncodeChanger; |
15 | 12 | |
16 | -import org.eclipse.core.resources.IFile; | |
17 | 13 | import org.eclipse.core.resources.IProject; |
18 | 14 | import org.eclipse.core.runtime.CoreException; |
19 | 15 | import org.eclipse.core.runtime.IConfigurationElement; |
@@ -30,11 +26,8 @@ | ||
30 | 26 | import org.eclipse.jface.text.IDocument; |
31 | 27 | import org.eclipse.jface.text.IDocumentPartitioner; |
32 | 28 | import org.eclipse.jface.text.rules.FastPartitioner; |
33 | -import org.eclipse.ui.IEditorInput; | |
34 | 29 | import org.eclipse.ui.IFileEditorInput; |
35 | -import org.eclipse.ui.PlatformUI; | |
36 | 30 | import org.eclipse.ui.editors.text.FileDocumentProvider; |
37 | -import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel; | |
38 | 31 | |
39 | 32 | public class PropertiesDocumentProvider extends FileDocumentProvider { |
40 | 33 | private static final String EXTENSION_POINT = "jp.gr.java_conf.ussiy.app.propedit.listeners"; //$NON-NLS-1$ |
@@ -63,19 +56,7 @@ | ||
63 | 56 | |
64 | 57 | protected IDocument createDocument(Object element) throws CoreException { |
65 | 58 | |
66 | - String readEncode = PropertiesEditorPlugin.getDefault().getPreferenceStore().getString(PropertiesPreference.P_ENCODE); | |
67 | - if (readEncode == null || readEncode.equals("")) { //$NON-NLS-1$ | |
68 | - readEncode = getDefaultEncoding(); | |
69 | - } | |
70 | - IDocument document = null; | |
71 | - if (element instanceof IEditorInput) { | |
72 | - document = createEmptyDocument(); | |
73 | - IProject project = ((IFileEditorInput)element).getFile().getProject(); | |
74 | - readEncode = PropertyUtil.getEncode(project, readEncode); | |
75 | - if (!setDocumentContent(document, (IEditorInput) element, readEncode)) { | |
76 | - document = null; | |
77 | - } | |
78 | - } | |
59 | + IDocument document = super.createDocument(element); | |
79 | 60 | |
80 | 61 | List listeners = computePropertiesDocumentListeners(); |
81 | 62 | for (int i = 0; i < listeners.size(); i++) { |
@@ -122,116 +103,63 @@ | ||
122 | 103 | |
123 | 104 | IProject project = input.getFile().getProject(); |
124 | 105 | |
125 | - try { | |
126 | - String encoding = PropertyUtil.getEncode(project, PropertiesEditorPlugin.getDefault().getPreferenceStore().getString(PropertiesPreference.P_ENCODE)); | |
127 | - if (encoding == null || encoding.equals("")) { //$NON-NLS-1$ | |
128 | - encoding = getDefaultEncoding(); | |
106 | + List listeners = computePropertiesDocumentListeners(); | |
107 | + for (int i = 0; i < listeners.size(); i++) { | |
108 | + IPropertiesDocumentListener listener = (IPropertiesDocumentListener)listeners.get(i); | |
109 | + try { | |
110 | + listener.beforeUnicodeConvertAtSavingDocument(monitor, element, document, overwrite); | |
111 | + } catch(Exception e) { | |
112 | + IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e); | |
113 | + ILog log = PropertiesEditorPlugin.getDefault().getLog(); | |
114 | + log.log(status); | |
129 | 115 | } |
130 | - | |
131 | - List listeners = computePropertiesDocumentListeners(); | |
132 | - for (int i = 0; i < listeners.size(); i++) { | |
133 | - IPropertiesDocumentListener listener = (IPropertiesDocumentListener)listeners.get(i); | |
134 | - try { | |
135 | - listener.beforeUnicodeConvertAtSavingDocument(monitor, element, document, overwrite); | |
136 | - } catch(Exception e) { | |
137 | - IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e); | |
138 | - ILog log = PropertiesEditorPlugin.getDefault().getLog(); | |
139 | - log.log(status); | |
116 | + } | |
117 | + | |
118 | + String uniEscStr = null; | |
119 | + String charcase = PropertyUtil.getCharCase(project, PropertiesEditorPlugin.getDefault().getPreferenceStore().getString(PropertiesPreference.P_CONVERT_CHAR_CASE)); | |
120 | + if (PropertyUtil.getNotAllConvert(project, PropertiesEditorPlugin.getDefault().getPreferenceStore().getBoolean(PropertiesPreference.P_NOT_ALL_CONVERT))) { | |
121 | + uniEscStr = document.get(); | |
122 | + } else if (PropertyUtil.getNotConvertComment(project, PropertiesEditorPlugin.getDefault().getPreferenceStore().getBoolean(PropertiesPreference.P_NOT_CONVERT_COMMENT))) { | |
123 | + try { | |
124 | + if (Messages.getString("eclipse.propertieseditor.preference.convert.char.uppercase").equals(charcase)) { //$NON-NLS-1$ | |
125 | + uniEscStr = EncodeChanger.unicode2UnicodeEscWithoutComment(document.get(), EncodeChanger.UPPERCASE); | |
126 | + } else { | |
127 | + uniEscStr = EncodeChanger.unicode2UnicodeEscWithoutComment(document.get(), EncodeChanger.LOWERCASE); | |
140 | 128 | } |
129 | + } catch (Exception e) { | |
130 | + IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e); | |
131 | + ILog log = PropertiesEditorPlugin.getDefault().getLog(); | |
132 | + log.log(status); | |
133 | + ErrorDialog.openError(null, Messages.getString("eclipse.propertieseditor.convert.error"), Messages.getString("eclipse.propertieseditor.property.get.settings.error"), status); //$NON-NLS-1$ //$NON-NLS-2$ | |
141 | 134 | } |
142 | - | |
143 | - String uniEscStr = null; | |
144 | - String charcase = PropertyUtil.getCharCase(project, PropertiesEditorPlugin.getDefault().getPreferenceStore().getString(PropertiesPreference.P_CONVERT_CHAR_CASE)); | |
145 | - if (PropertyUtil.getNotAllConvert(project, PropertiesEditorPlugin.getDefault().getPreferenceStore().getBoolean(PropertiesPreference.P_NOT_ALL_CONVERT))) { | |
146 | - uniEscStr = document.get(); | |
147 | - } else if (PropertyUtil.getNotConvertComment(project, PropertiesEditorPlugin.getDefault().getPreferenceStore().getBoolean(PropertiesPreference.P_NOT_CONVERT_COMMENT))) { | |
148 | - try { | |
149 | - if (Messages.getString("eclipse.propertieseditor.preference.convert.char.uppercase").equals(charcase)) { //$NON-NLS-1$ | |
150 | - uniEscStr = EncodeChanger.unicode2UnicodeEscWithoutComment(document.get(), EncodeChanger.UPPERCASE); | |
151 | - } else { | |
152 | - uniEscStr = EncodeChanger.unicode2UnicodeEscWithoutComment(document.get(), EncodeChanger.LOWERCASE); | |
153 | - } | |
154 | - } catch (Exception e) { | |
155 | - IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e); | |
156 | - ILog log = PropertiesEditorPlugin.getDefault().getLog(); | |
157 | - log.log(status); | |
158 | - ErrorDialog.openError(null, Messages.getString("eclipse.propertieseditor.convert.error"), Messages.getString("eclipse.propertieseditor.property.get.settings.error"), status); //$NON-NLS-1$ //$NON-NLS-2$ | |
135 | + } else { | |
136 | + try { | |
137 | + if (Messages.getString("eclipse.propertieseditor.preference.convert.char.uppercase").equals(charcase)) { //$NON-NLS-1$ | |
138 | + uniEscStr = EncodeChanger.unicode2UnicodeEsc(document.get(), EncodeChanger.UPPERCASE); | |
139 | + } else { | |
140 | + uniEscStr = EncodeChanger.unicode2UnicodeEsc(document.get(), EncodeChanger.LOWERCASE); | |
159 | 141 | } |
160 | - } else { | |
161 | - try { | |
162 | - if (Messages.getString("eclipse.propertieseditor.preference.convert.char.uppercase").equals(charcase)) { //$NON-NLS-1$ | |
163 | - uniEscStr = EncodeChanger.unicode2UnicodeEsc(document.get(), EncodeChanger.UPPERCASE); | |
164 | - } else { | |
165 | - uniEscStr = EncodeChanger.unicode2UnicodeEsc(document.get(), EncodeChanger.LOWERCASE); | |
166 | - } | |
167 | - } catch (Exception e) { | |
168 | - IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e); | |
169 | - ILog log = PropertiesEditorPlugin.getDefault().getLog(); | |
170 | - log.log(status); | |
171 | - ErrorDialog.openError(null, Messages.getString("eclipse.propertieseditor.convert.error"), Messages.getString("eclipse.propertieseditor.property.get.settings.error"), status); //$NON-NLS-1$ //$NON-NLS-2$ | |
172 | - } | |
142 | + } catch (Exception e) { | |
143 | + IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e); | |
144 | + ILog log = PropertiesEditorPlugin.getDefault().getLog(); | |
145 | + log.log(status); | |
146 | + ErrorDialog.openError(null, Messages.getString("eclipse.propertieseditor.convert.error"), Messages.getString("eclipse.propertieseditor.property.get.settings.error"), status); //$NON-NLS-1$ //$NON-NLS-2$ | |
173 | 147 | } |
174 | - document = new Document(uniEscStr); | |
175 | - | |
176 | - for (int i = 0; i < listeners.size(); i++) { | |
177 | - IPropertiesDocumentListener listener = (IPropertiesDocumentListener)listeners.get(i); | |
178 | - try { | |
179 | - listener.afterUnicodeConvertAtSavingDocument(monitor, element, document, overwrite); | |
180 | - } catch(Exception e) { | |
181 | - IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e); | |
182 | - ILog log = PropertiesEditorPlugin.getDefault().getLog(); | |
183 | - log.log(status); | |
184 | - } | |
148 | + } | |
149 | + document = new Document(uniEscStr); | |
150 | + | |
151 | + for (int i = 0; i < listeners.size(); i++) { | |
152 | + IPropertiesDocumentListener listener = (IPropertiesDocumentListener)listeners.get(i); | |
153 | + try { | |
154 | + listener.afterUnicodeConvertAtSavingDocument(monitor, element, document, overwrite); | |
155 | + } catch(Exception e) { | |
156 | + IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e); | |
157 | + ILog log = PropertiesEditorPlugin.getDefault().getLog(); | |
158 | + log.log(status); | |
185 | 159 | } |
186 | - | |
187 | - InputStream stream = new ByteArrayInputStream(uniEscStr.toString().getBytes(encoding)); | |
188 | - IFile file = input.getFile(); | |
189 | - | |
190 | - if (file.exists()) { | |
191 | - | |
192 | - FileInfo info = (FileInfo) getElementInfo(element); | |
193 | - | |
194 | - if (info != null && !overwrite) { | |
195 | - checkSynchronizationState(info.fModificationStamp, file); | |
196 | - | |
197 | - // inform about the upcoming content change | |
198 | - } | |
199 | - fireElementStateChanging(element); | |
200 | - try { | |
201 | - file.setContents(stream, overwrite, true, monitor); | |
202 | - } catch (CoreException x) { | |
203 | - // inform about failure | |
204 | - fireElementStateChangeFailed(element); | |
205 | - throw x; | |
206 | - } catch (RuntimeException x) { | |
207 | - // inform about failure | |
208 | - fireElementStateChangeFailed(element); | |
209 | - throw x; | |
210 | - } | |
211 | - | |
212 | - // If here, the editor state will be flipped to "not dirty". | |
213 | - // Thus, the state changing flag will be reset. | |
214 | - | |
215 | - if (info != null) { | |
216 | - | |
217 | - ResourceMarkerAnnotationModel model = (ResourceMarkerAnnotationModel) info.fModel; | |
218 | - model.updateMarkers(info.fDocument); | |
219 | - | |
220 | - info.fModificationStamp = computeModificationStamp(file); | |
221 | - } | |
222 | - | |
223 | - } else { | |
224 | - super.doSaveDocument(monitor, element, document, overwrite); | |
225 | - return; | |
226 | - } | |
227 | - | |
228 | - } catch (IOException x) { | |
229 | - IStatus s = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, x.getMessage(), x); | |
230 | - throw new CoreException(s); | |
231 | 160 | } |
232 | 161 | |
233 | - } else { | |
234 | - super.doSaveDocument(monitor, element, document, overwrite); | |
235 | 162 | } |
163 | + super.doSaveDocument(monitor, element, document, overwrite); | |
236 | 164 | } |
237 | 165 | } |
\ No newline at end of file |
@@ -0,0 +1,238 @@ | ||
1 | +package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.view.outline; | |
2 | + | |
3 | +import java.io.BufferedReader; | |
4 | +import java.io.IOException; | |
5 | +import java.io.StringReader; | |
6 | +import java.util.ArrayList; | |
7 | +import java.util.List; | |
8 | + | |
9 | +import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.view.outline.PropertiesContentOutlinePage.Segment; | |
10 | + | |
11 | +import org.eclipse.jface.text.BadPositionCategoryException; | |
12 | +import org.eclipse.jface.text.DefaultPositionUpdater; | |
13 | +import org.eclipse.jface.text.DocumentEvent; | |
14 | +import org.eclipse.jface.text.IDocument; | |
15 | +import org.eclipse.jface.text.IDocumentListener; | |
16 | +import org.eclipse.jface.text.IPositionUpdater; | |
17 | +import org.eclipse.jface.text.Position; | |
18 | +import org.eclipse.jface.viewers.ITreeContentProvider; | |
19 | +import org.eclipse.jface.viewers.Viewer; | |
20 | + | |
21 | +/** | |
22 | + * Divides the editor's document into ten segments and provides elements for | |
23 | + * them. | |
24 | + */ | |
25 | +class PropertiesOutlineContentProvider implements ITreeContentProvider, IDocumentListener { | |
26 | + | |
27 | + private final PropertiesContentOutlinePage fContentOutlinePage; | |
28 | + | |
29 | + /** | |
30 | + * @param page | |
31 | + */ | |
32 | + PropertiesOutlineContentProvider(PropertiesContentOutlinePage page) { | |
33 | + this.fContentOutlinePage = page; | |
34 | + } | |
35 | + | |
36 | + protected final static String SEGMENTS = "__properties_segments"; //$NON-NLS-1$ | |
37 | + | |
38 | + protected IPositionUpdater fPositionUpdater = new DefaultPositionUpdater( | |
39 | + SEGMENTS); | |
40 | + | |
41 | + protected List fContent = new ArrayList(10); | |
42 | + | |
43 | + protected void parse(IDocument document) { | |
44 | + String line = null; | |
45 | + int cntLine = 0; | |
46 | + boolean multipleValueFlg = false; | |
47 | + | |
48 | + BufferedReader reader = null; | |
49 | + try { | |
50 | + reader = new BufferedReader(new StringReader(document.get())); | |
51 | + while ((line = reader.readLine()) != null) { | |
52 | + cntLine++; | |
53 | + if (multipleValueFlg) { | |
54 | + if (line.endsWith("\\")) { //$NON-NLS-1$ | |
55 | + multipleValueFlg = true; | |
56 | + } else { | |
57 | + multipleValueFlg = false; | |
58 | + } | |
59 | + continue; | |
60 | + } else { | |
61 | + if (line.trim().equals("") || line.trim().startsWith("#") || line.trim().startsWith("!")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
62 | + continue; | |
63 | + } | |
64 | + } | |
65 | + line = line.trim(); | |
66 | + boolean escapeFlg = false; | |
67 | + boolean nonSeparate = true; | |
68 | + for (int i = 0; i < line.length(); i++) { | |
69 | + char achar = line.charAt(i); | |
70 | + if (achar == '\\') { | |
71 | + if (escapeFlg) { | |
72 | + String tmp = line; | |
73 | + line = ""; //$NON-NLS-1$ | |
74 | + line = tmp.substring(0, i); | |
75 | + line += tmp.substring(i + 1, tmp.length()); | |
76 | + escapeFlg = false; | |
77 | + i--; | |
78 | + } else { | |
79 | + escapeFlg = true; | |
80 | + } | |
81 | + } else if (achar == '=' || achar == '\t' || achar == ':' || achar == ' ') { | |
82 | + if (escapeFlg) { | |
83 | + String tmp = line; | |
84 | + line = ""; //$NON-NLS-1$ | |
85 | + line = tmp.substring(0, i - 1); | |
86 | + line += tmp.substring(i, tmp.length()); | |
87 | + escapeFlg = false; | |
88 | + i--; | |
89 | + continue; | |
90 | + } else { | |
91 | + int offset = document.getLineOffset(cntLine - 1); | |
92 | + Position p = new Position(offset, i); | |
93 | + document.addPosition(SEGMENTS, p); | |
94 | + | |
95 | + fContent.add(new Segment(line.substring(0, i).trim(), p)); //$NON-NLS-1$ | |
96 | + | |
97 | + nonSeparate = false; | |
98 | + escapeFlg = false; | |
99 | + break; | |
100 | + } | |
101 | + } else { | |
102 | + if (escapeFlg) { | |
103 | + String tmp = line; | |
104 | + line = ""; //$NON-NLS-1$ | |
105 | + line = tmp.substring(0, i - 1); | |
106 | + line += tmp.substring(i, tmp.length()); | |
107 | + i--; | |
108 | + } | |
109 | + escapeFlg = false; | |
110 | + } | |
111 | + } | |
112 | + if (nonSeparate) { | |
113 | + if (line.endsWith("\\")) { //$NON-NLS-1$ | |
114 | + continue; | |
115 | + } | |
116 | + } | |
117 | + if (line.endsWith("\\")) { //$NON-NLS-1$ | |
118 | + multipleValueFlg = true; | |
119 | + } else { | |
120 | + multipleValueFlg = false; | |
121 | + } | |
122 | + } | |
123 | + | |
124 | + } catch (Exception e) { | |
125 | + e.printStackTrace(); | |
126 | + } finally { | |
127 | + try { | |
128 | + if (reader != null) { | |
129 | + reader.close(); | |
130 | + } | |
131 | + } catch (IOException e) { | |
132 | + } | |
133 | + } | |
134 | + | |
135 | + } | |
136 | + | |
137 | + /* | |
138 | + * @see IContentProvider#inputChanged(Viewer, Object, Object) | |
139 | + */ | |
140 | + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | |
141 | + if (oldInput != null) { | |
142 | + IDocument document = this.fContentOutlinePage.fDocumentProvider | |
143 | + .getDocument(oldInput); | |
144 | + if (document != null) { | |
145 | + try { | |
146 | + document.removePositionCategory(SEGMENTS); | |
147 | + } catch (BadPositionCategoryException x) { | |
148 | + } | |
149 | + document.removePositionUpdater(fPositionUpdater); | |
150 | + } | |
151 | + } | |
152 | + | |
153 | + fContent.clear(); | |
154 | + | |
155 | + if (newInput != null) { | |
156 | + IDocument document = this.fContentOutlinePage.fDocumentProvider | |
157 | + .getDocument(newInput); | |
158 | + if (document != null) { | |
159 | + document.addPositionCategory(SEGMENTS); | |
160 | + document.addPositionUpdater(fPositionUpdater); | |
161 | + | |
162 | + parse(document); | |
163 | + } | |
164 | + } | |
165 | + } | |
166 | + | |
167 | + /* | |
168 | + * @see IContentProvider#dispose | |
169 | + */ | |
170 | + public void dispose() { | |
171 | + if (fContent != null) { | |
172 | + fContent.clear(); | |
173 | + fContent = null; | |
174 | + } | |
175 | + } | |
176 | + | |
177 | + /* | |
178 | + * @see IContentProvider#isDeleted(Object) | |
179 | + */ | |
180 | + public boolean isDeleted(Object element) { | |
181 | + return false; | |
182 | + } | |
183 | + | |
184 | + /* | |
185 | + * @see IStructuredContentProvider#getElements(Object) | |
186 | + */ | |
187 | + public Object[] getElements(Object element) { | |
188 | + return fContent.toArray(); | |
189 | + } | |
190 | + | |
191 | + /* | |
192 | + * @see ITreeContentProvider#hasChildren(Object) | |
193 | + */ | |
194 | + public boolean hasChildren(Object element) { | |
195 | + return element == this.fContentOutlinePage.fInput; | |
196 | + } | |
197 | + | |
198 | + /* | |
199 | + * @see ITreeContentProvider#getParent(Object) | |
200 | + */ | |
201 | + public Object getParent(Object element) { | |
202 | + if (element instanceof Segment) | |
203 | + return this.fContentOutlinePage.fInput; | |
204 | + return null; | |
205 | + } | |
206 | + | |
207 | + /* | |
208 | + * @see ITreeContentProvider#getChildren(Object) | |
209 | + */ | |
210 | + public Object[] getChildren(Object element) { | |
211 | + if (element == this.fContentOutlinePage.fInput) | |
212 | + return fContent.toArray(); | |
213 | + return new Object[0]; | |
214 | + } | |
215 | + | |
216 | + /** | |
217 | + * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent) | |
218 | + */ | |
219 | + public void documentAboutToBeChanged(DocumentEvent event) { | |
220 | + } | |
221 | + | |
222 | + /** | |
223 | + * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent) | |
224 | + */ | |
225 | + public void documentChanged(DocumentEvent event) { | |
226 | +// try { | |
227 | +// event.getDocument().removePositionCategory(SEGMENTS); | |
228 | +// } catch (BadPositionCategoryException x) { | |
229 | +// } | |
230 | +// event.getDocument().removePositionUpdater(fPositionUpdater); | |
231 | +// fContent.clear(); | |
232 | +// event.getDocument().addPositionCategory(SEGMENTS); | |
233 | +// event.getDocument().addPositionUpdater(fPositionUpdater); | |
234 | +// parse(event.getDocument()); | |
235 | +// fContentOutlinePage.update(); | |
236 | + } | |
237 | + | |
238 | +} | |
\ No newline at end of file |
@@ -0,0 +1,186 @@ | ||
1 | +package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.view.outline; | |
2 | + | |
3 | +import java.net.MalformedURLException; | |
4 | +import java.net.URL; | |
5 | + | |
6 | +import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin; | |
7 | +import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.resources.Messages; | |
8 | + | |
9 | +import org.eclipse.jface.action.Action; | |
10 | +import org.eclipse.jface.action.IToolBarManager; | |
11 | +import org.eclipse.jface.resource.ImageDescriptor; | |
12 | +import org.eclipse.jface.text.Position; | |
13 | +import org.eclipse.jface.viewers.ISelection; | |
14 | +import org.eclipse.jface.viewers.IStructuredSelection; | |
15 | +import org.eclipse.jface.viewers.SelectionChangedEvent; | |
16 | +import org.eclipse.jface.viewers.TreeViewer; | |
17 | +import org.eclipse.jface.viewers.ViewerSorter; | |
18 | +import org.eclipse.swt.widgets.Composite; | |
19 | +import org.eclipse.swt.widgets.Control; | |
20 | +import org.eclipse.ui.texteditor.IDocumentProvider; | |
21 | +import org.eclipse.ui.texteditor.ITextEditor; | |
22 | +import org.eclipse.ui.views.contentoutline.ContentOutlinePage; | |
23 | + | |
24 | +public class PropertiesContentOutlinePage extends ContentOutlinePage { | |
25 | + protected static String ALPHA_SORT_BTN_CHECK_KEY = "jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.alphaSortCheckKey"; //$NON-NLS-1$ | |
26 | + | |
27 | + /** | |
28 | + * A segment element. | |
29 | + */ | |
30 | + protected static class Segment { | |
31 | + public String name; | |
32 | + public Position position; | |
33 | + | |
34 | + public Segment(String name, Position position) { | |
35 | + this.name= name; | |
36 | + this.position= position; | |
37 | + } | |
38 | + | |
39 | + public String toString() { | |
40 | + return name; | |
41 | + } | |
42 | + } | |
43 | + | |
44 | + protected Object fInput; | |
45 | + protected IDocumentProvider fDocumentProvider; | |
46 | + protected ITextEditor fTextEditor; | |
47 | + protected PropertiesOutlineContentProvider contentProvider; | |
48 | + | |
49 | + protected static ImageDescriptor sortImageDescriptor; | |
50 | + | |
51 | + /** | |
52 | + * Creates a content outline page using the given provider and the given editor. | |
53 | + */ | |
54 | + public PropertiesContentOutlinePage(IDocumentProvider provider, ITextEditor editor) { | |
55 | + super(); | |
56 | + fDocumentProvider= provider; | |
57 | + fTextEditor= editor; | |
58 | + fDocumentProvider.getDocument(fTextEditor.getEditorInput()).addDocumentListener(getContentProvider()); | |
59 | + } | |
60 | + | |
61 | + protected PropertiesOutlineContentProvider getContentProvider() { | |
62 | + if (contentProvider == null) { | |
63 | + contentProvider = new PropertiesOutlineContentProvider(this); | |
64 | + } | |
65 | + return contentProvider; | |
66 | + } | |
67 | + | |
68 | + /** | |
69 | + * Method declared on ContentOutlinePage | |
70 | + */ | |
71 | + public void createControl(Composite parent) { | |
72 | + | |
73 | + super.createControl(parent); | |
74 | + | |
75 | + // create tree viewer | |
76 | + TreeViewer viewer= getTreeViewer(); | |
77 | + viewer.setContentProvider(getContentProvider()); | |
78 | + viewer.setLabelProvider(new PropertiesOutlineLabelProvider()); | |
79 | + viewer.addSelectionChangedListener(this); | |
80 | + | |
81 | + if (fInput != null) | |
82 | + viewer.setInput(fInput); | |
83 | + | |
84 | + // create toolbar action | |
85 | + PropertiesEditorPlugin.getDefault().getPluginPreferences().setDefault(ALPHA_SORT_BTN_CHECK_KEY, false); | |
86 | + IToolBarManager toolbar = getSite().getActionBars().getToolBarManager(); | |
87 | + String label = Messages.getString("eclipse.contentoutline.sort.label"); //$NON-NLS-1$ | |
88 | + Action action = new Action(label, Action.AS_CHECK_BOX) { | |
89 | + public void run() { | |
90 | + PropertiesEditorPlugin.getDefault().getPluginPreferences().setValue(ALPHA_SORT_BTN_CHECK_KEY, isChecked()); | |
91 | + if (isChecked()) { | |
92 | + TreeViewer v = getTreeViewer(); | |
93 | + v.setSorter(new ViewerSorter()); | |
94 | + v.setInput(v.getInput()); | |
95 | + } else { | |
96 | + getTreeViewer().setSorter(null); | |
97 | + redraw(); | |
98 | + } | |
99 | + } | |
100 | + }; | |
101 | + action.setToolTipText(action.getText()); | |
102 | + if (sortImageDescriptor == null) { | |
103 | + URL url = PropertiesEditorPlugin.getDefault().getBundle().getEntry("/"); //$NON-NLS-1$ | |
104 | + String path = "icons/alphab_sort_co.gif"; //$NON-NLS-1$ | |
105 | + try { | |
106 | + sortImageDescriptor = ImageDescriptor.createFromURL(new URL(url, path)); | |
107 | + } catch (MalformedURLException e) { | |
108 | + sortImageDescriptor = ImageDescriptor.getMissingImageDescriptor(); | |
109 | + } | |
110 | + } | |
111 | + action.setImageDescriptor(sortImageDescriptor); | |
112 | + toolbar.add(action); | |
113 | + | |
114 | + action.setChecked(PropertiesEditorPlugin.getDefault().getPluginPreferences().getBoolean(ALPHA_SORT_BTN_CHECK_KEY)); | |
115 | + action.run(); | |
116 | + } | |
117 | + | |
118 | + /* (non-Javadoc) | |
119 | + * Method declared on ContentOutlinePage | |
120 | + */ | |
121 | + public void selectionChanged(SelectionChangedEvent event) { | |
122 | + | |
123 | + super.selectionChanged(event); | |
124 | + | |
125 | + ISelection selection= event.getSelection(); | |
126 | + if (selection.isEmpty()) | |
127 | + fTextEditor.resetHighlightRange(); | |
128 | + else { | |
129 | + Segment segment= (Segment) ((IStructuredSelection) selection).getFirstElement(); | |
130 | + int start= segment.position.getOffset(); | |
131 | + int length= segment.position.getLength(); | |
132 | + try { | |
133 | + fTextEditor.setHighlightRange(start, length, true); | |
134 | + } catch (IllegalArgumentException x) { | |
135 | + fTextEditor.resetHighlightRange(); | |
136 | + } | |
137 | + } | |
138 | + } | |
139 | + | |
140 | + /** | |
141 | + * Sets the input of the outline page | |
142 | + */ | |
143 | + public void setInput(Object input) { | |
144 | + fInput= input; | |
145 | + update(); | |
146 | + } | |
147 | + | |
148 | + /** | |
149 | + * Updates the outline page. | |
150 | + */ | |
151 | + public void update() { | |
152 | + TreeViewer viewer= getTreeViewer(); | |
153 | + if (viewer != null) { | |
154 | + Control control= viewer.getControl(); | |
155 | + if (control != null && !control.isDisposed()) { | |
156 | + control.setRedraw(false); | |
157 | + viewer.setInput(fInput); | |
158 | + viewer.expandAll(); | |
159 | + control.setRedraw(true); | |
160 | + } | |
161 | + } | |
162 | + } | |
163 | + | |
164 | + /** | |
165 | + * Redraw the outline page. | |
166 | + */ | |
167 | + public void redraw() { | |
168 | + TreeViewer viewer= getTreeViewer(); | |
169 | + | |
170 | + if (viewer != null) { | |
171 | + Control control= viewer.getControl(); | |
172 | + if (control != null && !control.isDisposed()) { | |
173 | + control.setRedraw(false); | |
174 | + viewer.expandAll(); | |
175 | + control.setRedraw(true); | |
176 | + } | |
177 | + } | |
178 | + } | |
179 | + | |
180 | + /** | |
181 | + * @see org.eclipse.ui.part.IPage#dispose() | |
182 | + */ | |
183 | + public void dispose() { | |
184 | + super.dispose(); | |
185 | + } | |
186 | +} |
@@ -0,0 +1,43 @@ | ||
1 | +package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.view.outline; | |
2 | + | |
3 | +import java.net.MalformedURLException; | |
4 | +import java.net.URL; | |
5 | + | |
6 | +import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin; | |
7 | + | |
8 | +import org.eclipse.jface.resource.ImageDescriptor; | |
9 | +import org.eclipse.jface.viewers.LabelProvider; | |
10 | +import org.eclipse.swt.graphics.Image; | |
11 | + | |
12 | +public class PropertiesOutlineLabelProvider extends LabelProvider { | |
13 | + protected static Image markerImage; | |
14 | + | |
15 | + /** | |
16 | + * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) | |
17 | + */ | |
18 | + public Image getImage(Object element) { | |
19 | + if (markerImage != null && !markerImage.isDisposed()) { | |
20 | + return markerImage; | |
21 | + } | |
22 | + URL url = PropertiesEditorPlugin.getDefault().getBundle().getEntry("/"); //$NON-NLS-1$ | |
23 | + String path = "icons/outlineMarker.gif"; //$NON-NLS-1$ | |
24 | + ImageDescriptor descriptor = null; | |
25 | + try { | |
26 | + descriptor = ImageDescriptor.createFromURL(new URL(url, path)); | |
27 | + } catch (MalformedURLException e) { | |
28 | + descriptor = ImageDescriptor.getMissingImageDescriptor(); | |
29 | + } | |
30 | + markerImage = descriptor.createImage(); | |
31 | + return markerImage; | |
32 | + } | |
33 | + | |
34 | + /** | |
35 | + * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() | |
36 | + */ | |
37 | + public void dispose() { | |
38 | + super.dispose(); | |
39 | + if (markerImage != null) { | |
40 | + markerImage.dispose(); | |
41 | + } | |
42 | + } | |
43 | +} |
@@ -1,7 +1,6 @@ | ||
1 | 1 | package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.action; |
2 | 2 | |
3 | 3 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin; |
4 | -import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.MultiPagePropertiesEditor; | |
5 | 4 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.PropertiesEditor; |
6 | 5 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.preference.PropertiesPreference; |
7 | 6 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.property.PropertyUtil; |
@@ -26,9 +25,7 @@ | ||
26 | 25 | * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart) |
27 | 26 | */ |
28 | 27 | public void setActiveEditor(IAction action, IEditorPart targetEditor) { |
29 | - if (targetEditor instanceof MultiPagePropertiesEditor) { | |
30 | - textEditor = ((MultiPagePropertiesEditor)targetEditor).getEditor(); | |
31 | - } else if (targetEditor instanceof PropertiesEditor) { | |
28 | + if (targetEditor instanceof PropertiesEditor) { | |
32 | 29 | textEditor = (PropertiesEditor)targetEditor; |
33 | 30 | } |
34 | 31 |
@@ -2,7 +2,6 @@ | ||
2 | 2 | |
3 | 3 | import java.util.Iterator; |
4 | 4 | |
5 | -import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.MultiPagePropertiesEditor; | |
6 | 5 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.PropertiesEditor; |
7 | 6 | |
8 | 7 | import org.eclipse.jface.action.IAction; |
@@ -19,9 +18,7 @@ | ||
19 | 18 | * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart) |
20 | 19 | */ |
21 | 20 | public void setActiveEditor(IAction action, IEditorPart targetEditor) { |
22 | - if (targetEditor instanceof MultiPagePropertiesEditor) { | |
23 | - textEditor = ((MultiPagePropertiesEditor)targetEditor).getEditor(); | |
24 | - } else if (targetEditor instanceof PropertiesEditor) { | |
21 | + if (targetEditor instanceof PropertiesEditor) { | |
25 | 22 | textEditor = (PropertiesEditor)targetEditor; |
26 | 23 | } |
27 | 24 | } |
@@ -2,7 +2,6 @@ | ||
2 | 2 | |
3 | 3 | import java.util.Iterator; |
4 | 4 | |
5 | -import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.MultiPagePropertiesEditor; | |
6 | 5 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.PropertiesEditor; |
7 | 6 | |
8 | 7 | import org.eclipse.jface.action.IAction; |
@@ -19,9 +18,7 @@ | ||
19 | 18 | * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart) |
20 | 19 | */ |
21 | 20 | public void setActiveEditor(IAction action, IEditorPart targetEditor) { |
22 | - if (targetEditor instanceof MultiPagePropertiesEditor) { | |
23 | - textEditor = ((MultiPagePropertiesEditor)targetEditor).getEditor(); | |
24 | - } else if (targetEditor instanceof PropertiesEditor) { | |
21 | + if (targetEditor instanceof PropertiesEditor) { | |
25 | 22 | textEditor = (PropertiesEditor)targetEditor; |
26 | 23 | } |
27 | 24 | } |
@@ -3,7 +3,6 @@ | ||
3 | 3 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin; |
4 | 4 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.resources.Messages; |
5 | 5 | |
6 | -import org.eclipse.core.resources.ResourcesPlugin; | |
7 | 6 | import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; |
8 | 7 | import org.eclipse.jface.preference.IPreferenceStore; |
9 | 8 |
@@ -16,7 +15,6 @@ | ||
16 | 15 | |
17 | 16 | IPreferenceStore pStore = PropertiesEditorPlugin.getDefault().getPreferenceStore(); |
18 | 17 | pStore.setDefault(PropertiesEditorDuplicationCheckerPreference.P_CHECK_KEY, false); |
19 | - pStore.setDefault(PropertiesPreference.P_ENCODE, ResourcesPlugin.getEncoding()); | |
20 | 18 | pStore.setDefault(PropertiesPreference.P_COMMENT_CHARACTER, "#"); //$NON-NLS-1$ |
21 | 19 | pStore.setDefault(PropertiesPreference.P_CONVERT_CHAR_CASE, Messages.getString("eclipse.propertieseditor.preference.convert.char.lowercase")); //$NON-NLS-1$ |
22 | 20 | pStore.setDefault(PropertiesEditorPreference.P_COLLAPSE, false); |
@@ -2,7 +2,6 @@ | ||
2 | 2 | |
3 | 3 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin; |
4 | 4 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.ColorManager; |
5 | -import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.MultiPagePropertiesEditor; | |
6 | 5 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.resources.Messages; |
7 | 6 | |
8 | 7 | import org.eclipse.jface.preference.BooleanFieldEditor; |
@@ -130,14 +129,9 @@ | ||
130 | 129 | for (int k = 0; k < editorReferences.length; k++) { |
131 | 130 | IEditorReference ref = editorReferences[k]; |
132 | 131 | IEditorPart editorPart = ref.getEditor(false); |
133 | - if (editorPart instanceof MultiPagePropertiesEditor) { | |
132 | + if (editorPart instanceof jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.PropertiesEditor) { | |
134 | 133 | RGB rgb = PreferenceConverter.getColor(pStore, PropertiesEditorPreference.P_BACKGROUND_COLOR); |
135 | 134 | Color color = new ColorManager().getColor(rgb); |
136 | - jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.PropertiesEditor editor = ((MultiPagePropertiesEditor) editorPart).getEditor(); | |
137 | - editor.setBackground(color); | |
138 | - } else if (editorPart instanceof jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.PropertiesEditor) { | |
139 | - RGB rgb = PreferenceConverter.getColor(pStore, PropertiesEditorPreference.P_BACKGROUND_COLOR); | |
140 | - Color color = new ColorManager().getColor(rgb); | |
141 | 135 | jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.PropertiesEditor editor = |
142 | 136 | (jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.PropertiesEditor)editorPart; |
143 | 137 | editor.setBackground(color); |
@@ -1,7 +1,6 @@ | ||
1 | 1 | package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.preference; |
2 | 2 | |
3 | 3 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin; |
4 | -import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.ComboFieldEditor; | |
5 | 4 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.resources.Messages; |
6 | 5 | |
7 | 6 | import org.eclipse.jface.preference.BooleanFieldEditor; |
@@ -18,8 +17,6 @@ | ||
18 | 17 | |
19 | 18 | public class PropertiesPreference extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { |
20 | 19 | |
21 | - public static final String P_ENCODE = "readEncode"; //$NON-NLS-1$ | |
22 | - | |
23 | 20 | public static final String P_NOT_CONVERT_COMMENT = "notConvertComment"; //$NON-NLS-1$ |
24 | 21 | |
25 | 22 | public static final String P_NOT_ALL_CONVERT = "notConvert"; //$NON-NLS-1$ |
@@ -28,8 +25,6 @@ | ||
28 | 25 | |
29 | 26 | public static final String P_CONVERT_CHAR_CASE = "convertCharCase"; //$NON-NLS-1$ |
30 | 27 | |
31 | - private ComboFieldEditor encodeComboFieldEditor; | |
32 | - | |
33 | 28 | private BooleanFieldEditor notAllConvertEditor; |
34 | 29 | |
35 | 30 | private BooleanFieldEditor notConvertCommentField; |
@@ -37,8 +32,6 @@ | ||
37 | 32 | private StringFieldEditor commentCharacterField; |
38 | 33 | |
39 | 34 | private RadioGroupFieldEditor convertCharCaseField; |
40 | - | |
41 | - private String[] items = new String[] { System.getProperty("file.encoding"), "US-ASCII", "UTF-8", "UTF-16" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ | |
42 | 35 | |
43 | 36 | private String[][] charCaseItems = new String[][] { { Messages.getString("eclipse.propertieseditor.preference.convert.char.uppercase"), Messages.getString("eclipse.propertieseditor.preference.convert.char.uppercase") }, { Messages.getString("eclipse.propertieseditor.preference.convert.char.lowercase"), Messages.getString("eclipse.propertieseditor.preference.convert.char.lowercase") } }; //$NON-NLS-1$ //$NON-NLS-2$ |
44 | 37 |
@@ -53,7 +46,6 @@ | ||
53 | 46 | |
54 | 47 | Composite parent = getFieldEditorParent(); |
55 | 48 | |
56 | - encodeComboFieldEditor = new ComboFieldEditor(P_ENCODE, Messages.getString("eclipse.propertieseditor.preference.read.encode"), items, parent); //$NON-NLS-1$ | |
57 | 49 | commentCharacterField = new StringFieldEditor(P_COMMENT_CHARACTER, Messages.getString("eclipse.propertieseditor.preference.comment.character"), 1, parent); //$NON-NLS-1$ |
58 | 50 | commentCharacterField.setTextLimit(1); |
59 | 51 | convertCharCaseField = new RadioGroupFieldEditor(P_CONVERT_CHAR_CASE, Messages.getString("eclipse.propertieseditor.preference.convert.char.case"), 2, charCaseItems, parent, true); //$NON-NLS-1$ |
@@ -79,7 +71,6 @@ | ||
79 | 71 | notConvertCommentField.setEnabled(!PropertiesEditorPlugin.getDefault().getPreferenceStore().getBoolean(PropertiesPreference.P_NOT_ALL_CONVERT), convGroup); |
80 | 72 | |
81 | 73 | addField(commentCharacterField); |
82 | - addField(encodeComboFieldEditor); | |
83 | 74 | addField(convertCharCaseField); |
84 | 75 | addField(notAllConvertEditor); |
85 | 76 | addField(notConvertCommentField); |
@@ -214,6 +214,7 @@ | ||
214 | 214 | name="Properties File" |
215 | 215 | base-type="org.eclipse.core.runtime.text" |
216 | 216 | file-extensions="properties" |
217 | + priority="high" | |
217 | 218 | default-charset=""/> |
218 | 219 | </extension> |
219 | 220 |