コード例 #1
0
 @Override
 public void copyAttributes(Widget widgetSource, Widget widgetTarget) {
   super.copyAttributes(widgetSource, widgetTarget);
   VkMenuBarHorizontal sourceMenuBar = (VkMenuBarHorizontal) widgetSource;
   VkMenuBarHorizontal targetMenuBar = (VkMenuBarHorizontal) widgetTarget;
   for (int i = 0, allItems = 0, k = 0; i < sourceMenuBar.getItemCount(); i++, allItems++) {
     if (sourceMenuBar.getItems().get(i).getSubMenu() == null)
       addMenuItem(
           targetMenuBar,
           sourceMenuBar.getItems().get(i).getHTML(),
           sourceMenuBar
               .getCommandJs()
               .get(sourceMenuBar.getItems().indexOf(sourceMenuBar.getItems().get(i))));
     else {
       VkMenuBarHorizontal widget =
           (VkMenuBarHorizontal)
               VkStateHelper.getInstance().getEngine().getWidget(VkMenuBarVertical.NAME);
       targetMenuBar.addItem(
           new MenuItem(
               sourceMenuBar.getItems().get(i).getHTML(),
               (VkMenuBarVertical)
                   VkStateHelper.getInstance()
                       .getWidgetEngineMapping()
                       .getEngineMap()
                       .get(((IVkWidget) widget).getWidgetName())
                       .deepClone(sourceMenuBar.getItems().get(i).getSubMenu(), widget)));
     }
     if (k < sourceMenuBar.getSeperatorIndices().size()
         && sourceMenuBar.getSeperatorIndices().get(k) == allItems + 1)
       addSeparator(targetMenuBar);
   }
 }
コード例 #2
0
 @Override
 public List<String> getAttributesList(Widget invokingWidget) {
   List<String> list = new ArrayList<String>();
   list.add(ADD_SEPERATOR);
   list.add(ADD_ITEM);
   list.add(EDIT_ITEM);
   list.add(REMOVE_ITEM);
   list.add(ADD_MENU);
   list.addAll(VkStateHelper.getInstance().getEngine().getAttributesList(invokingWidget));
   return list;
 }
コード例 #3
0
 public void setHorizontalAlignment(String horizontalAlignment) {
   if (VkStateHelper.getInstance().isDesignerMode()) {
     final ListBox listBox = new ListBox(false);
     listBox.addItem("Left", "left");
     listBox.addItem("Center", "center");
     listBox.addItem("Right", "right");
     listBox.setWidth("100px");
     showSetCellAlignmentDialog(
         listBox,
         new IAlignment() {
           @Override
           public void doAlignment(int widgetIndex, String align) {
             DOM.setElementAttribute(
                 (Element) getWidget(widgetIndex).getElement().getParentElement(), "align", align);
           }
         });
   }
 }
コード例 #4
0
 @Override
 public String serialize(IVkWidget widget) {
   StringBuffer buffer = new StringBuffer("{");
   buffer.append("widgetName:'").append(widget.getWidgetName()).append("'");
   buffer.append(",style:'").append(VkDesignerUtil.getCssText((Widget) widget)).append("'");
   serializeAttributes(buffer, (Widget) widget);
   VkMenuBarHorizontal menuBar = (VkMenuBarHorizontal) widget;
   buffer.append(",items:[");
   for (int i = 0, allItems = 0, k = 0; i < menuBar.getItemCount(); i++, allItems++) {
     buffer.append("{html:'").append(menuBar.getItems().get(i).getHTML()).append("'");
     if (menuBar.getItems().get(i).getSubMenu() == null) {
       if (menuBar.getCommandJs().containsKey(i))
         buffer
             .append(",js:'")
             .append(menuBar.getCommandJs().get(i).replace('\'', '"'))
             .append("'");
       else
         buffer
             .append(",child:")
             .append(
                 VkStateHelper.getInstance()
                     .getWidgetEngineMapping()
                     .getEngineMap()
                     .get(((IVkWidget) menuBar.getWidgets().get(i)).getWidgetName())
                     .serialize((IVkWidget) menuBar.getWidgets().get(i)));
     } else
       buffer
           .append(",menu:")
           .append(serialize((IVkWidget) menuBar.getItems().get(i).getSubMenu()));
     buffer.append("},");
     if (k < menuBar.getSeperatorIndices().size()
         && menuBar.getSeperatorIndices().get(k) == allItems + 1) {
       buffer.append("{separator:''},");
       allItems++;
       k++;
     }
   }
   if (buffer.charAt(buffer.length() - 1) == ',') buffer.deleteCharAt(buffer.length() - 1);
   buffer.append("]}");
   return buffer.toString();
 }
