隨筆 - 6, 文章 - 3, 評論 - 3, 引用 - 0
          數(shù)據(jù)加載中……

          使用workbenchkeyboard

          IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
          Workbench workbench = (Workbench)configurer.getWindow().getWorkbench();
          ?
          //????????
          WorkbenchKeyboard workbenchkeyboard = new WorkbenchKeyboard(workbench);????????
          workbenchkeyboard.openMultiKeyAssistShell();

          當(dāng)然workbench必需是被創(chuàng)建以后才可以

          這樣就可以show key assist出來啦~

          <extension
          ???????? point="org.eclipse.ui.commands">
          ????? <command
          ??????????? categoryId="org.eclipse.ui.category.file"
          ??????????? id="KeyAssist.test.save"
          ??????????? name="Test Key Assist "/>
          ?? </extension>
          ?? <extension
          ???????? point="org.eclipse.ui.bindings">
          ????? <key
          ??????????? commandId="KeyAssist.test.save"
          ??????????? contextId="org.eclipse.ui.contexts.dialogAndWindow"
          ??????????? schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
          ??????????? sequence="M1+Q"/>
          ?? </extension>

          定義多以上東東就可以顯示自己的keyassit item啦。


          終于研究出如何runtime modify keyassist了,記下這個(gè)util class

          ??1 package ?com.hactl.eaf.ui.rich.composite.widget.keyassist;
          ??2
          ??3 import ?java.io.IOException;
          ??4 import ?java.util.HashMap;
          ??5 import ?java.util.Iterator;
          ??6 import ?java.util.Set;
          ??7
          ??8 import ?org.eclipse.core.commands.Command;
          ??9 import ?org.eclipse.core.commands.ParameterizedCommand;
          ?10 import ?org.eclipse.jface.bindings.Binding;
          ?11 import ?org.eclipse.jface.bindings.keys.KeyBinding;
          ?12 import ?org.eclipse.jface.bindings.keys.KeySequence;
          ?13 import ?org.eclipse.jface.bindings.keys.ParseException;
          ?14 import ?org.eclipse.ui.IWorkbench;
          ?15 import ?org.eclipse.ui.commands.ICommandService;
          ?16 import ?org.eclipse.ui.internal.Workbench;
          ?17 import ?org.eclipse.ui.internal.keys.WorkbenchKeyboard;
          ?18 import ?org.eclipse.ui.keys.IBindingService;
          ?19
          ?20 /**
          ?21 ?*?ShortCutKeyAssist?Util
          ?22 ?*?<p>
          ?23 ?*?this?class?can?modify?KeyAssist?in?runtime
          ?24 ?*?
          ?25 ?*? @author ?baal
          ?26 ?*?2006.05.17
          ?27 ? */

          ?28
          ?29 public ? class ?ShortCutKeyAssist? {
          ?30 ????
          ?31 ???? // schemeid?mapping?plugin.xml
          ?32 ???? private ? final ? static ?String?SCHEME_NAME? = ? " com.hactl.eaf.ui.rich.application.defaultAcceleratorConfiguration " ;
          ?33
          ?34 ???? // contextid?mapping?plugin.xml
          ?35 ???? private ? final ? static ?String?CONTEXT_NAME? = ? " org.eclipse.ui.contexts.dialogAndWindow " ;
          ?36 ????
          ?37 ???? // categroyid?mapping?plugin.xml
          ?38 ???? private ? final ? static ?String?CATEGORY_NAME? = ? " RichClient.category " ;
          ?39 ????
          ?40 ???? private ?Workbench?workbench;
          ?41
          ?42 ???? private ?ICommandService?commandService;
          ?43
          ?44 ???? private ?IBindingService?bindingService;
          ?45
          ?46 ???? private ?Binding[]?oldbindings;
          ?47
          ?48 ???? private ?HashMap?newbindings;
          ?49
          ?50 ???? public ?ShortCutKeyAssist(IWorkbench?workbench)? {
          ?51
          ?52 ???????? this .workbench? = ?(Workbench)?workbench;
          ?53
          ?54 ????????bindingService? = ?(IBindingService)?workbench
          ?55 ????????????????.getAdapter(IBindingService. class );
          ?56 ????????commandService? = ?(ICommandService)?workbench
          ?57 ????????????????.getAdapter(ICommandService. class );
          ?58
          ?59 ????????oldbindings? = ?bindingService.getBindings();
          ?60
          ?61 ????????newbindings? = ? new ?HashMap();
          ?62
          ?63 ????}

          ?64
          ?65 ???? public ?KeyBinding?addShortKey(String?commandId,?String?commandName,
          ?66 ????????????String?keySequence,?String?description)? {
          ?67 ????????KeySequence?seq? = ? null ;
          ?68 ????????KeyBinding?binding;
          ?69 ???????? final ?Command?command? = ?commandService.getCommand(commandId);
          ?70
          ?71 ???????? if ?( ! command.isDefined())
          ?72 ????????????command.define(commandName,?description,?commandService
          ?73 ????????????????????.getCategory(CATEGORY_NAME),? null );
          ?74
          ?75 ???????? try ? {
          ?76 ????????????seq? = ?KeySequence.getInstance(keySequence);
          ?77 ????????}
          ? catch ?(ParseException?e1)? {
          ?78 ???????????? // ?TODO?Auto-generated?catch?block
          ?79 ????????????e1.printStackTrace();
          ?80 ????????}

          ?81
          ?82 ????????binding? = ? new ?KeyBinding(seq,? new ?ParameterizedCommand(command,? null ),
          ?83 ????????????????SCHEME_NAME,?CONTEXT_NAME,? "" ,? "" ,? null ,?Binding.USER);
          ?84
          ?85 ????????newbindings.put(keySequence,binding);
          ?86 ????????System.out.println(newbindings.get(keySequence));
          ?87 ???????? return ?binding;
          ?88 ????}

          ?89
          ?90 ???? public ? void ?removeAllShortKey()? {
          ?91 ????????newbindings.clear();
          ?92 ????}

          ?93
          ?94 ???? public ? void ?removeShortKey(String?keySequence)? {
          ?95 ????????newbindings.remove(keySequence);
          ?96 ????}

          ?97
          ?98 ???? public ? void ?OpenKeyAssist()? {
          ?99 ????????recomputeBindings();
          100 ????????WorkbenchKeyboard?workbenchkeyboard? = ? new ?WorkbenchKeyboard(
          101 ???????????????? this .workbench);
          102 ????????workbenchkeyboard.openMultiKeyAssistShell();
          103 ????}

          104
          105 ???? private ? void ?recomputeBindings()? {
          106
          107 ????????Binding[]?bindings? = ? new ?Binding[oldbindings.length
          108 ???????????????? + ?newbindings.size()];
          109 ????????System.arraycopy(oldbindings,? 0 ,?bindings,? 0 ,?oldbindings.length);
          110 ????????
          111 ????????Set?set? = ?newbindings.keySet();
          112 ????????Iterator?iter? = ?set.iterator();
          113 ????????????????
          114 ???????? for ?( int ?i? = ?oldbindings.length;?i? < ?bindings.length;?i ++ )? {
          115 ???????????? if ?(iter.hasNext())
          116 ????????????bindings[i]? = ?(Binding)?newbindings.get(iter.next());
          117 ????????}

          118
          119 ???????? try ? {
          120 ????????????bindingService.savePreferences(bindingService
          121 ????????????????????.getScheme(SCHEME_NAME),?bindings);
          122
          123 ????????}
          ? catch ?(IOException?e)? {
          124 ???????????? // ?TODO?Auto-generated?catch?block
          125 ????????????e.printStackTrace();
          126 ????????}

          127 ????}

          128 }

          129


          關(guān)于command這個(gè)東西,也有點(diǎn)bt,自定義的command會記錄在runtime data里,so 第一次run可以看到的item第二次就看不到。需要在run的選項(xiàng)里選中clear workspace data

          posted on 2006-05-12 15:34 馬甲丁 閱讀(819) 評論(2)  編輯  收藏 所屬分類: Eclipse

          評論

          # re: 使用workbenchkeyboard   回復(fù)  更多評論   

          你的pda開發(fā)很牛吧
          2006-05-18 11:53 | colin

          # re: 使用workbenchkeyboard   回復(fù)  更多評論   

          @colin
          一般一般,才玩沒幾天。
          colin? 是不是我認(rèn)識哪個(gè)?
          2006-05-19 09:07 | 馬甲丁

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 鸡东县| 仁化县| 宝清县| 青海省| 延安市| 昔阳县| 侯马市| 云阳县| 吴桥县| 定兴县| 司法| 博野县| 玛沁县| 大竹县| 文登市| 栾城县| 阆中市| 桐庐县| 门头沟区| 洛隆县| 涡阳县| 阿坝县| 兴隆县| 武穴市| 兰坪| 丽水市| 青川县| 彭阳县| 锡林郭勒盟| 哈密市| 镶黄旗| 鄂州市| 崇左市| 军事| 鄂伦春自治旗| 东明县| 商丘市| 富顺县| 文昌市| 新余市| 旌德县|