Exemplo n.º 1
0
 private RaplaMenuItem createMenuItem(SaveableToggleAction action) throws RaplaException {
   RaplaMenuItem menu = new RaplaMenuItem(action.getName());
   menu.setAction(new ActionWrapper(action, getI18n(), raplaImages));
   final User user = getUser();
   final Preferences preferences = getQuery().getPreferences(user);
   boolean selected = preferences.getEntryAsBoolean(action.getConfigEntry(), true);
   if (selected) {
     menu.setSelected(true);
     menu.setIcon(raplaImages.getIconFromKey("icon.checked"));
   } else {
     menu.setSelected(false);
     menu.setIcon(raplaImages.getIconFromKey("icon.unchecked"));
   }
   return menu;
 }
Exemplo n.º 2
0
 private void service(RaplaContext context) throws RaplaException {
   this.context = context;
   i18n = context.lookup(RaplaResources.class);
   RaplaImages images = context.lookup(RaplaImages.class);
   if (useDefaultOptions) {
     if (buttons.length > 1) {
       getButton(0).setText(i18n.getString("ok"));
       getButton(1).setIcon(images.getIconFromKey("icon.abort"));
       getButton(1).setText(i18n.getString("abort"));
     } else {
       getButton(0).setText(i18n.getString("ok"));
     }
   }
   localeSelector = (ServerBundleManager) context.lookup(BundleManager.class);
   localeSelector.addLocaleChangeListener(this);
   frameList = context.lookup(FrameControllerList.class);
   frameList.add(this);
 }
Exemplo n.º 3
0
  private Action createOptionAction(final Preferences preferences) {
    AbstractAction action =
        new AbstractAction() {
          private static final long serialVersionUID = 1L;

          public void actionPerformed(ActionEvent arg0) {
            try {
              editController.edit(preferences, createPopupContext(getMainComponent(), null));
            } catch (RaplaException ex) {
              dialogUiFactory.showException(ex, new SwingPopupContext(getMainComponent(), null));
            }
          }
        };
    action.putValue(Action.SMALL_ICON, raplaImages.getIconFromKey("icon.options"));
    action.putValue(Action.NAME, getString("options"));
    return action;
  }
Exemplo n.º 4
0
  /**
   * the action to perform when someone clicks on the license entry in the help section of the menu
   * menubar
   *
   * <p>this method is a modified version of the existing method createInfoAction()
   */
  private Action createLicenseAction() {
    final String name = getString("licensedialog.title");
    final Icon icon = raplaImages.getIconFromKey("icon.info_small");

    // overwrite the cass AbstractAction to design our own
    AbstractAction action =
        new AbstractAction() {
          private static final long serialVersionUID = 1L;

          // overwrite the actionPerformed method that is called on click
          public void actionPerformed(ActionEvent e) {
            try {
              // we need a new instance of HTMLView to visualize the short
              // version of the license text including the two links
              HTMLView licenseText = new HTMLView();
              // giving the gui element some borders
              licenseText.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
              // we look up the text was originally meant for the welcome field
              // and put it into a new instance of RaplaWidget
              RaplaWidget welcomeField = licenseInfoUIProvider.get();
              // the following creates the dialog that pops up, when we click
              // on the license entry within the help section of the menu menubar
              // we call the create Method of the DialogUI class and give it all necessary things
              DialogInterface dialog =
                  dialogUiFactory.create(
                      new SwingPopupContext(getMainComponent(), null),
                      true,
                      new JScrollPane((Component) welcomeField.getComponent()),
                      new String[] {getString("ok")});
              // setting the dialog's title
              dialog.setTitle(name);
              // and the size of the popup window
              dialog.setSize(550, 250);
              // but I honestly have no clue what this startNoPack() does
              dialog.start(false);
            } catch (RaplaException ex) {
              dialogUiFactory.showException(ex, new SwingPopupContext(getMainComponent(), null));
            }
          }
        };

    action.putValue(Action.SMALL_ICON, icon);
    action.putValue(Action.NAME, name);
    return action;
  }
