View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.uruma.rcp.ui;
17  
18  import org.eclipse.jface.action.GroupMarker;
19  import org.eclipse.jface.action.IMenuManager;
20  import org.eclipse.jface.action.IStatusLineManager;
21  import org.eclipse.ui.IWorkbenchWindow;
22  import org.eclipse.ui.application.ActionBarAdvisor;
23  import org.eclipse.ui.application.IActionBarConfigurer;
24  import org.seasar.uruma.component.rcp.WorkbenchComponent;
25  import org.seasar.uruma.context.ContextFactory;
26  import org.seasar.uruma.context.WidgetHandle;
27  import org.seasar.uruma.core.UrumaConstants;
28  import org.seasar.uruma.rcp.util.UrumaServiceUtil;
29  
30  /**
31   * {@link WorkbenchComponent} の内容からメニューバーを構築するクラスです。<br />
32   * 
33   * @author y-komori
34   */
35  public class UrumaActionBarAdvisor extends ActionBarAdvisor {
36      private IActionBarConfigurer configurer;
37  
38      /**
39       * {@link UrumaActionBarAdvisor} を構築します。<br />
40       * 
41       * @param configurer
42       *            {@link IActionBarConfigurer} オブジェクト
43       */
44      public UrumaActionBarAdvisor(final IActionBarConfigurer configurer) {
45          super(configurer);
46          this.configurer = configurer;
47          UrumaServiceUtil.getService().getContainer().register(configurer);
48      }
49  
50      @Override
51      protected void fillMenuBar(final IMenuManager menuBar) {
52          GroupMarker marker = new GroupMarker("urumaMenu");
53          menuBar.add(marker);
54      }
55  
56      /*
57       * @see org.eclipse.ui.application.ActionBarAdvisor#fillMenuBar(org.eclipse.jface.action.IMenuManager)
58       */
59      // @Override
60      // protected void fillMenuBar(final IMenuManager menuBar) {
61      // WindowContext context = UrumaServiceUtil.getService()
62      // .getWorkbenchWindowContext();
63      //
64      // WorkbenchComponent workbench = UrumaServiceUtil.getService()
65      // .getWorkbenchComponent();
66      // WidgetHandle handle;
67      // if (StringUtil.isNotBlank(workbench.menu)) {
68      // handle = context.getWidgetHandle(workbench.menu);
69      // } else {
70      // return;
71      // }
72      //
73      // if (handle != null) {
74      // if (handle.instanceOf(MenuManager.class)) {
75      // MenuManager menuManager = handle.<MenuManager> getCastWidget();
76      // IContributionItem[] items = menuManager.getItems();
77      // for (int i = 0; i < items.length; i++) {
78      // menuBar.add(items[i]);
79      // }
80      //
81      // // ビューの表示アクションの作成
82      // // MenuManager showViewMenu = new MenuManager("ビューの表示(&V)");
83      // // showViewMenu.add(ContributionItemFactory.VIEWS_SHORTLIST
84      // // .create(configurer.getWindowConfigurer().getWindow()));
85      // // menuBar.add(showViewMenu);
86      // // 複数のウィンドウが開かれている場合にのみ表示され、
87      // // ウィンドウの切り替えを行うアクション
88      // // menu.add(ContributionItemFactory.OPEN_WINDOWS.create(window));
89      // } else {
90      // throw new RenderException(
91      // UrumaMessageCodes.UNSUPPORTED_TYPE_ERROR,
92      // workbench.menu, MenuManager.class.getName());
93      // }
94      // } else {
95      // throw new NotFoundException(
96      // UrumaMessageCodes.UICOMPONENT_NOT_FOUND, workbench.menu);
97      // }
98      //
99      // }
100     @Override
101     protected void fillStatusLine(final IStatusLineManager statusLine) {
102         // IStatusLineManager を WindowContext へ登録しておく
103         WorkbenchComponent workbench = UrumaServiceUtil.getService()
104                 .getWorkbenchComponent();
105 
106         if (Boolean.parseBoolean(workbench.statusLine)) {
107             WidgetHandle handle = ContextFactory.createWidgetHandle(statusLine);
108             handle.setId(UrumaConstants.STATUS_LINE_MANAGER_CID);
109 
110             UrumaServiceUtil.getService().getWorkbenchWindowContext()
111                     .putWidgetHandle(handle);
112         }
113     }
114 
115     /*
116      * @see org.eclipse.ui.application.ActionBarAdvisor#makeActions(org.eclipse.ui.IWorkbenchWindow)
117      */
118     @Override
119     protected void makeActions(final IWorkbenchWindow window) {
120         // do nothing
121     }
122 }