Пример #1
0
 /** Does the actual reload of Main Menu */
 private void doReload(final boolean canWait) {
   if (menu.getDisplay().isDisposed()) {
     log.warn("Menu disposed - won't reload");
     return;
   }
   menu.getDisplay()
       .asyncExec(
           new Runnable() {
             public void run() {
               try {
                 if (canWait) {
                   if (hiddenSince == -1) {
                     log.debug("Skipping planned reload as it was forced a while ago.");
                     return;
                   }
                   if (hiddenSince == 0L) {
                     log.debug("Menu now open, reload skipped");
                     isReloading = false;
                     return;
                   } else if (System.currentTimeMillis() - hiddenSince
                       < cfg.getMenuReloadDelay()) {
                     // menu is actively used, try reloading later
                     if (log.isDebugEnabled()) {
                       log.debug(
                           "Reloading later, menu is not sleeping "
                               + "long enough: ("
                               + ((System.currentTimeMillis() - hiddenSince) / 1000.0)
                               + " seconds)");
                     }
                     isReloading = false;
                     reloadMenu(true);
                     return;
                   }
                 } else {
                   // way of telling other reloader threads to stay the f*** away :)
                   hiddenSince = -1;
                 }
                 clearMenu();
                 loadMenu();
                 Runtime.getRuntime().gc();
               } catch (final Exception e) {
                 log.debug("Failed reloading menu", e);
               }
               isReloading = false;
               hiddenSince = System.currentTimeMillis();
               enqueueIdleReload();
             }
           });
 }
  private void showStandaloneViewMenu(
      ExecutionEvent event, MPart model, MMenu menuModel, Composite partContainer) {
    Shell shell = partContainer.getShell();
    Menu menu = (Menu) menuModel.getWidget();
    if (menu == null) {
      IPresentationEngine engine =
          (IPresentationEngine) HandlerUtil.getVariable(event, IPresentationEngine.class.getName());
      menu = (Menu) engine.createGui(menuModel, shell, model.getContext());
      if (menu != null) {
        final Menu tmpMenu = menu;
        partContainer.addDisposeListener(
            new DisposeListener() {
              public void widgetDisposed(DisposeEvent e) {
                tmpMenu.dispose();
              }
            });
      }
    }

    Display display = menu.getDisplay();
    Point location = display.map(partContainer, null, partContainer.getLocation());
    Point size = partContainer.getSize();
    menu.setLocation(location.x + size.x, location.y);
    menu.setVisible(true);

    while (!menu.isDisposed() && menu.isVisible()) {
      if (!display.readAndDispatch()) display.sleep();
    }

    if (!(menu.getData() instanceof MenuManager)) {
      menu.dispose();
    }
  }
Пример #3
0
  public static void setVisiable(ActionContext actionContext) throws OgnlException {
    Thing self = (Thing) actionContext.get("self");

    String method = self.getString("method");
    if (method == null || "".equals(method)) {
      method = "enable";
    }

    String controlList = self.getString("controlList");
    if (controlList == null || "".equals(controlList)) {
      return;
    }

    for (String controlName : controlList.split("[,]")) {
      Object c = Ognl.getValue(controlName, actionContext);
      if (c instanceof Control) {
        final Control control = (Control) c;
        if (control != null) {
          final String m = method;
          control
              .getDisplay()
              .asyncExec(
                  new Runnable() {
                    public void run() {
                      if ("true".equals(m)) {
                        control.setVisible(true);
                      } else if ("false".equals(m)) {
                        control.setVisible(false);
                      } else if ("reverse".equals(m)) {
                        control.setVisible(!control.getEnabled());
                      }
                    }
                  });
        }
      } else if (c instanceof Menu) {
        final Menu item = (Menu) c;
        final String m = method;
        item.getDisplay()
            .asyncExec(
                new Runnable() {
                  public void run() {
                    if ("true".equals(m)) {
                      item.setVisible(true);
                    } else if ("false".equals(m)) {
                      item.setVisible(false);
                    } else if ("reverse".equals(m)) {
                      item.setVisible(!item.getEnabled());
                    }
                  }
                });
      }
    }
  }