Package org.eclipse.jface.internal.provisional.action

Examples of org.eclipse.jface.internal.provisional.action.ICoolBarManager2


    actionBars.removeRef();
    if (actionBars.getRef() <= 0) {
      String type = actionBars.getEditorType();
      actionCache.remove(type);
      // refresh the cool bar manager before disposing of a cool item
      ICoolBarManager2 coolBar = (ICoolBarManager2) window.getCoolBarManager2();
            if (coolBar != null) {
              coolBar.refresh();
      }
      actionBars.dispose();
    }
  }
View Full Code Here


    // Restore the cool bar order by creating all the tool bar contribution
    // items
    // This needs to be done before pages are created to ensure proper
    // canonical creation
    // of cool items
    final ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
        if (coolBarMgr != null) {
      IMemento coolBarMem = memento
          .getChild(IWorkbenchConstants.TAG_COOLBAR_LAYOUT);
      if (coolBarMem != null) {
        // Check if the layout is locked
        final Integer lockedInt = coolBarMem
            .getInteger(IWorkbenchConstants.TAG_LOCKED);
        StartupThreading.runWithoutExceptions(new StartupRunnable(){

          public void runWithException() {
            if ((lockedInt != null) && (lockedInt.intValue() == 1)) {
              coolBarMgr.setLockLayout(true);
            } else {
              coolBarMgr.setLockLayout(false);
            }
          }});
       
        // The new layout of the cool bar manager
        ArrayList coolBarLayout = new ArrayList();
        // Traverse through all the cool item in the memento
        IMemento contributionMems[] = coolBarMem
            .getChildren(IWorkbenchConstants.TAG_COOLITEM);
        for (int i = 0; i < contributionMems.length; i++) {
          IMemento contributionMem = contributionMems[i];
          String type = contributionMem
              .getString(IWorkbenchConstants.TAG_ITEM_TYPE);
          if (type == null) {
            // Do not recognize that type
            continue;
          }
          String id = contributionMem
              .getString(IWorkbenchConstants.TAG_ID);

          // Prevent duplicate items from being read back in.
          IContributionItem existingItem = coolBarMgr.find(id);
          if ((id != null) && (existingItem != null)) {
            if (Policy.DEBUG_TOOLBAR_DISPOSAL) {
              System.out
                  .println("Not loading duplicate cool bar item: " + id); //$NON-NLS-1$
            }
            coolBarLayout.add(existingItem);
            continue;
          }
          IContributionItem newItem = null;
          if (type.equals(IWorkbenchConstants.TAG_TYPE_SEPARATOR)) {
            if (id != null) {
              newItem = new Separator(id);
            } else {
              newItem = new Separator();
            }
          } else if (id != null) {
            if (type
                .equals(IWorkbenchConstants.TAG_TYPE_GROUPMARKER)) {
              newItem = new GroupMarker(id);

            } else if (type
                .equals(IWorkbenchConstants.TAG_TYPE_TOOLBARCONTRIBUTION)
                || type
                    .equals(IWorkbenchConstants.TAG_TYPE_PLACEHOLDER)) {

              // Get Width and height
              Integer width = contributionMem
                  .getInteger(IWorkbenchConstants.TAG_ITEM_X);
              Integer height = contributionMem
                  .getInteger(IWorkbenchConstants.TAG_ITEM_Y);
              // Look for the object in the current cool bar
              // manager
              IContributionItem oldItem = coolBarMgr.find(id);
              // If a tool bar contribution item already exists
              // for this id then use the old object
              if (oldItem != null) {
                newItem = oldItem;
              } else {
                IActionBarPresentationFactory actionBarPresentation = getActionBarPresentationFactory();
                newItem = actionBarPresentation.createToolBarContributionItem(
                    actionBarPresentation.createToolBarManager(), id);
                if (type
                    .equals(IWorkbenchConstants.TAG_TYPE_PLACEHOLDER)) {
                  IToolBarContributionItem newToolBarItem = (IToolBarContributionItem) newItem;
                  if (height != null) {
                    newToolBarItem.setCurrentHeight(height
                        .intValue());
                  }
                  if (width != null) {
                    newToolBarItem.setCurrentWidth(width
                        .intValue());
                  }
                  newItem = new PlaceholderContributionItem(
                      newToolBarItem);
                }
                // make it invisible by default
                newItem.setVisible(false);
                // Need to add the item to the cool bar manager
                // so that its canonical order can be preserved
                IContributionItem refItem = findAlphabeticalOrder(
                    IWorkbenchActionConstants.MB_ADDITIONS,
                    id, coolBarMgr);
                if (refItem != null) {
                  coolBarMgr.insertAfter(refItem.getId(),
                      newItem);
                } else {
                  coolBarMgr.add(newItem);
                }
              }
              // Set the current height and width
              if ((width != null)
                  && (newItem instanceof IToolBarContributionItem)) {
                ((IToolBarContributionItem) newItem)
                    .setCurrentWidth(width.intValue());
              }
              if ((height != null)
                  && (newItem instanceof IToolBarContributionItem)) {
                ((IToolBarContributionItem) newItem)
                    .setCurrentHeight(height.intValue());
              }
            }
          }
          // Add new item into cool bar manager
          if (newItem != null) {
            coolBarLayout.add(newItem);
            newItem.setParent(coolBarMgr);
            coolBarMgr.markDirty();
          }
        }

        // We need to check if we have everything we need in the layout.
        final ArrayList finalLayout = new ArrayList();
        IContributionItem[] existingItems = coolBarMgr.getItems();
        for (int i = 0; i < existingItems.length; i++) {
          IContributionItem existingItem = existingItems[i];

          /*
           * This line shouldn't be necessary, but is here for
           * robustness.
           */
          if (existingItem == null) {
            continue;
          }

          boolean found = false;
          Iterator layoutItemItr = coolBarLayout.iterator();
          while (layoutItemItr.hasNext()) {
            IContributionItem layoutItem = (IContributionItem) layoutItemItr
                .next();
            if ((layoutItem != null)
                && (layoutItem.equals(existingItem))) {
              found = true;
              break;
            }
          }

          if (!found) {
            if (existingItem != null) {
              finalLayout.add(existingItem);
            }
          }
        }

        // Set the cool bar layout to the given layout.
        finalLayout.addAll(coolBarLayout);
        final IContributionItem[] itemsToSet = new IContributionItem[finalLayout
            .size()];
        finalLayout.toArray(itemsToSet);
        StartupThreading.runWithoutExceptions(new StartupRunnable() {

          public void runWithException() {
            coolBarMgr.setItems(itemsToSet);
          }});
       
      } else {
        // For older workbenchs
        coolBarMem = memento
View Full Code Here

  private boolean restoreOldCoolBar(IMemento coolbarMem) {
    // Make sure the tag exist
    if (coolbarMem == null) {
      return false;
    }
        ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
    // Check to see if layout is locked
    Integer locked = coolbarMem.getInteger(IWorkbenchConstants.TAG_LOCKED);
    boolean state = (locked != null) && (locked.intValue() == 1);
    coolBarMgr.setLockLayout(state);

    // Get the visual layout
    IMemento visibleLayout = coolbarMem
        .getChild(IWorkbenchConstants.TAG_TOOLBAR_LAYOUT);
    ArrayList visibleWrapIndicies = new ArrayList();
    ArrayList visibleItems = new ArrayList();
    if (visibleLayout != null) {
      if (readLayout(visibleLayout, visibleItems, visibleWrapIndicies) == false) {
        return false;
      }
    }
    // Get the remembered layout
    IMemento rememberedLayout = coolbarMem
        .getChild(IWorkbenchConstants.TAG_LAYOUT);
    ArrayList rememberedWrapIndicies = new ArrayList();
    ArrayList rememberedItems = new ArrayList();
    if (rememberedLayout != null) {
      if (readLayout(rememberedLayout, rememberedItems,
          rememberedWrapIndicies) == false) {
        return false;
      }
    }

    // Create the objects
    if (visibleItems != null) {
      // Merge remembered layout into visible layout
      if (rememberedItems != null) {
        // Traverse through all the remembered items
        int currentIndex = 0;
        for (Iterator i = rememberedItems.iterator(); i.hasNext(); currentIndex++) {
          String id = (String) i.next();
          int index = -1;
          for (Iterator iter = visibleItems.iterator(); iter
              .hasNext();) {
            String visibleId = (String) iter.next();
            if (visibleId.equals(id)) {
              index = visibleItems.indexOf(visibleId);
              break;
            }
          }
          // The item is not in the visible list
          if (index == -1) {
            int insertAt = Math.max(0, Math.min(currentIndex,
                visibleItems.size()));
            boolean separateLine = false;
            // Check whether this item is on a separate line
            for (Iterator iter = rememberedWrapIndicies.iterator(); iter
                .hasNext();) {
              Integer wrapIndex = (Integer) iter.next();
              if (wrapIndex.intValue() <= insertAt) {
                insertAt = visibleItems.size();
                // Add new wrap index for this Item
                visibleWrapIndicies.add(new Integer(insertAt));
                separateLine = true;
              }
            }
            // Add item to array list
            visibleItems.add(insertAt, id);
            // If the item was not on a separate line then adjust
            // the visible wrap indicies
            if (!separateLine) {
              // Adjust visible wrap indicies
              for (int j = 0; j < visibleWrapIndicies.size(); j++) {
                Integer index2 = (Integer) visibleWrapIndicies
                    .get(j);
                if (index2.intValue() >= insertAt) {
                  visibleWrapIndicies.set(j, new Integer(
                      index2.intValue() + 1));
                }
              }
            }
          }
        }
      }
      // The new layout of the cool bar manager
      ArrayList coolBarLayout = new ArrayList(visibleItems.size());
      // Add all visible items to the layout object
      for (Iterator i = visibleItems.iterator(); i.hasNext();) {
        String id = (String) i.next();
        // Look for the object in the current cool bar manager
        IContributionItem oldItem = null;
        IContributionItem newItem = null;
        if (id != null) {
          oldItem = coolBarMgr.find(id);
        }
        // If a tool bar contribution item already exists for this id
        // then use the old object
        if (oldItem instanceof IToolBarContributionItem) {
          newItem = oldItem;
        } else {
          IActionBarPresentationFactory actionBarPresentaiton = getActionBarPresentationFactory();
          newItem = actionBarPresentaiton.createToolBarContributionItem(
                  actionBarPresentaiton.createToolBarManager(), id);
          // make it invisible by default
          newItem.setVisible(false);
          // Need to add the item to the cool bar manager so that its
          // canonical order can be preserved
          IContributionItem refItem = findAlphabeticalOrder(
              IWorkbenchActionConstants.MB_ADDITIONS, id,
              coolBarMgr);
          if (refItem != null) {
            coolBarMgr.insertAfter(refItem.getId(), newItem);
          } else {
            coolBarMgr.add(newItem);
          }
        }
        // Add new item into cool bar manager
        if (newItem != null) {
          coolBarLayout.add(newItem);
          newItem.setParent(coolBarMgr);
          coolBarMgr.markDirty();
        }
      }

      // Add separators to the displayed Items data structure
      int offset = 0;
      for (int i = 1; i < visibleWrapIndicies.size(); i++) {
        int insertAt = ((Integer) visibleWrapIndicies.get(i))
            .intValue()
            + offset;
        coolBarLayout.add(insertAt, new Separator(
            CoolBarManager.USER_SEPARATOR));
        offset++;
      }

      // Add any group markers in their appropriate places
      IContributionItem[] items = coolBarMgr.getItems();
      for (int i = 0; i < items.length; i++) {
        IContributionItem item = items[i];
        if (item.isGroupMarker()) {
          coolBarLayout.add(Math.max(Math
              .min(i, coolBarLayout.size()), 0), item);
        }
      }
      IContributionItem[] itemsToSet = new IContributionItem[coolBarLayout
          .size()];
      coolBarLayout.toArray(itemsToSet);
      coolBarMgr.setItems(itemsToSet);
    }
    return true;
  }
View Full Code Here

    if (perspectiveSwitcher != null) {
      perspectiveSwitcher.saveState(persBarMem);
    }

    // / Save the order of the cool bar contribution items
        ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
        if (coolBarMgr != null) {
          coolBarMgr.refresh();
      IMemento coolBarMem = memento
          .createChild(IWorkbenchConstants.TAG_COOLBAR_LAYOUT);
            if (coolBarMgr.getLockLayout() == true) {
        coolBarMem.putInteger(IWorkbenchConstants.TAG_LOCKED, 1);
      } else {
        coolBarMem.putInteger(IWorkbenchConstants.TAG_LOCKED, 0);
      }
            IContributionItem[] items = coolBarMgr.getItems();
      for (int i = 0; i < items.length; i++) {
        IMemento coolItemMem = coolBarMem
            .createChild(IWorkbenchConstants.TAG_COOLITEM);
        IContributionItem item = items[i];
        // The id of the contribution item
View Full Code Here

    WorkbenchPage currentPage = getActiveWorkbenchPage();
    if (currentPage == null) {
      getActionPresentation().clearActionSets();
    } else {
      ICoolBarManager2 coolBarManager = (ICoolBarManager2) getCoolBarManager2();
      if (coolBarManager != null) {
        coolBarManager.refresh();
      }
      getActionPresentation().setActionSets(
          currentPage.getActionSets());
    }
    fireActionSetsChanged();
View Full Code Here

     */
    public void resetPerspective() {
        // Run op in busy cursor.
        // Use set redraw to eliminate the "flash" that can occur in the
        // coolbar as the perspective is reset.
        ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2();
        try {
            mgr.getControl2().setRedraw(false);
            BusyIndicator.showWhile(null, new Runnable() {
                public void run() {
                    busyResetPerspective();
                }
            });
        } finally {
            mgr.getControl2().setRedraw(true);
        }
    }
View Full Code Here

        return;
      }
        // Going from multiple to single rows can make the coolbar
        // and its adjacent views appear jumpy as perspectives are
        // switched. Turn off redraw to help with this.
        ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2();
        try {
            mgr.getControl2().setRedraw(false);
            getClientComposite().setRedraw(false);
            // Run op in busy cursor.
            BusyIndicator.showWhile(null, new Runnable() {
                public void run() {
                    busySetPerspective(desc);
                }
            });
        } finally {
            getClientComposite().setRedraw(true);
            mgr.getControl2().setRedraw(true);
            IWorkbenchPart part = getActivePart();
            if (part != null) {
        part.setFocus();
      }
        }
View Full Code Here

    /**
     * Restore the toolbar layout for the active perspective.
     */
    protected void resetToolBarLayout() {
      ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2();
      mgr.resetItemOrder();
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jface.internal.provisional.action.ICoolBarManager2

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.