コード例 #5
0
 @Override
 public void buildWidget(JSONObject jsonObj, Widget parent) {
   VkMenuBarHorizontal tree = (VkMenuBarHorizontal) parent;
   addAttributes(jsonObj, parent);
   JSONArray items = jsonObj.get("items").isArray();
   for (int i = 0; i < items.size(); i++) {
     JSONObject item = items.get(i).isObject();
     JSONValue js = item.get("js");
     if (js != null)
       ((VkMenuBarHorizontalEngine)
               VkStateHelper.getInstance()
                   .getWidgetEngineMapping()
                   .getEngineMap()
                   .get(((IVkWidget) tree).getWidgetName()))
           .addMenuItem(
               tree,
               item.get("html").isString().stringValue(),
               item.get("js").isString().stringValue());
     else if (item.containsKey("child")) {
       JSONObject childObj = item.get("child").isObject();
       JSONString widgetName = childObj.get("widgetName").isString();
       Widget widget = VkStateHelper.getInstance().getEngine().getWidget(widgetName.stringValue());
       VkStateHelper.getInstance().getEngine().addWidget(widget, ((IVkPanel) tree));
       VkStateHelper.getInstance()
           .getWidgetEngineMapping()
           .getEngineMap()
           .get(((IVkWidget) widget).getWidgetName())
           .buildWidget(childObj, widget);
       // addAttributes(childObj, widget);
     } else if (item.get("separator") == null) {
       VkMenuBarHorizontal subTree =
           (VkMenuBarHorizontal)
               VkStateHelper.getInstance()
                   .getEngine()
                   .getWidget(VkMenuBarVertical.NAME); // all submenus are vertical
       // addAttributes(item.get("menu").isObject(), subTree);
       tree.addItem(new MenuItem(item.get("html").isString().stringValue(), subTree));
       VkStateHelper.getInstance()
           .getWidgetEngineMapping()
           .getEngineMap()
           .get(((IVkWidget) tree).getWidgetName())
           .buildWidget(item.get("menu").isObject(), subTree);
     } else addSeparator(tree);
   }
 }
コード例 #6
0
 @Override
 public void setVerticalAlignment(String verticalAlignment) {
   if (VkStateHelper.getInstance().isDesignerMode()) {
     final ListBox listBox = new ListBox(false);
     listBox.addItem("Top", "top");
     listBox.addItem("Middle", "middle");
     listBox.addItem("Bottom", "bottom");
     listBox.setWidth("100px");
     if (getVerticalAlignmentString().equals("top")) listBox.setSelectedIndex(0);
     else if (getVerticalAlignmentString().equals("middle")) listBox.setSelectedIndex(1);
     else if (getVerticalAlignmentString().equals("bottom")) listBox.setSelectedIndex(2);
     showSetCellAlignmentDialog(
         listBox,
         new IAlignment() {
           @Override
           public void doAlignment(int widgetIndex, String align) {
             DOM.setStyleAttribute(
                 (Element) getWidget(widgetIndex).getElement().getParentElement(),
                 "verticalAlign",
                 align);
           }
         });
   }
 }
コード例 #7
0
  @Override
  public void applyAttribute(String attributeName, Widget invokingWidget) {
    final VkMenuBarHorizontal menuBar = (VkMenuBarHorizontal) invokingWidget;
    if (attributeName.equals(ADD_SEPERATOR)) addSeparator(menuBar);
    else if (attributeName.equals(ADD_ITEM)) showAddItemAttributeDialog(menuBar);
    else if (attributeName.equals(REMOVE_ITEM)) {
      final ListBox listBox = new ListBox();
      listBox.setWidth("200px");
      int itemCount = menuBar.getItemCount();
      if (itemCount == 0) {
        Window.alert("No Items found to remove");
        return;
      }
      for (int i = 0; i < itemCount; i++)
        listBox.addItem(menuBar.getMenuItem(i).getText(), Integer.toString(i));
      VkDesignerUtil.showAddListDialog(
          "Choose the item to edit",
          listBox,
          new IDialogCallback() {
            @Override
            public void save(String number) {
              menuBar.removeItem(menuBar.getMenuItem(listBox.getSelectedIndex()));
            }
          });
    } else if (attributeName.equals(EDIT_ITEM)) {
      final ListBox listBox = new ListBox();
      listBox.setWidth("200px");
      int itemCount = menuBar.getItemCount();
      if (itemCount == 0) {
        Window.alert("No Items found to edit");
        return;
      }
      for (int i = 0; i < itemCount; i++)
        listBox.addItem(menuBar.getMenuItem(i).getText(), Integer.toString(i));
      VkDesignerUtil.showAddListDialog(
          "Choose the item to edit",
          listBox,
          new IDialogCallback() {
            @Override
            public void save(String number) {
              int index = listBox.getSelectedIndex();
              showEditItemAttributeDialog(menuBar, index);
            }
          });
    } else if (attributeName.equals(ADD_MENU)) {
      final TextBox nameTb = new TextBox();
      nameTb.setWidth("300px");
      VkDesignerUtil.showAddTextAttributeDialog(
          "Please provide name of sub-menu",
          nameTb,
          new IDialogCallback() {

            @Override
            public void save(String js) {
              final VkMenuBarVertical widget =
                  (VkMenuBarVertical)
                      VkStateHelper.getInstance().getEngine().getWidget(VkMenuBarVertical.NAME);
              menuBar.add(widget);
              menuBar.getMenuItem(menuBar.getItemCount() - 1).setText(nameTb.getText());
            }
          });
    } else VkStateHelper.getInstance().getEngine().applyAttribute(attributeName, invokingWidget);
  }