Author: takezoe
Date: Sun Mar 14 14:40:06 2010
New Revision: 922870
URL: http://svn.apache.org/viewvc?rev=922870&view=rev
Log:
[CLKE-39]Fixed browsing page class and page classname completion behavior.
Modified:
click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ClickPlugin.java
click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ClickUtils.java
click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ui/editor/attrs/AttributeEditorUtils.java
click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ui/fieldassist/TypeNameContentProposalProvider.java
Modified: click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ClickPlugin.java
URL: http://svn.apache.org/viewvc/click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ClickPlugin.java?rev=922870&r1=922869&r2=922870&view=diff
==============================================================================
--- click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ClickPlugin.java
(original)
+++ click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ClickPlugin.java
Sun Mar 14 14:40:06 2010
@@ -161,7 +161,7 @@ public class ClickPlugin extends Abstrac
* @param substitutions the substitutions
* @return the localized and formatted message
*/
- public static String getString(String key, Object [] substitutions){
+ public static String getString(String key, Object... substitutions){
return MessageFormat.format(getString(key), substitutions);
}
Modified: click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ClickUtils.java
URL: http://svn.apache.org/viewvc/click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ClickUtils.java?rev=922870&r1=922869&r2=922870&view=diff
==============================================================================
--- click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ClickUtils.java
(original)
+++ click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ClickUtils.java
Sun Mar 14 14:40:06 2010
@@ -751,6 +751,9 @@ public class ClickUtils {
return simpleName;
}
+ /**
+ * Copy data from <code>InputStream</code> to <code>OutputStream</code>.
+ */
public static void copyStream(InputStream in, OutputStream out){
try {
byte[] buf = new byte[1024 * 8];
@@ -766,6 +769,9 @@ public class ClickUtils {
}
}
+ /**
+ * Read <code>InputStream</code> as UTF-8 text.
+ */
public static String readStream(InputStream in){
ByteArrayOutputStream out = new ByteArrayOutputStream();
copyStream(in, out);
@@ -786,5 +792,25 @@ public class ClickUtils {
}
}
+ /**
+ * Tests the given string is null or empty.
+ *
+ * @param value test string
+ * @return true if value is null or empty, false otherwise
+ */
+ public static boolean isEmpty(String value){
+ return value == null || value.length() == 0;
+ }
+
+ /**
+ * Tests the given string is not null and empty.
+ *
+ * @param value test string
+ * @return true if value is not null and empty, false otherwise
+ */
+ public static boolean isNotEmpty(String value){
+ return !isEmpty(value);
+ }
+
}
Modified: click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ui/editor/attrs/AttributeEditorUtils.java
URL: http://svn.apache.org/viewvc/click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ui/editor/attrs/AttributeEditorUtils.java?rev=922870&r1=922869&r2=922870&view=diff
==============================================================================
--- click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ui/editor/attrs/AttributeEditorUtils.java
(original)
+++ click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ui/editor/attrs/AttributeEditorUtils.java
Sun Mar 14 14:40:06 2010
@@ -78,9 +78,9 @@ public class AttributeEditorUtils {
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- if(element!=null){
+ if(element != null){
String initialValue = element.getAttribute(attrName);
- if(initialValue!=null){
+ if(initialValue != null){
text.setText(initialValue);
}
}
@@ -108,9 +108,9 @@ public class AttributeEditorUtils {
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- if(element!=null){
+ if(element != null){
String initialValue = element.getAttribute(attrName);
- if(initialValue!=null){
+ if(initialValue != null){
text.setText(initialValue);
}
}
@@ -135,10 +135,10 @@ public class AttributeEditorUtils {
Composite composite = FieldAssistUtils.createNullDecoratedPanel(parent, true);
final Combo combo = new Combo(composite, SWT.READ_ONLY);
- for(int i=0;i<values.length;i++){
+ for(int i = 0; i < values.length; i++){
combo.add(values[i]);
}
- if(element!=null){
+ if(element != null){
String initialValue = element.getAttribute(attrName);
if(initialValue!=null){
combo.setText(initialValue);
@@ -148,6 +148,8 @@ public class AttributeEditorUtils {
return combo;
}
+
+
/**
* Creates the classname field editor.
*
@@ -164,38 +166,40 @@ public class AttributeEditorUtils {
final IDOMElement element, String label, final String attrName,
final String superClass, final Text textFileName){
+ // packagename of page class
+ final String packageName = getPagePackageName(element, superClass);
+
final Hyperlink link = toolkit.createHyperlink(parent, label, SWT.NULL);
link.addHyperlinkListener(new HyperlinkAdapter(){
public void linkActivated(HyperlinkEvent e){
try {
Control[] controls = parent.getChildren();
Text text = null;
- for(int i=0;i<controls.length;i++){
- if(i>0 && controls[i-1]==link && controls[i] instanceof Composite){
+ for(int i = 0; i < controls.length; i++){
+ if(i > 0 && controls[i-1] == link && controls[i] instanceof Composite){
Composite composite = (Composite)controls[i];
text = (Text)((Composite)composite.getChildren()[0]).getChildren()[0];
}
}
- if(text!=null && !text.getText().equals("")){
+ if(text != null && !text.getText().equals("")){
String className = text.getText();
- if(superClass!=null && superClass==ClickPlugin.CLICK_PAGE_CLASS){
- String packageName = ((Element)element.getParentNode()).getAttribute(ClickPlugin.ATTR_PACKAGE);
- if(packageName!=null && packageName.length()!=0){
+ if(superClass != null && superClass == ClickPlugin.CLICK_PAGE_CLASS){
+ if(ClickUtils.isNotEmpty(packageName)){
className = packageName + "." + className;
}
}
IFile file = (IFile)ClickUtils.getResource(element.getStructuredDocument());
IJavaProject project = JavaCore.create(file.getProject());
IType type = project.findType(className);
- if(type!=null){
+ if(type != null){
JavaUI.revealInEditor(JavaUI.openInEditor(type), (IJavaElement)type);
} else {
- if(superClass!=null && superClass==ClickPlugin.CLICK_PAGE_CLASS){
+ if(superClass != null && superClass == ClickPlugin.CLICK_PAGE_CLASS){
// Opens the new page creation wizard
NewClickPageWizard wizard = new NewClickPageWizard();
wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(project));
wizard.setInitialClassName(className);
- if(textFileName!=null){
+ if(textFileName != null){
wizard.setInitialPageName(textFileName.getText());
}
WizardDialog dialog = new WizardDialog(text.getShell(), wizard);
@@ -204,7 +208,7 @@ public class AttributeEditorUtils {
// Opens the new java class creation wizard
NewClassWizard wizard = new NewClassWizard();
wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(project));
- if(superClass!=null){
+ if(superClass != null){
if(superClass == ClickPlugin.CLICK_CONTROL_IF || superClass.endsWith("Service")){
wizard.addInterface(superClass);
} else {
@@ -227,18 +231,18 @@ public class AttributeEditorUtils {
Composite composite = toolkit.createComposite(parent);
composite.setLayout(FieldAssistUtils.createGridLayout());
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
+
ContentAssistField field = new ContentAssistField(composite, SWT.BORDER,
new TextControlCreator(), new TextContentAdapter(),
- new TypeNameContentProposalProvider(project),
+ new TypeNameContentProposalProvider(project, packageName),
ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS,
new char[0]);
- final Text text = (Text)field.getControl();
+ final Text text = (Text) field.getControl();
field.getLayoutControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
field.getLayoutControl().setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
- if(element!=null){
+ if(element != null){
String initialValue = element.getAttribute(attrName);
if(initialValue!=null){
text.setText(initialValue);
@@ -255,9 +259,13 @@ public class AttributeEditorUtils {
SearchEngine.createJavaSearchScope(new IJavaElement[]{project}),
IJavaElementSearchConstants.CONSIDER_CLASSES,false);
- if(dialog.open()==SelectionDialog.OK){
+ if(dialog.open() == SelectionDialog.OK){
Object[] result = dialog.getResult();
- text.setText(((IType)result[0]).getFullyQualifiedName());
+ String className = ((IType)result[0]).getFullyQualifiedName();
+ if(ClickUtils.isNotEmpty(packageName) && className.startsWith(packageName)){
+ className = className.substring(packageName.length() + 1);
+ }
+ text.setText(className);
}
} catch(Exception ex){
ClickPlugin.log(ex);
@@ -268,4 +276,12 @@ public class AttributeEditorUtils {
return text;
}
+ private static String getPagePackageName(final IDOMElement element, final String superClass)
{
+ String packageName = null;
+ if(superClass != null && superClass == ClickPlugin.CLICK_PAGE_CLASS){
+ packageName = ((Element) element.getParentNode()).getAttribute(ClickPlugin.ATTR_PACKAGE);
+ }
+ return packageName;
+ }
+
}
Modified: click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ui/fieldassist/TypeNameContentProposalProvider.java
URL: http://svn.apache.org/viewvc/click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ui/fieldassist/TypeNameContentProposalProvider.java?rev=922870&r1=922869&r2=922870&view=diff
==============================================================================
--- click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ui/fieldassist/TypeNameContentProposalProvider.java
(original)
+++ click/trunk/tools/eclipse/org.apache.click.eclipse/src/org/apache/click/eclipse/ui/fieldassist/TypeNameContentProposalProvider.java
Sun Mar 14 14:40:06 2010
@@ -21,6 +21,7 @@ package org.apache.click.eclipse.ui.fiel
import java.util.ArrayList;
import java.util.List;
+import org.apache.click.eclipse.ClickUtils;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner;
@@ -39,6 +40,7 @@ import org.eclipse.jface.fieldassist.ICo
public class TypeNameContentProposalProvider implements IContentProposalProvider {
private IJavaProject project;
+ private String packageName;
/**
* Constructor.
@@ -46,25 +48,40 @@ public class TypeNameContentProposalProv
* @param project the Java project
*/
public TypeNameContentProposalProvider(IJavaProject project){
- this.project = project;
+ this(project, null);
}
- public void setJavaProject(IJavaProject project){
+ /**
+ * Constructor.
+ *
+ * @param project the Java project
+ * @param packageName prefix of the package name
+ */
+ public TypeNameContentProposalProvider(IJavaProject project, String packageName){
this.project = project;
+ this.packageName = packageName;
}
public IContentProposal[] getProposals(String contents, int position) {
try {
+ String rawContents = contents;
+
CompletionProposalCollector collector = new CompletionProposalCollector(project);
ICompilationUnit unit = FieldAssistUtils.getTemporaryCompilationUnit(project);
+
contents = contents.substring(0, position);
+ if(ClickUtils.isNotEmpty(packageName)){
+ contents = packageName + "." + contents;
+ }
+
String source = "public class _xxx { public static void hoge(){ " + contents + "}}";
+
FieldAssistUtils.setContentsToCU(unit, source);
unit.codeComplete(source.length() - 2, collector, DefaultWorkingCopyOwner.PRIMARY);
IJavaCompletionProposal[] proposals = collector.getJavaCompletionProposals();
List<IContentProposal> result = new ArrayList<IContentProposal>();
- for(int j=0;j<proposals.length;j++){
+ for(int j = 0; j < proposals.length; j++){
if(proposals[j].getImage()!=null){
String replaceString = null;
if(proposals[j] instanceof LazyJavaTypeCompletionProposal){
@@ -74,8 +91,17 @@ public class TypeNameContentProposalProv
JavaCompletionProposal p = (JavaCompletionProposal)proposals[j];
replaceString = p.getReplacementString();
}
- if(replaceString!=null && replaceString.startsWith(contents)){
- result.add(new FieldAssistUtils.ContentProposalImpl(replaceString, position));
+
+ if(ClickUtils.isNotEmpty(replaceString)){
+ if(replaceString.equals("_xxx")){
+ continue;
+ }
+ if(ClickUtils.isNotEmpty(packageName) && replaceString.startsWith(packageName)){
+ replaceString = replaceString.substring(packageName.length() + 1);
+ }
+ if(ClickUtils.isNotEmpty(replaceString) && replaceString.startsWith(rawContents)){
+ result.add(new FieldAssistUtils.ContentProposalImpl(replaceString, position));
+ }
}
}
}
|