2012-04-10 8 views
3

状況依存ヘルプが必要なJava Desktopアプリケーションがあります。 たとえば、Validatorアプリケーションは入力をSQL文として取得し、入力された内容に基づいて状況依存ヘルプを表示する必要があります。Javaアプリケーションで状況依存ヘルプを作成する方法

つのユースケースが考えられますときに、ユーザータイプ「更新」とし、Ctrl +スペースを押すことは、私はこのために行くにはどうすればよい

状況依存ヘルプとして、テーブル名のリストを表示する必要がありますか?

+0

自動補完/先行入力または状況依存ヘルプを意味しますか?後者は、あなたが開いているインターフェースのどのダイアログ/部分に基づいてヘルプファイルの関連部分に行くことができるかです。 –

+0

これがSwingベースのアプリケーションの場合は、[GlassPane](http://docs.oracle.com/javase/tutorial/uiswing/components/rootpane.html)を参照してください。 – alphazero

答えて

1

eclipse RCPアプリケーションを作成し、eclipseエディターを拡張します。

eclipseを使用すると、エディタを作成してコンテンツの補助を追加するのは非常に簡単です。

これを見てくださいFAQ

+0

あなたの提供するリンクには詳細はありませんか? "現在このページにはテキストはありません。このページのタイトルを他のページで検索したり、このページを編集することができます。 – Reg

+1

私はDash1eがFAQリンクhttp://wiki.eclipse.org/FAQ_How_do_I_add_Content_Assist_to_my_editor%3F – siva

+0

でこれを参照しようとしていると思います。 – dash1e

1

あなたの質問を完全に理解しているかどうかわかりません。私はあなたがスイングでこれをやっていると思います。あなたが検索を入力しているときにGoogleが持っているように、それらのawtホバーのようなものの1つを探しています(申し訳ありませんが、それは畏敬の念です、私はちょうどそれが呼ばれていることを覚えていないことができます)?

私はそれを手伝ってくれるかどうかは分かりませんが、ここではリフレクションを使って属性の値に基づいてオブジェクトを検索用語と照合する方法を紹介します。これはあなたがまったく必要ないものかもしれませんが、もし私があなたにそれを与えることができる場合に備えて、私は考えました。それが役に立てば幸い!

/** 
    * Returns true if any attribute in the item matches the given constraints 
    * 
    * @param object the object you want to match 
    * @param klass the class to get the fields from (in most cases you'll just call object.getClass()) 
    * @param iterations how many inherited levels you want to check fields for 
    * @param match the String to match fields against 
    * @param ignoreField fieldNames you wish to ignore, you can give as many as you like, you can also give an 
    * array of strings 
    * @return whether the given object contained fields which matched the given string 
    */ 
    public static boolean matches(Object object, Class klass, int iterations, String match, String... ignoreField) { 
    if (iterations < 0) { 
     return false; 
    } 
    boolean checkMatch = false; 
    try { 
     checkMatch = matchFields(klass.getDeclaredFields(), object, match, ignoreField); 
    } catch (IllegalArgumentException ex) { 
     Logger.getLogger(OtherHelper.class.getName()).log(Level.SEVERE, null, ex); 
    } catch (IllegalAccessException ex) { 
     Logger.getLogger(OtherHelper.class.getName()).log(Level.SEVERE, null, ex); 
    } 
    if (checkMatch) { 
     return true; 
    } else { 
     Class<? extends Object> supersSuperclass = (Class<? extends Object>) klass.getSuperclass(); 
     if (supersSuperclass != Object.class) { 
     boolean matches = matches(object, supersSuperclass, (iterations - 1), match, ignoreField); 
     if (matches) { 
      return true; 
     } else { 
      return false; 
     } 
     } else { 
     return false; 
     } 
    } 
    } 

    /** 
    * Calls matchField(field, bo, match) on each field in the given field array. 
    * 
    * @param fields the fields array to get the fields from 
    * @param object the object to get the field values from 
    * @param match the text to match fields to 
    * @param ignoreField any number of fieldNames which are to be ignored. 
    * @return true on first true field match 
    * @throws IllegalArgumentException 
    * @throws IllegalArgumentException 
    * @throws IllegalAccessException 
    */ 
    private static boolean matchFields(Field[] fields, Object object, String match, String... ignoreField) throws IllegalArgumentException, IllegalArgumentException, IllegalAccessException { 
    List<String> ignoreFieldsList = Arrays.asList(ignoreField); 
    for (Field field : fields) { 
     if (!ignoreFieldsList.contains(field.getName())) { 
     if (matchField(field, object, match)) { 
      return true; 
     } 
     } 
    } 
    return false; 
    } 

    /** 
    * Gets the value of the field and matches the string version of it with the given match 
    * 
    * @param field the field to match 
    * @param object the object to get the field value from 
    * @param match the match to match the field value to. 
    * @return 
    * @throws IllegalArgumentException 
    * @throws IllegalArgumentException 
    * @throws IllegalAccessException 
    */ 
    private static boolean matchField(Field field, Object object, String match) throws IllegalArgumentException, IllegalArgumentException, IllegalAccessException { 
    field.setAccessible(true); 
    if (field.get(object) == null) { 
     return false; 
    } 
    Class<?> type = field.getType(); 
    String value = null; 
    if (type == Date.class) { 
     SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy"); 
     Date date = (Date) field.get(object); 
     value = sdf.format(date); 
    } else if (type == String.class || isPrimitive(type)) { 
     value = field.get(object).toString(); 
    } 
    if (value != null 
      && Pattern.compile(Pattern.quote(match), Pattern.CASE_INSENSITIVE).matcher(value).find()) { 
     return true; 
    } else { 
     return false; 
    } 
    } 

    /** 
    * Checks first whether it is primitive and then whether it's wrapper is a primitive wrapper. Returns true 
    * if either is true 
    * 
    * @param c 
    * @return whether it's a primitive type itself or it's a wrapper for a primitive type 
    */ 
    public static boolean isPrimitive(Class c) { 
    if (c.isPrimitive()) { 
     return true; 
    } else if (c == Byte.class 
      || c == Short.class 
      || c == Integer.class 
      || c == Long.class 
      || c == Float.class 
      || c == Double.class 
      || c == Boolean.class 
      || c == Character.class) { 
     return true; 
    } else { 
     return false; 
    } 
    } 
+0

ツールチップと呼ばれています。 – alphazero

+0

@alphazeroいいえ、それは私が考えているものではありません。私は、Googleインスタントのように、あなたが入力するときにポップアップしてフィルタリングするリストを考えています。 – kentcdodds

関連する問題