Exemplo n.º 5
0
  private Action createInfoAction() {
    final String name = getString("info");
    final Icon icon = raplaImages.getIconFromKey("icon.info_small");

    AbstractAction action =
        new AbstractAction() {
          private static final long serialVersionUID = 1L;

          public void actionPerformed(ActionEvent e) {
            try {
              HTMLView infoText = new HTMLView();
              infoText.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
              String javaversion;
              try {
                javaversion = System.getProperty("java.version");
              } catch (SecurityException ex) {
                javaversion = "-";
                getLogger().warn("Permission to system properties denied!");
              }

              String mainText = getI18n().infoText(javaversion);
              StringBuffer completeText = new StringBuffer();
              completeText.append(mainText);
              URL librariesURL = null;
              try {
                Enumeration<URL> resources =
                    ConfigTools.class.getClassLoader().getResources("META-INF/readme.txt");
                if (resources.hasMoreElements()) {
                  librariesURL = resources.nextElement();
                }
              } catch (IOException e1) {
              }
              if (librariesURL != null) {
                completeText.append("<pre>\n\n\n");
                BufferedReader bufferedReader = null;
                try {
                  bufferedReader =
                      new BufferedReader(new InputStreamReader(librariesURL.openStream()));
                  while (true) {
                    String line = bufferedReader.readLine();
                    if (line == null) {
                      break;
                    }
                    completeText.append(line);
                    completeText.append("\n");
                  }
                } catch (IOException ex) {
                  try {
                    if (bufferedReader != null) {
                      bufferedReader.close();
                    }
                  } catch (IOException e1) {
                  }
                }
                completeText.append("</pre>");
              }

              String body = completeText.toString();
              infoText.setBody(body);
              final JScrollPane content = new JScrollPane(infoText);
              DialogInterface dialog =
                  dialogUiFactory.create(
                      new SwingPopupContext(getMainComponent(), null),
                      false,
                      content,
                      new String[] {getString("ok")});
              dialog.setTitle(name);
              dialog.setSize(780, 580);
              dialog.start(false);

              SwingUtilities.invokeLater(
                  new Runnable() {
                    public void run() {
                      content.getViewport().setViewPosition(new Point(0, 0));
                    }
                  });
            } catch (RaplaException ex) {
              dialogUiFactory.showException(ex, new SwingPopupContext(getMainComponent(), null));
            }
          }
        };
    action.putValue(Action.SMALL_ICON, icon);
    action.putValue(Action.NAME, name);
    return action;
  }
