我愛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 兼聽則明 閱讀(600) 評論(0)  編輯  收藏 所屬分類: java

          主站蜘蛛池模板: 建德市| 深水埗区| 峨眉山市| 汨罗市| 海宁市| 那曲县| 屏南县| 黎平县| 台南市| 屯门区| 武山县| 雅江县| 沙坪坝区| 萨嘎县| 呼伦贝尔市| 甘南县| 南投市| 宜宾市| 晋宁县| 湘阴县| 天气| 崇左市| 固镇县| 蒙自县| 巴东县| 兴化市| 马龙县| 怀安县| 贺州市| 迁安市| 名山县| 台南市| 闸北区| 江陵县| 泸水县| 高州市| 彭州市| 汤阴县| 安宁市| 丰城市| 衡阳县|