示例#1
0
 @Override
 public void insert(Portlet portlet, int index, int column) {
   int portletId = nextPortalId++;
   if (reinsert(portlet, index, column, portletId)) {
     if (portlet instanceof AppPortlet) {
       AppPortlet appPortlet = (AppPortlet) portlet;
       appPortlet.registerUserPortlet(portletId, index, column);
     }
     scrollToPortlet(portlet);
   }
 }
示例#2
0
 @Override
 public void refreshAllPortletStates() {
   for (int col = 0; col < portletTabs.size(); col++) {
     List<TabItem> list = new ArrayList<TabItem>(portletTabs.get(col));
     for (int row = 0; row < list.size(); row++) {
       TabItem tab = list.get(row);
       if (tab.getItemCount() > 0 && tab.getItem(0) instanceof AppPortlet) {
         AppPortlet appPortlet = (AppPortlet) tab.getItem(0);
         appPortlet.updateUserPortlet(row, col);
       }
     }
   }
 }
示例#3
0
  @Override
  public Portlet getByIdentity(String identity) {
    if (identity == null) return null;

    for (List<TabItem> tabs : portletTabs) {
      for (TabItem tab : tabs) {
        for (Component component : tab.getItems()) {
          if (component instanceof AppPortlet) {
            AppPortlet appPortlet = (AppPortlet) component;
            if (identity.equals(appPortlet.getPortletIdentity())) return appPortlet;
          }
        }
      }
    }

    return null;
  }
示例#4
0
  @Override
  public void close(Portlet portlet) {
    TabItem tab = getTab(portlet);
    if (tab != null) {
      if (tab.getTabPanel() != null) tab.close();

      //	Take the tab out of the list of tabs
      for (List<TabItem> column : portletTabs) {
        for (TabItem targetTab : column) {
          if (tab.hashCode() == targetTab.hashCode()) {
            column.remove(targetTab);
            break;
          }
        }
      }
    }

    //	Make sure the portlet is out of the tab itself
    if (portlet.getParent() != null) portlet.removeFromParent();

    //	Update the portlet as "closed" in the user cache
    if (portlet instanceof AppPortlet) ((AppPortlet) portlet).updateUserPortlet();
  }
示例#5
0
  @Override
  public boolean reinsert(Portlet portlet, int index, int column, int portletId) {
    //	Do any AppPortlet specific tasks
    if (portlet instanceof AppPortlet) {
      AppPortlet appPortlet = (AppPortlet) portlet;
      //	Make sure there's not already a duplicate portlet, and if so, don't add this one, just jump
      // to that one
      AppPortlet existingPortlet = (AppPortlet) getByIdentity(appPortlet.getPortletIdentity());
      if (existingPortlet != null && !existingPortlet.allowDuplicatePortlets()) {
        scrollToPortlet(existingPortlet);
        return false;
      }
      //	Otherwise, set the id and stuff
      appPortlet.setPortletId(portletId);
      appPortlet.setPresenter(this);
    }

    if (index < 0) index = 0;
    if (column < 0) column = 0;

    //	Get the tab we'll add (with the portlet in it)
    TabItem tab = getNewPortletTab(portlet, index, column);

    //	Create all the columns we need
    while (portletTabs.size() <= column) {
      portletTabs.add(new ArrayList<TabItem>());
    }

    //	Get the column we'll add to
    List<TabItem> tabColumn = portletTabs.get(column);

    //	Now we'll add the tab to the proper column, and to the display

    //	If this is at the end of the column, the tab has to go before the first item in the next
    // column
    if (index >= tabColumn.size()) {
      //	Append to end of the column
      tabColumn.add(tab);

      //	Find the next actual tab item
      TabItem nextTab = null;
      int nextColumn = column + 1;

      while (nextTab == null && nextColumn < portletTabs.size()) {
        //	Insert before first tab in next column
        List<TabItem> nextTabColumn = portletTabs.get(nextColumn);
        nextColumn++;
        if (nextTabColumn.size() > 0) {
          nextTab = nextTabColumn.get(0);
          break;
        }
      }

      //	Add the tab
      if (nextTab == null) {
        //	No next column, just add to end
        tabPanel.add(tab);
      } else {
        tabPanel.insert(tab, tabPanel.indexOf(nextTab));
      }
    } else {
      //	Insert before the specified tab in this column
      TabItem beforeTab = tabColumn.get(index);
      if (beforeTab != null) {
        tabColumn.add(index, tab);
        int tabIndex = tabPanel.indexOf(beforeTab);
        if (tabIndex < 0) tabIndex = 0;
        tabPanel.insert(tab, tabIndex);
      } else {
        tabColumn.add(0, tab);
        tabPanel.insert(tab, 0);
      }
    }

    //	Lastly, set the row and column for the portlet, and fix the local next portlet ID
    if (portlet instanceof AppPortlet) {
      AppPortlet appPortlet = (AppPortlet) portlet;

      // Set the tooltip for the tab
      tab.getHeader().setToolTip(appPortlet.getPresenterToolTip());
      //	appPortlet.registerUserPortlet(appPortlet.getPortletId(), index, column);
      appPortlet.setPortalColumn(column);
      appPortlet.setPortalRow(index);
      if (appPortlet.getPortletId() >= nextPortalId) nextPortalId = appPortlet.getPortletId() + 1;
    }

    return true;
  }