我愛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

          主站蜘蛛池模板: 建瓯市| 长岛县| 竹山县| 瓮安县| 江津市| 石城县| 天全县| 偏关县| 广平县| 定州市| 阿克苏市| 武义县| 津南区| 宁夏| 顺昌县| 太原市| 南涧| 宜宾县| 武城县| 中西区| 师宗县| 婺源县| 宁河县| 安陆市| 巨鹿县| 沅江市| 志丹县| 阿拉善右旗| 巴马| 徐州市| 雅江县| 民乐县| 彰武县| 慈利县| 大悟县| 公安县| 安达市| 洮南市| 房山区| 涿鹿县| 铜川市|