Package org.beryl.gui.widgets

Examples of org.beryl.gui.widgets.TreeItem


    dataModel.addModelChangeListener(this);
  }

  public void refresh(Document document) throws GUIException {
    for (int i = 0; i < rootNode.getChildCount(); i++) {
      TreeItem item = (TreeItem) rootNode.getChild(i);
      WidgetUserObject object = (WidgetUserObject) item.getUserObject();

      if (object.widget instanceof Frame) {
        ((Frame) object.widget).dispose();
      } else if (object.widget instanceof Dialog) {
        ((Dialog) object.widget).dispose();
View Full Code Here


  /**
   * Traverses the XML tree, creates the preview
   * and builds the widget tree
   */
  private Widget traverseDocument(Element xmlNode, TreeItem parentNode) throws GUIException {
    TreeItem newNode = new TreeItem(parentNode, null);
    WidgetUserObject parent = (WidgetUserObject) parentNode.getUserObject();

    String classAttribute = xmlNode.getAttribute("class");
    String nameAttribute = xmlNode.getAttribute("name");
    String presetAttribute = xmlNode.getAttribute("preset");

    if (presetAttribute.equals(""))
      presetAttribute = null;
    if (nameAttribute.equals(""))
      nameAttribute = null;
    Widget widget = constructWidget(parent.widget, classAttribute, nameAttribute, presetAttribute);
    WidgetUserObject object = new WidgetUserObject(xmlNode, widget, newNode);
    newNode.setUserObject(object);
    newNode.setText(describeWidget(xmlNode));

    NodeList childNodes = xmlNode.getChildNodes();

    object.tableModel.addRow(new NameTableRow(object));
    Element anchorNode = XMLUtils.getChild(xmlNode, "anchor");
View Full Code Here

    return buf.toString();
  }

  public void doInsert(String className) throws GUIException {
    TreeItem items[] = (TreeItem[]) dataModel.getValue("tree.selected");
    if (items.length == 1) {
      WidgetInfo info = constructWidget(null, className, null, null).getWidgetInfo();
      Element anchorElement =
        ((WidgetUserObject) rootNode.getUserObject()).element.getOwnerDocument().createElement("anchor");
      new InsertDialog(this, className, info, anchorElement);
View Full Code Here

      new InsertDialog(this, className, info, anchorElement);
    }
  }

  public void doInsert(String className, String preset, Element anchorNode) throws GUIException {
    TreeItem items[] = (TreeItem[]) dataModel.getValue("tree.selected");
    TreeItem item = items[0];
    WidgetUserObject parentObject = (WidgetUserObject) item.getUserObject();
    Document document = parentObject.element.getOwnerDocument();

    Element childWidget = document.createElement("widget");
    childWidget.setAttribute("class", className);
    if (preset != null)
      childWidget.setAttribute("preset", preset);

    TreeItem newNode = new TreeItem(item, null);
    Widget parentWidget = ((WidgetUserObject) item.getUserObject()).widget;
    Widget widget = constructWidget(parentWidget, className, null, preset);

    Object anchor = null;

    if (parentWidget != null) {
      anchor = createAnchor(widget, anchorNode);
      parentWidget.addChild(widget, anchor);
    }

    widget.finalizeConstruction();

    parentObject.element.appendChild(childWidget);

    if (widget instanceof Dialog) {
      Dialog dialog = (Dialog) widget;
      dialog.initDialog(null);
      dialog.show();
    }

    if (parentWidget != null)
      revalidate(parentWidget);

    WidgetUserObject userObject = new WidgetUserObject(childWidget, widget, newNode);
    userObject.tableModel.addRow(new NameTableRow(userObject));

    if (anchorNode != null) {
      childWidget.appendChild(anchorNode);
      PropertyTableRow row = new PropertyTableRow(userObject, anchor, anchorNode);
      userObject.tableModel.addRow(row);
    }

    newNode.setUserObject(userObject);
    newNode.setText(className);
    item.addChild(newNode, null);
    widgetTree.structureChanged(item);
    dataModel.setValue("tree.selected", new TreeItem[] { newNode });
    Builder.markModified();
  }
View Full Code Here

      throw new GUIException("Widget constructor threw an exception", e);
    }
  }

  private void doDelete(TreeItem item) throws GUIException {
    TreeItem parent = (TreeItem) item.getParent();
    WidgetUserObject object = (WidgetUserObject) item.getUserObject();
    object.element.getParentNode().removeChild(object.element);
    Widget parentWidget = object.widget.getParentWidget();

    if (object.widget.getParentWidget() != null) {
      object.widget.getParentWidget().removeChildWidget(object.widget);
      revalidate(parentWidget);
    } else {
      if (object.widget instanceof Frame) {
        ((Frame) object.widget).dispose();
      } else if (object.widget instanceof Dialog) {
        ((Dialog) object.widget).dispose();
      }
    }

    parent.remove(item);
    widgetTree.structureChanged(parent);
    Builder.markModified();
  }
View Full Code Here

   * Removes and then re-inserts all children of the given widget's parent
   */
  public static void doReInsert(WidgetUserObject object) throws GUIException {
    ArrayList temp = new ArrayList(), tempAnchors = new ArrayList();
    Widget parentWidget = object.widget.getParentWidget();
    TreeItem parentNode = (TreeItem) object.treeNode.getParentWidget();

    for (int i=0, count=parentNode.getChildCount(); i<count; i++) {
      TreeItem node = (TreeItem) parentNode.getChild(i);
      WidgetUserObject nodeObj = (WidgetUserObject) node.getUserObject();
      temp.add(nodeObj.widget);
      tempAnchors.add(XMLUtils.getChild(nodeObj.element, "anchor"));
      parentWidget.removeChildWidget(nodeObj.widget);
    }
    for (int i=0; i<temp.size(); i++) {
View Full Code Here

  private void doMove(TreeItem moveItem, boolean up) throws GUIException {
    WidgetUserObject object = (WidgetUserObject) moveItem.getUserObject();
    ArrayList temp = new ArrayList();

    /* Update tree */
    TreeItem parentTreeItem = (TreeItem) moveItem.getParentWidget();
    int treeIndex = parentTreeItem.getChildIndex(moveItem);
    if (treeIndex == -1)
      throw new GUIException("Tree node not found");
    for (int i=0, count=parentTreeItem.getChildCount(); i<count; i++) {
      TreeItem item = (TreeItem) parentTreeItem.getChild(0);
      if (item != moveItem)
        temp.add(item);
      parentTreeItem.removeChildWidget(item);
    }
    temp.add(treeIndex + (up ? -1 : 1), moveItem);
View Full Code Here

  public void eventOccured(GUIEvent event) {
    String command = event.getName();

    try {
      if (command.equals("tree.popup")) {
        TreeItem items[] = (TreeItem[]) dataModel.getValue("tree.selected");
        if (items.length > 0) {
          boolean notRoot = items.length > 1 || (items.length == 1 && items[0] != rootNode);
          boolean moveUp =
            items.length == 1
              && items[0] != rootNode
              && (items[0].getParentWidget().getChildIndex(items[0]) > 0);
          boolean moveDown =
            items.length == 1
              && items[0] != rootNode
              && (items[0].getParentWidget().getChildIndex(items[0])
                < items[0].getParentWidget().getChildCount() - 1);
          treePopupMenu.getWidget("Delete").setEnabled(notRoot);
          treePopupMenu.getWidget("MoveUp").setEnabled(moveUp);
          treePopupMenu.getWidget("MoveDown").setEnabled(moveDown);
          treePopupMenu.popup(event);
        }
      } else if (command.equals("property.popup")) {
        propertyPopupMenu.popup(event);
      } else if (command.equals("delete")) {
        TreeItem items[] = (TreeItem[]) dataModel.getValue("tree.selected");
        for (int i = 0; i < items.length; i++) {
          if (items[i] != rootNode)
            doDelete(items[i]);
        }
      } else if (command.equals("add_property")) {
        TreeItem items[] = (TreeItem[]) dataModel.getValue("tree.selected");
        if (items.length == 1 && items[0] != rootNode) {
          new AddPropertyDialog(frame, (WidgetUserObject) items[0].getUserObject());
        }
      } else if (command.equals("delete_property")) {
        TableRow rows[] = (TableRow[]) dataModel.getValue("property.value");
        for (int i = 0; i < rows.length; i++) {
          if (rows[i] instanceof PropertyTableRow) {
            doDeleteProperty((PropertyTableRow) rows[i]);
            Builder.markModified();
          }
        }
      } else if (command.equals("events")) {
        TreeItem items[] = (TreeItem[]) dataModel.getValue("tree.selected");

        if (items.length == 1 && items[0] != rootNode) {
          new EventDialog(this, frame, (WidgetUserObject) items[0].getUserObject());
        }
      } else if (command.equals("move_up")) {
        TreeItem items[] = (TreeItem[]) dataModel.getValue("tree.selected");

        if (items.length == 1 && items[0] != rootNode) {
          doMove(items[0], true);
        }
      } else if (command.equals("move_down")) {
        TreeItem items[] = (TreeItem[]) dataModel.getValue("tree.selected");

        if (items.length == 1 && items[0] != rootNode) {
          doMove(items[0], false);
        }
      }
View Full Code Here

  public void modelChanged(ModelChangeEvent e) throws GUIException {
    if (e instanceof MapChangeEvent) {
      MapChangeEvent event = (MapChangeEvent) e;
      if (event.getKey().equals("tree.selected")) {
        TreeItem items[] = (TreeItem[]) event.getNewValue();
        dataModel.setValue("property.value", new TableRow[] {
        });
        if (items.length == 1 && items[0] != rootNode) {
          WidgetUserObject object = (WidgetUserObject) items[0].getUserObject();
          table.setTableDataModel(object.tableModel);
View Full Code Here

    layoutNode.setAttribute("hweights", hweights);
    layoutNode.setAttribute("vweights", vweights);
    object.widget.setProperty("layout", LayoutFactory.getInstance().constructLayout(object.widget, layoutNode));

    for (int i = 0; i < object.treeNode.getChildCount(); i++) {
      TreeItem item = (TreeItem) object.treeNode.getChild(i);
      WidgetUserObject childObject = (WidgetUserObject) item.getUserObject();
      Element anchorNode = XMLUtils.getChild(childObject.element, "anchor");

      Widget childWidget = childObject.widget;
      object.widget.removeChildWidget(childWidget);
      object.widget.addChild(childWidget, WidgetTree.createAnchor(object.widget, anchorNode));
View Full Code Here

TOP

Related Classes of org.beryl.gui.widgets.TreeItem

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.