Exemplo n.º 6
0
  @Inject
  public RaplaMenuBar(
      RaplaMenuBarContainer menuBarContainer,
      ClientFacade facade,
      RaplaResources i18n,
      RaplaLocale raplaLocale,
      Logger logger,
      PrintAction printAction,
      Set<AdminMenuExtension> adminMenuExt,
      Set<EditMenuExtension> editMenuExt,
      Set<ViewMenuExtension> viewMenuExt,
      Set<HelpMenuExtension> helpMenuExt,
      Set<ImportMenuExtension> importMenuExt,
      Set<ExportMenuExtension> exportMenuExt,
      MenuFactory menuFactory,
      EditController editController,
      CalendarSelectionModel model,
      UserClientService clientService,
      RestartServer restartServerService,
      RaplaImages raplaImages,
      DialogUiFactoryInterface dialogUiFactory,
      TemplateEditFactory templateEditFactory,
      Provider<LicenseInfoUI> licenseInfoUIProvider,
      ReservationEditFactory editFactory,
      ReservationController reservationController,
      // FIXME hack for initialization
      SwingActivityController activityController)
      throws RaplaException {
    super(facade, i18n, raplaLocale, logger);
    this.licenseInfoUIProvider = licenseInfoUIProvider;
    this.editController = editController;
    this.raplaImages = raplaImages;
    this.dialogUiFactory = dialogUiFactory;
    this.templateEditFactory = templateEditFactory;
    // TODO Hack to solve dependency Cycle
    ((MenuFactoryImpl) menuFactory).setEditController(editController);
    ((ReservationControllerImpl) reservationController).setEditFactory(editFactory);

    RaplaMenu editMenu = menuBarContainer.getEditMenu();
    RaplaMenu viewMenu = menuBarContainer.getViewMenu();
    RaplaMenu systemMenu = menuBarContainer.getSystemMenu();
    RaplaMenu adminMenu = menuBarContainer.getAdminMenu();
    RaplaMenu extraMenu = menuBarContainer.getExtraMenu();
    RaplaMenu importMenu = menuBarContainer.getImportMenu();
    RaplaMenu exportMenu = menuBarContainer.getExportMenu();

    if (getUser().isAdmin()) {
      addPluginExtensions(adminMenuExt, adminMenu);
    }
    addPluginExtensions(importMenuExt, importMenu);
    addPluginExtensions(exportMenuExt, exportMenu);
    addPluginExtensions(helpMenuExt, extraMenu);
    addPluginExtensions(viewMenuExt, viewMenu);
    addPluginExtensions(editMenuExt, editMenu);

    systemMenu.add(new JSeparator());

    JMenuItem printMenu = new JMenuItem(getString("print"));
    systemMenu.setMnemonic('F');
    printMenu.setAction(new ActionWrapper(printAction));
    printAction.setEnabled(true);
    printAction.setModel(model);
    systemMenu.add(printMenu);

    systemMenu.add(new JSeparator());

    if (clientService.canSwitchBack()) {
      JMenuItem switchBack = new JMenuItem();
      switchBack.setAction(
          new ActionWrapper(
              new UserAction(
                      getClientFacade(),
                      getI18n(),
                      getRaplaLocale(),
                      getLogger(),
                      null,
                      clientService,
                      editController,
                      raplaImages,
                      dialogUiFactory)
                  .setSwitchToUser()));
      adminMenu.add(switchBack);
    }

    boolean server = restartServerService.isRestartPossible();
    if (server && isAdmin()) {
      JMenuItem restartServer = new JMenuItem();
      restartServer.setAction(
          new ActionWrapper(
              new RestartServerAction(
                  getClientFacade(),
                  getI18n(),
                  getRaplaLocale(),
                  getLogger(),
                  restartServerService,
                  raplaImages)));
      adminMenu.add(restartServer);
    }

    Listener listener = new Listener();
    JMenuItem restart = new JMenuItem();
    restart.setAction(
        new ActionWrapper(
            new RestartRaplaAction(
                getClientFacade(),
                getI18n(),
                getRaplaLocale(),
                getLogger(),
                clientService,
                raplaImages)));
    systemMenu.add(restart);

    systemMenu.setMnemonic('F');
    exit = new JMenuItem(getString("exit"));
    exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
    exit.setMnemonic('x');
    exit.addActionListener(listener);
    systemMenu.add(exit);

    redo = new JMenuItem(getString("redo"));
    undo = new JMenuItem(getString("undo"));
    undo.setToolTipText(getString("undo"));
    undo.setIcon(raplaImages.getIconFromKey("icon.undo"));
    redo.addActionListener(listener);
    undo.addActionListener(listener);

    redo.setToolTipText(getString("redo"));
    redo.setIcon(raplaImages.getIconFromKey("icon.redo"));
    getModification().getCommandHistory().addCommandHistoryChangedListener(listener);

    undo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK));
    redo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, ActionEvent.CTRL_MASK));

    undo.setEnabled(false);
    redo.setEnabled(false);
    editMenu.insertBeforeId(undo, "EDIT_BEGIN");
    editMenu.insertBeforeId(redo, "EDIT_BEGIN");

    RaplaMenuItem userOptions = new RaplaMenuItem("userOptions");
    editMenu.add(userOptions);
    if (isTemplateEditAllowed(getUser())) {
      templateEdit = new RaplaMenuItem("template");
      updateTemplateText();
      templateEdit.addActionListener(listener);
      editMenu.add(templateEdit);
    }

    boolean modifyPreferencesAllowed = isModifyPreferencesAllowed();
    if (modifyPreferencesAllowed) {
      userOptions.setAction(createOptionAction(getQuery().getPreferences()));
    } else {
      userOptions.setVisible(false);
    }

    {
      SaveableToggleAction action =
          new SaveableToggleAction(
              getClientFacade(),
              getI18n(),
              getRaplaLocale(),
              getLogger(),
              "show_tips",
              RaplaBuilder.SHOW_TOOLTIP_CONFIG_ENTRY,
              dialogUiFactory);
      RaplaMenuItem menu = createMenuItem(action);
      viewMenu.insertBeforeId(menu, "view_save");
      action.setEnabled(modifyPreferencesAllowed);
    }
    {
      SaveableToggleAction action =
          new SaveableToggleAction(
              getClientFacade(),
              getI18n(),
              getRaplaLocale(),
              getLogger(),
              CalendarEditor.SHOW_CONFLICTS_MENU_ENTRY,
              CalendarEditor.SHOW_CONFLICTS_CONFIG_ENTRY,
              dialogUiFactory);
      RaplaMenuItem menu = createMenuItem(action);
      viewMenu.insertBeforeId(menu, "view_save");
      action.setEnabled(modifyPreferencesAllowed);
    }
    {
      SaveableToggleAction action =
          new SaveableToggleAction(
              getClientFacade(),
              getI18n(),
              getRaplaLocale(),
              getLogger(),
              CalendarEditor.SHOW_SELECTION_MENU_ENTRY,
              CalendarEditor.SHOW_SELECTION_CONFIG_ENTRY,
              dialogUiFactory);
      RaplaMenuItem menu = createMenuItem(action);
      viewMenu.insertBeforeId(menu, "view_save");
    }

    if (isAdmin()) {
      RaplaMenuItem adminOptions = new RaplaMenuItem("adminOptions");
      adminOptions.setAction(createOptionAction(getQuery().getSystemPreferences()));
      adminMenu.add(adminOptions);
    }

    RaplaMenuItem info = new RaplaMenuItem("info");
    info.setAction(createInfoAction());
    extraMenu.add(info);

    // within the help menu we need another point for the license
    RaplaMenuItem license = new RaplaMenuItem("license");
    // give this menu item an action to perform on click
    license.setAction(createLicenseAction());
    // add the license dialog below the info entry
    extraMenu.add(license);

    adminMenu.setEnabled(adminMenu.getMenuComponentCount() != 0);
    exportMenu.setEnabled(exportMenu.getMenuComponentCount() != 0);
    importMenu.setEnabled(importMenu.getMenuComponentCount() != 0);
    getUpdateModule().addModificationListener(listener);
  }
Exemplo n.º 7
0
 public Icon getIcon() {
   if (icon == null) {
     icon = RaplaImages.getIcon("/org/rapla/plugin/compactweekview/images/week_compact.png");
   }
   return icon;
 }
Exemplo n.º 8
0
 public Icon getIcon() {
   if (icon == null) {
     icon = RaplaImages.getIcon("/org/rapla/plugin/monthview/images/month.png");
   }
   return icon;
 }