• R/O
  • SSH
  • HTTPS

propedit: 提交


Commit MetaInfo

修订版182 (tree)
时间2009-05-17 23:42:33
作者chomakichi

Log Message

Javaエディタにホバー表示を追加

更改概述

差异

--- trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/wizard/BasicNewPropertiesFileWizard.java (nonexistent)
+++ trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/wizard/BasicNewPropertiesFileWizard.java (revision 182)
@@ -0,0 +1,27 @@
1+/**
2+ *
3+ */
4+package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.wizard;
5+
6+import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.resources.Messages;
7+
8+import org.eclipse.jface.wizard.IWizardPage;
9+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
10+import org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard;
11+
12+/**
13+ *
14+ */
15+public class BasicNewPropertiesFileWizard extends BasicNewFileResourceWizard {
16+
17+ /**
18+ * @see org.eclipse.jface.wizard.Wizard#addPage(org.eclipse.jface.wizard.IWizardPage)
19+ */
20+ public void addPage(IWizardPage page) {
21+ page.setTitle(Messages.getString("eclipse.propertieseditor.BasicNewPropertiesFileWizard.0")); //$NON-NLS-1$
22+ page.setDescription(Messages.getString("eclipse.propertieseditor.BasicNewPropertiesFileWizard.1")); //$NON-NLS-1$
23+ ((WizardNewFileCreationPage)page).setFileExtension("properties"); //$NON-NLS-1$
24+ super.addPage(page);
25+ }
26+
27+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/jdt/proposal/PropertiesCompletionProposalComputer.java (revision 181)
+++ trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/jdt/proposal/PropertiesCompletionProposalComputer.java (revision 182)
@@ -9,11 +9,11 @@
99 import java.util.Properties;
1010
1111 import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin;
12+import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.resources.Messages;
13+import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.util.PropertiesFileUtil;
1214
13-import org.eclipse.core.resources.IContainer;
1415 import org.eclipse.core.resources.IFile;
1516 import org.eclipse.core.resources.IProject;
16-import org.eclipse.core.resources.IResource;
1717 import org.eclipse.core.runtime.CoreException;
1818 import org.eclipse.core.runtime.ILog;
1919 import org.eclipse.core.runtime.IPath;
@@ -65,8 +65,8 @@
6565
6666 public void run(IProgressMonitor monitor)
6767 throws InvocationTargetException, InterruptedException {
68- monitor.setTaskName("searching property");
69- files = findFileExt(project, excludePath, "properties");
68+ monitor.setTaskName(Messages.getString("eclipse.propertieseditor.PropertiesCompletionProposalComputer.0")); //$NON-NLS-1$
69+ files = PropertiesFileUtil.findFileExt(project, excludePath, "properties"); //$NON-NLS-1$
7070 monitor.done();
7171 }
7272
@@ -116,7 +116,7 @@
116116
117117 String source = context.getDocument().get();
118118 int offset = context.getInvocationOffset();
119- int idx = source.charAt(offset) == '\"' ? source.lastIndexOf("\"", offset - 1) : source.lastIndexOf("\"", offset);
119+ int idx = source.charAt(offset) == '\"' ? source.lastIndexOf("\"", offset - 1) : source.lastIndexOf("\"", offset); //$NON-NLS-1$ //$NON-NLS-2$
120120 StringBuffer buf = new StringBuffer();
121121 for (int i = idx + 1; i < offset; i++) {
122122 char c = source.charAt(i);
@@ -147,7 +147,7 @@
147147 }
148148
149149 public String getErrorMessage() {
150- return "An error happened when searching the property.";
150+ return Messages.getString("eclipse.propertieseditor.PropertiesCompletionProposalComputer.4"); //$NON-NLS-1$
151151 }
152152
153153 public void sessionEnded() {
@@ -155,38 +155,5 @@
155155
156156 public void sessionStarted() {
157157 }
158-
159- public IFile[] findFileExt(IContainer container, IPath excludePath, String extension) {
160- IResource[] list = null;
161- try {
162- list = container.members();
163- } catch (CoreException e) {
164- IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e);
165- ILog log = PropertiesEditorPlugin.getDefault().getLog();
166- log.log(status);
167- return new IFile[0];
168- }
169- if (list == null) {
170- return new IFile[0];
171- }
172- List fileList = new ArrayList();
173- for (int i = 0; i < list.length; i++) {
174- if (list[i] instanceof IFile) {
175- if (extension.equals(list[i].getFileExtension())) {
176- fileList.add((IFile)list[i]);
177- }
178- } else if (list[i] instanceof IContainer) {
179- if (excludePath.matchingFirstSegments(list[i].getFullPath()) == excludePath.segmentCount()) {
180- continue;
181- }
182- IFile[] files = findFileExt((IContainer)list[i], excludePath, extension);
183- for (int j = 0; j < files.length; j++) {
184- fileList.add(files[j]);
185- }
186- }
187- }
188-
189- return (IFile[])fileList.toArray(new IFile[0]);
190- }
191158
192159 }
--- trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/jdt/hover/PropertiesHover.java (nonexistent)
+++ trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/jdt/hover/PropertiesHover.java (revision 182)
@@ -0,0 +1,194 @@
1+/**
2+ *
3+ */
4+package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.jdt.hover;
5+
6+import java.io.IOException;
7+import java.util.Enumeration;
8+import java.util.Properties;
9+
10+import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin;
11+import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.resources.Messages;
12+import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.util.PropertiesFileUtil;
13+
14+import org.eclipse.core.resources.IFile;
15+import org.eclipse.core.resources.IProject;
16+import org.eclipse.core.runtime.CoreException;
17+import org.eclipse.core.runtime.ILog;
18+import org.eclipse.core.runtime.IPath;
19+import org.eclipse.core.runtime.IStatus;
20+import org.eclipse.core.runtime.Status;
21+import org.eclipse.jdt.core.IJavaProject;
22+import org.eclipse.jdt.core.JavaCore;
23+import org.eclipse.jdt.core.JavaModelException;
24+import org.eclipse.jdt.ui.text.java.hover.IJavaEditorTextHover;
25+import org.eclipse.jface.text.BadLocationException;
26+import org.eclipse.jface.text.IDocument;
27+import org.eclipse.jface.text.IRegion;
28+import org.eclipse.jface.text.ITextViewer;
29+import org.eclipse.ui.IEditorInput;
30+import org.eclipse.ui.IEditorPart;
31+import org.eclipse.ui.IFileEditorInput;
32+
33+/**
34+ *
35+ */
36+public class PropertiesHover implements IJavaEditorTextHover {
37+
38+ private IEditorPart editorPart;
39+
40+ /**
41+ * @see org.eclipse.jdt.ui.text.java.hover.IJavaEditorTextHover#setEditor(org.eclipse.ui.IEditorPart)
42+ */
43+ public void setEditor(IEditorPart editorPart) {
44+ this.editorPart = editorPart;
45+ }
46+
47+ /**
48+ * @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
49+ */
50+ public String getHoverInfo(ITextViewer textViewer, IRegion region) {
51+ IDocument document = textViewer.getDocument();
52+ int offset = region.getOffset();
53+ try {
54+ int lineNum = document.getLineOfOffset(offset);
55+ int lineOffset = document.getLineOffset(lineNum);
56+ int lineLength = document.getLineLength(lineNum);
57+ String source = document.get();
58+ int startIdx = -1;
59+ int tmp = offset - 1;
60+ while (tmp >= lineOffset) {
61+ tmp = source.lastIndexOf("\"", tmp); //$NON-NLS-1$
62+ if (tmp < lineOffset) {
63+ startIdx = -1;
64+ break;
65+ }
66+ if (tmp > 0) {
67+ if (document.getChar(tmp - 1) == '\\') {
68+ continue;
69+ } else {
70+ startIdx = tmp + 1;
71+ break;
72+ }
73+ } else if (tmp == 0) {
74+ startIdx = 0 + 1;
75+ break;
76+ } else {
77+ startIdx = -1;
78+ break;
79+ }
80+ }
81+ tmp = offset + 1;
82+ int endIdx = -1;
83+ while (tmp < lineOffset + lineLength) {
84+ tmp = source.indexOf("\"", tmp); //$NON-NLS-1$
85+ if (tmp > lineOffset + lineLength) {
86+ endIdx = -1;
87+ break;
88+ }
89+ if (tmp > 0) {
90+ if (document.getChar(tmp - 1) == '\\') {
91+ continue;
92+ } else {
93+ endIdx = tmp;
94+ break;
95+ }
96+ } else if (tmp == 0) {
97+ endIdx = 0;
98+ break;
99+ } else {
100+ endIdx = -1;
101+ }
102+ }
103+
104+ if (startIdx == -1 || endIdx == -1 || startIdx == endIdx) {
105+ return null;
106+ }
107+
108+ String key = textViewer.getDocument().get(startIdx, endIdx - startIdx);
109+
110+ return getPropertyValue(key);
111+
112+ } catch (BadLocationException e) {
113+ IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e);
114+ ILog log = PropertiesEditorPlugin.getDefault().getLog();
115+ log.log(status);
116+ return null;
117+ }
118+ }
119+
120+ private String getPropertyValue(String targetKey) {
121+ if (targetKey == null || targetKey.equals("")) { //$NON-NLS-1$
122+ return ""; //$NON-NLS-1$
123+ }
124+
125+ IEditorInput editorInput = this.editorPart.getEditorInput();
126+
127+ if (editorInput instanceof IFileEditorInput) {
128+
129+ IFileEditorInput fEditorInput = (IFileEditorInput)editorInput;
130+ IProject project = fEditorInput.getFile().getProject();
131+ IJavaProject jProject = JavaCore.create(project);
132+
133+ IPath outputPath = null;
134+ try {
135+ outputPath = jProject.getOutputLocation();
136+ } catch (JavaModelException 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);
140+ }
141+
142+ IFile[] pFiles = PropertiesFileUtil.findFileExt(project, outputPath, "properties"); //$NON-NLS-1$
143+
144+ Properties list = new Properties();
145+ for (int i = 0; i < pFiles.length; i++) {
146+ Properties prop = new Properties();
147+ try {
148+ prop.load(pFiles[i].getContents());
149+ } catch (IOException e) {
150+ IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e);
151+ ILog log = PropertiesEditorPlugin.getDefault().getLog();
152+ log.log(status);
153+ } catch (CoreException e) {
154+ IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e);
155+ ILog log = PropertiesEditorPlugin.getDefault().getLog();
156+ log.log(status);
157+ }
158+
159+ if (prop.containsKey(targetKey)) {
160+ list.put(pFiles[i].getFullPath().toPortableString(), prop.getProperty(targetKey));
161+ }
162+ }
163+
164+ if (list.isEmpty()) {
165+ return null;
166+ }
167+
168+ Enumeration enu = list.keys();
169+ StringBuffer buf = new StringBuffer();
170+ buf.append("&lt;").append(Messages.getString("eclipse.propertieseditor.hover.key")).append(":").append(targetKey).append("&gt;<br/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
171+ while (enu.hasMoreElements()) {
172+ String path = (String)enu.nextElement();
173+ String value = (String)list.get(path);
174+ value = value.replaceAll("\r\n", "<br/>"); //$NON-NLS-1$ //$NON-NLS-2$
175+ value = value.replaceAll("\n", "<br/>"); //$NON-NLS-1$ //$NON-NLS-2$
176+ value = value.replaceAll("\r", "<br/>"); //$NON-NLS-1$ //$NON-NLS-2$
177+ buf.append("&lt;").append(Messages.getString("eclipse.propertieseditor.hover.file")).append(":").append(path).append("&gt;<br/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
178+ buf.append(value);
179+ buf.append("<br/>"); //$NON-NLS-1$
180+ }
181+ return buf.toString();
182+ } else {
183+ return null;
184+ }
185+ }
186+
187+ /**
188+ * @see org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer, int)
189+ */
190+ public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
191+ return null;
192+ }
193+
194+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/property/PropertiesProperty.java (revision 181)
+++ trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/property/PropertiesProperty.java (revision 182)
@@ -235,7 +235,7 @@
235235
236236 protected void performDefaults() {
237237 commentText.setText("#"); //$NON-NLS-1$
238- convertCharCaseCombo.setText(Messages.getString("eclipse.propertieseditor.preference.convert.char.lowercase"));
238+ convertCharCaseCombo.setText(Messages.getString("eclipse.propertieseditor.preference.convert.char.lowercase")); //$NON-NLS-1$
239239 notAllConvertCheckBox.setSelection(false);
240240 notConvertCommentCheckBox.setEnabled(false);
241241 notConvertCommentCheckBox.setSelection(false);
--- trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/util/PropertiesFileUtil.java (nonexistent)
+++ trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/util/PropertiesFileUtil.java (revision 182)
@@ -0,0 +1,51 @@
1+package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.util;
2+
3+import java.util.ArrayList;
4+import java.util.List;
5+
6+import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin;
7+
8+import org.eclipse.core.resources.IContainer;
9+import org.eclipse.core.resources.IFile;
10+import org.eclipse.core.resources.IResource;
11+import org.eclipse.core.runtime.CoreException;
12+import org.eclipse.core.runtime.ILog;
13+import org.eclipse.core.runtime.IPath;
14+import org.eclipse.core.runtime.IStatus;
15+import org.eclipse.core.runtime.Status;
16+
17+public class PropertiesFileUtil {
18+
19+ public static IFile[] findFileExt(IContainer container, IPath excludePath, String extension) {
20+ IResource[] list = null;
21+ try {
22+ list = container.members();
23+ } catch (CoreException e) {
24+ IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e);
25+ ILog log = PropertiesEditorPlugin.getDefault().getLog();
26+ log.log(status);
27+ return new IFile[0];
28+ }
29+ if (list == null) {
30+ return new IFile[0];
31+ }
32+ List fileList = new ArrayList();
33+ for (int i = 0; i < list.length; i++) {
34+ if (list[i] instanceof IFile) {
35+ if (extension.equals(list[i].getFileExtension())) {
36+ fileList.add((IFile)list[i]);
37+ }
38+ } else if (list[i] instanceof IContainer) {
39+ if (excludePath.matchingFirstSegments(list[i].getFullPath()) == excludePath.segmentCount()) {
40+ continue;
41+ }
42+ IFile[] files = findFileExt((IContainer)list[i], excludePath, extension);
43+ for (int j = 0; j < files.length; j++) {
44+ fileList.add(files[j]);
45+ }
46+ }
47+ }
48+
49+ return (IFile[])fileList.toArray(new IFile[0]);
50+ }
51+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/preference/PropertiesPreference.java (revision 181)
+++ trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/preference/PropertiesPreference.java (revision 182)
@@ -33,7 +33,7 @@
3333
3434 private RadioGroupFieldEditor convertCharCaseField;
3535
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$
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$ //$NON-NLS-3$ //$NON-NLS-4$
3737
3838 public PropertiesPreference() {
3939
--- trunk/PropertiesEditor/plugin.xml (revision 181)
+++ trunk/PropertiesEditor/plugin.xml (revision 182)
@@ -217,5 +217,24 @@
217217 priority="high"
218218 default-charset=""/>
219219 </extension>
220+ <extension
221+ point="org.eclipse.ui.newWizards">
222+ <wizard
223+ id="jp.gr.java_conf.ussiy.app.propedit.newwizard"
224+ name="%wizardName"
225+ class="jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.wizard.BasicNewPropertiesFileWizard"
226+ category="org.eclipse.jdt.ui.java"
227+ icon="icons/pe_32.gif"
228+ project="false"/>
229+ </extension>
230+ <extension
231+ point="org.eclipse.jdt.ui.javaEditorTextHovers">
232+ <hover
233+ id="jp.gr.java_conf.ussiy.app.propedit.hover"
234+ class="jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.jdt.hover.PropertiesHover"
235+ label="%hoverLabel"
236+ description="%hoverDescription"
237+ activate="true"/>
238+ </extension>
220239
221240 </plugin>
Show on old repository browser