我愛oo,我愛java

          交流blog QQ:421057986 oofrank@donews

          在eclipse-plugin開發中碰到的怪問題:(eclipse 3.1.1 + wtp1.0)

          一個popupMenus Extensions,
          objectContribution:objectClass*: org.eclipse.core.resources.IFile

          在action的Class代碼中:
          public void selectionChanged(IAction action, ISelection selection) {
              StructuredSelection ss = (StructuredSelection) selection;
                  this.selectedFile==(IFile)ss.getFirstElement(); //此處拋出異常
          }

          上述代碼的異常非常奇怪:
          根據的的跟蹤,ss.getFirstElement()返回值是File,該類實現了IFile接口,
          而且我用 ss.getFirstElement().getClass().isAssignableFrom(IFile.class)返回是false;
          真是奇怪!---有人知道為什么嗎?

          另外在實踐eclipse plugin開發過程中也有幾個心得:(肯定能用,但未必最佳)

          1、如果開發plugin,所有的依賴庫都要包含到 Plug-in Dependencies 中;而不能只是引入到工程中。
          2、如何輸出到console:
          MessageConsole mc=new MessageConsole("****",null);
          IConsole[] cs=new IConsole[1];
          cs[0]=mc;
          ConsolePlugin.getDefault().getConsoleManager().addConsoles(cs);
          mc.activate();
          PrintStream out=new PrintStream( mc.newOutputStream());
          out.println("*******.");
          3、如何獲取依賴工程的輸出路徑:
          selectedProject:當前工程---由用戶選擇
          String[] ps= selectedProject.getRequiredProjectNames();                
          IWorkspace w= selectedProject.getProject().getWorkspace();
          for(int i=0;i<ps.length;i++){
          IResource r=w.getRoot().findMember(ps[i]);
          try{
              IJavaProject jp=new JavaProject((IProject)r,null);                
              File source=new File(jp.getProject().getLocation().append(jp.getOutputLocation().removeFirstSegments(1)).toOSString());
                  //作你的事情.....
          }catch(Exception e){
                //不是javaProject                                
              e.printStackTrace();                            
          }                
          4、如何使用進度Dialog:
          Shell shell = new Shell();
          ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);        
          IRunnableWithProgress thread = new SomeRunner(shell);            
          dialog.run(true, false, thread);
          //=============================
          private class SomeRunner implements IRunnableWithProgress {
              public void run(IProgressMonitor monitor)throws InvocationTargetException, InterruptedException {
              monitor.beginTask("一些信息", 數值-總工作量);
                  for(;;){
                  // 一些工作
                  monitor.worked(數值-已完成工作量); //實際中,我得情況不太相符,不明白,但差不多 :(
                  monitor.setTaskName("一些信息");
               // 一些工作    
                 }
                  monitor.done();
              }
          }


          posted on 2006-01-20 18:45 兼聽則明 閱讀(603) 評論(0)  編輯  收藏 所屬分類: java

          主站蜘蛛池模板: 即墨市| 垣曲县| 海门市| 永寿县| 怀宁县| 宜兰市| 如东县| 庄浪县| 永安市| 仙游县| 万州区| 商水县| 大丰市| 奉新县| 漳浦县| 四子王旗| 牡丹江市| 图片| 无锡市| 溧水县| 广平县| 宣武区| 弥勒县| 黑龙江省| 塔城市| 夏河县| 于都县| 桐乡市| 左贡县| 正定县| 阳东县| 平陆县| 金沙县| 通江县| 乡宁县| 巍山| 奇台县| 林口县| 土默特右旗| 治县。| 永宁县|