隨筆 - 6  文章 - 129  trackbacks - 0
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(14)

          隨筆檔案(6)

          文章分類(467)

          文章檔案(423)

          相冊

          收藏夾(18)

          JAVA

          搜索

          •  

          積分與排名

          • 積分 - 828785
          • 排名 - 49

          最新評論

          閱讀排行榜

          評論排行榜

          一、同時關閉所有打開的view 
           
          在view中,只有一個close,每次只能關閉當前窗口
          在eclipse的編輯窗口的標題上點右鍵,里面有 close All
          可以使用遍歷的方法,遍歷所有打開的View,然后將其隱藏:
          AsyncUtil.asyncExec(new Runnable()
          {
                 public void run()
                 {
                       IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                       IViewReference[] iViewReferences = page.getViewReferences();
                       for (IViewReference iViewReference: iViewReferences)
                            if (!ID.equals(iViewReference.getId()))
                                 page.hideView(iViewReference);
                  }
          });   
            二、RCP中產生目標區的Bar 
           
          產生紅線區域的Bar,實現方法如下:
          1、這個是perspective,要創建多個perspective,然后設置某個為active
          2、在WorkbenchWindowAdvisor中preWindowOpen內,加下面這段代碼
          public void preWindowOpen() { 
                  IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore();
                  apiStore.setValue(IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR,
                          IWorkbenchPreferenceConstants.TOP_RIGHT);
                  apiStore.setValue(
                          IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
                          false);
           }
          3、需要加 config.setShowPespectivebar(true); 
          三、RCP項目--窗口關閉事件 
          在ApplicationWorkbenchWindowAdvisor中override
          public boolean preWindowShellClose() {
                  // do nothing, but allow the close() to proceed
                  MessageBox msgBox = new MessageBox(new Shell(), SWT.YES|SWT.NO|SWT.ICON_QUESTION);
                  msgBox.setText("退出系統");
                  msgBox.setMessage("確定退出系統?");
                  if(msgBox.open()==SWT.YES){
                      return true;
                  }
                  return false;
              }
          以后使用IWorkbenchWindow的getShell().close();都會調用該處代碼.  
          四、在RCP中設計界面適合桌面大小 
           
          final int screenWidth = Display.getCurrent().getBounds().width;
          final int screenHeight = Display.getCurrent().getBounds().height;
           
          五、Treeviewer中通過代碼,選中樹上的某個node節點 
          StructuredSelection sel=new StructuredSelection(node);
           tree.setSelected(sel); 
          六、TreeViewer實現雙擊展開、關閉 
          private class DoubleEventPro implements MouseListener {
                  public void mouseDoubleClick(MouseEvent e) {
                      TreeItem item = viewer.getTree().getItem(new Point(e.x, e.y));

                      if (item != null && item.getItem(0).getText().trim().length() == 0) {
                          viewer.expandToLevel(item.getData(), 1);
                          return;
                      }

                      if (item != null && item.getItemCount() > 0
                              && item.getItem(0).getText().trim().length() > 0) {
                          item.setExpanded(!item.getExpanded());
                      }
                  }

                  public void mouseDown(MouseEvent e) {
                  }
                  public void mouseUp(MouseEvent e) {

                  }
              } 
          七、 如何屏蔽掉視圖窗口上的右鍵彈出菜單?


          方法一:在 postWindowOpen() 中執行下面語句:
          PlatformUI.getWorkbench().getDisplay().addFilter(SWT.MouseUp, new Listener() {
              public void handleEvent(final Event event) {
                  if(event.widget == your editor && event.button == 3) {
                      int hwndCursor = OS.GetCapture ();
                      OS.PostMessage(hwndCursor, OS.WM_LBUTTONDOWN, hwndCursor, OS.HTCLIENT | (OS.WM_MOUSEMOVE << 16));
                  }
              }
          });

          其它:org.eclipse.ui.internal.presentations.util包中的StandardViewSystemMenu類控制著這些菜單,還沒來得急仔細研究,研究過后再補充

          八、在使用tableviewer的時候導入大量數據的問題

          創建了一個tableviewer,然后使用setInput方法導入數據,如果數據量很大的話根本就無效率可言了,以下是幾種解決的方法:

          方法一:通過移動滾動條來達到自動加載的目的,在滾動條的事件中加入翻頁的代碼,可以參考《Eclipse從入門到精通》第二版的P383

          方法二:分頁顯示(http://www.eclipseworld.org/bbs/read-cec-tid-11678-keyword-table.html

          方法三:使用 Virtual Tables,JFace3.2的Viewer已經支持SWT.VIRTUAL樣式
          http://www.eclipse.org/articles/Article-SWT-Virtual/Virtual-in-SWT.html

          1 int COUNT = 10000;
          2 final String [] itemStrings = new String [COUNT];
          3 for (int i = 0; i < COUNT; i++) {
          4   itemStrings = "item " + i;
          5 }
          6 final Table table = new Table(parent, SWT.BORDER | SWT.VIRTUAL);
          7 table.addListener(SWT.SetData, new Listener() {
          8   public void handleEvent(Event event) {
          9     TableItem item = (TableItem)event.item;
          10     int index = event.index;
          11     item.setText(itemStrings [index]);
          12   }
          13 });
          14 table.setItemCount(COUNT);

          九、在透視圖快捷方式欄中同時顯示多個透視圖快捷方式

          如果在程序中做了多個個透視圖,默認只顯示初始透視圖快捷方式,每次都要 打開透視圖——other,特麻煩,所以,一下提供兩種方法:

          1、在切換欄中顯示
          public class PIMWorkbenchAdvisor extends WorkbenchAdvisor {
              @Override
              public void postStartup() {
                  super.postStartup();
                  IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                  //2007.01.11 設置同時顯示多個透視圖標
                  PerspectiveBarManager barManager=((WorkbenchWindow)activeWorkbenchWindow).getPerspectiveBar();
                  if(barManager != null){
                      IPerspectiveDescriptor mailPerspective = WorkbenchPlugin.getDefault().getPerspectiveRegistry   ().findPerspectiveWithId("MyWork_mail.perspective");
                      PerspectiveBarContributionItem item=new PerspectiveBarContributionItem(mailPerspective,activeWorkbenchWindow.getActivePage());
                      barManager.addItem(item);
                  }
          }
          2、在下拉框中(shortcut)顯示
          public class UiPerspective implements IPerspectiveFactory
          {
              public void createInitialLayout(IPageLayout layout){
          ....
                  //增加透視圖
                  layout.addPerspectiveShortcut("net.sf.pim.plugin.UiPerspective");
                  layout.addPerspectiveShortcut("MyWork_mail.perspective");
                 }
          }
          十、控制“最近打開文檔”的個數
                 RCP中在繼承ActionBarAdvisor的類中定義:
                 private IContributionItem reOpenAction = ContributionItemFactory.REOPEN_EDITORS.create(window);
                 然后在fillMenuBar(IMenuManager menuBar)方法中添加上面的aciton
                 運行時“最近打開的文檔”只有4個,如果想自己控制“最近打開的文檔”的數量,則設置一下Workbench中的初始化首選項時RECENT_FILES的默認參數值如:
          WorkbenchPlugin.getDefault().getPreferenceStore().setDefault(IPreferenceConstants.RECENT_FILES,10);

          十一、設置Eclipse RCP程序的外觀和首選項
                 RCP應用程序的缺省外觀是一個空白窗口,一般我們要通過一個WorkbenchAdvisor類對界面進行定制。 WorkbenchAdvisor有很多回調方法,可以在preWindowOpen()方法里設置菜單、工具條、狀態欄、進度欄、透視圖切換工具是否可 見,在fillActionBars()方法里添加菜單和工具條項,在getInitialWindowPerspectiveId()方法里指定首選的 透視圖。

                 缺省情況下,透視圖切換工具位于窗口左上角,在Eclipse里可以通過Window->Preferences-> Workbench->Appearance改變它的位置,那么怎樣用程序控制它呢?有兩個方法,第一個是使用如下代碼設置 IPreferenceStore中的變量:

          IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore();
          apiStore.setValue(IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR, IWorkbenchPreferenceConstants.TOP_RIGHT);
          另一個方法是在plugin所在目錄建一個名為plugin_customization.ini的文件,里面寫如下內容:

          your.plugin.id/DOCK_PERSPECTIVE_BAR=topRight
          其他與plugin相關的Preference值可以用同樣方法設置。

          Update:在最新的Eclipse 3.1M5a版本中,對RCP應用程序菜單和工具條的定制方法有所改變,應該使用新加入的ActionBarAdvisor類來完成此項工作。

          十二、獲得自己開發的plugin被安裝的目錄
            /** *//**
               * @return 本插件的安裝路徑
               */
              public String getInstallDir() ...{
                  if (installPath == null) ...{
                      URL localUrl = null;
                      try ...{
                          localUrl = FileLocator.toFileURL(getDefault().getBundle()
                                  .getEntry("/"));
                          installPath = localUrl.getFile().substring(1);
                      } catch (Exception e) ...{
                          log(e);
                      }
                  }
                  return installPath;
              }

          轉自http://duguanglong002.blog.163.com/blog/static/26955626200955415545/



          posted on 2009-07-27 13:46 Ke 閱讀(2297) 評論(0)  編輯  收藏 所屬分類: eclipse RCP
          主站蜘蛛池模板: 抚顺市| 靖边县| 汕头市| 永善县| 墨玉县| 双峰县| 牟定县| 台湾省| 泗洪县| 永城市| 西峡县| 定南县| 山东省| 兴城市| 隆德县| 色达县| 荆门市| 利川市| 尚志市| 三江| 河西区| 宁南县| 长葛市| 台南市| 汝南县| 南涧| 南澳县| 湾仔区| 宿迁市| 长寿区| 图木舒克市| 庆阳市| 庆元县| 三台县| 莎车县| 长治市| 阜城县| 财经| 彭阳县| 宝坻区| 疏附县|