Esempio n. 1
0
  @Override
  protected void setup(VaadinRequest request) {
    TestUtils.injectCSS(this, ".hugemargin { margin: 10px 20px !important; }");

    HorizontalLayout hl = new HorizontalLayout();
    addLayoutTest(hl);
    hl.setExpandRatio(hl.getComponent(0), 1.0f);
    hl.setExpandRatio(hl.getComponent(2), 0.5f);
    VerticalLayout vl = new VerticalLayout();
    addLayoutTest(vl);
    vl.setExpandRatio(vl.getComponent(0), 1.0f);
    vl.setExpandRatio(vl.getComponent(2), 0.5f);

    GridLayout gl = new GridLayout(2, 1);
    addLayoutTest(gl);
    gl.setColumnExpandRatio(0, 1.0f);
    gl.setRowExpandRatio(0, 1.0f);
    gl.setColumnExpandRatio(1, 0.5f);
    gl.setRowExpandRatio(1, 0.5f);
  }
Esempio n. 2
0
  @Override
  protected void setup() {
    instance = this; // Note, test only works with single app per server if
    // get()
    // not converted to thread local

    sp = new HorizontalSplitPanel();
    sp.setSplitPosition(20);
    CssLayout l = new CssLayout();
    sp.setFirstComponent(l);

    tree1 = new Tree("Volume 1");
    tree1.setImmediate(true);

    fs1 = new BeanItemContainer<File>(File.class);
    tree1.setContainerDataSource(fs1);
    for (int i = 0; i < files.length; i++) {
      fs1.addBean(files[i]);
      if (files[i] instanceof Folder) {
        tree1.setChildrenAllowed(files[i], true);
      } else {
        tree1.setChildrenAllowed(files[i], false);
      }
      if (i >= files.length / 2) {
        tree1.setParent(files[i], files[i - files.length / 2]);
      }
    }
    tree1.setItemCaptionPropertyId("name");
    tree1.setItemIconPropertyId("icon");

    tree1.setDragMode(TreeDragMode.NODE);

    DropHandler dropHandler =
        new DropHandler() {
          @Override
          public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
          }

          @Override
          public void drop(DragAndDropEvent dropEvent) {
            File file = null;
            Folder folder = null;
            TreeTargetDetails dropTargetData = (TreeTargetDetails) dropEvent.getTargetDetails();
            folder = (Folder) dropTargetData.getItemIdInto();
            if (dropEvent.getTransferable() instanceof DataBoundTransferable) {
              DataBoundTransferable transferable =
                  (DataBoundTransferable) dropEvent.getTransferable();
              file = (File) transferable.getItemId();
            } else if (dropEvent.getTransferable().getSourceComponent() instanceof FileIcon) {
              FileIcon draggedIcon = (FileIcon) dropEvent.getTransferable().getSourceComponent();
              file = draggedIcon.file;
            }
            setParent(file, folder);
          }
        };

    tree1.setDropHandler(dropHandler);

    Handler actionHandler =
        new Handler() {

          private Action[] actions = new Action[] {new Action("Remove")};

          @Override
          public void handleAction(Action action, Object sender, Object target) {
            ContainerHierarchicalWrapper containerDataSource =
                (ContainerHierarchicalWrapper) tree1.getContainerDataSource();
            containerDataSource.removeItemRecursively(target);
          }

          @Override
          public Action[] getActions(Object target, Object sender) {
            return actions;
          }
        };
    tree1.addActionHandler(actionHandler);

    tree1.addListener(
        new Property.ValueChangeListener() {
          @Override
          public void valueChange(ValueChangeEvent event) {
            Object value = event.getProperty().getValue();
            if (value != null && !(value instanceof Folder)) {
              value = tree1.getParent(value);
            }
            FolderView folderView = FolderView.get((Folder) value);
            sp.setSecondComponent(folderView);
            folderView.reload();
          }
        });

    l.addComponent(tree1);

    sp.setSecondComponent(FolderView.get(null));

    getLayout().setSizeFull();
    getLayout().addComponent(sp);
    TestUtils.injectCSS(
        getLayout().getUI(),
        ""
            + ".v-tree .v-icon {height:16px;} "
            + ".v-tree-node-caption-drag-top {/*border-top: none;*/} "
            + ".v-tree-node-caption-drag-bottom {border-bottom: none ;} "
            + ".v-tree-node-caption-drag-center {background-color: transparent;}"
            + ".v-tree-node-caption-dragfolder { background-color: cyan;} ");
  }