예제 #1
0
  public void updateTreeItems(TreeItem treeItem, List<FileWrapper> list) {
    if (treeItem == null) treeItem = trtmRoot;

    int index = 0, numberOfChildren = treeItem.getChildCount();
    int newIndex = 0, numberOfNewChildren = list.size();
    while (newIndex < numberOfNewChildren && index < numberOfChildren) {
      FileWrapper fileWrapper = list.get(newIndex);
      if (fileWrapper.getKind() != FileType.DIR) {
        break;
      }
      TreeItem child = treeItem.getChild(index);
      int diff = child.getText().compareTo(fileWrapper.getName());
      if (diff < 0) {
        treeItem.removeItem(child);
      } else if (diff > 0) {
        TreeItem trtmNewItem = new TreeItem();
        treeItem.insertItem(index, trtmNewItem);
        trtmNewItem.setText(fileWrapper.getName());
        index++;
        numberOfChildren++;
        newIndex++;
        presenter.getFiles(trtmNewItem, getPath(trtmNewItem));
      } else {
        index++;
        newIndex++;
        presenter.getFiles(child, getPath(child));
      }
    }
    while (newIndex < numberOfNewChildren) {
      FileWrapper fileWrapper = list.get(newIndex++);
      if (fileWrapper.getKind() != FileType.DIR) {
        break;
      }
      TreeItem trtmNewItem = new TreeItem();
      treeItem.addItem(trtmNewItem);
      trtmNewItem.setText(fileWrapper.getName());
      presenter.getFiles(trtmNewItem, getPath(trtmNewItem));
    }
    while (index < numberOfChildren) {
      treeItem.removeItem(treeItem.getChild(index));
      numberOfChildren--;
    }
  }
예제 #2
0
  public void sprayFileList(List<FileWrapper> list) {
    checkBoxList.clear();
    selectedFileSet.clear();
    flowPanel.clear();

    for (final FileWrapper fileWrapper : list) {
      final FlowPanel tempFlowPanel = new FlowPanel();
      flowPanel.add(tempFlowPanel);
      tempFlowPanel.getElement().getStyle().setProperty("margin", 50, Unit.PX);
      tempFlowPanel.getElement().getStyle().setProperty("textAlign", "center");
      tempFlowPanel.getElement().getStyle().setProperty("verticalAlign", "top");
      tempFlowPanel.getElement().getStyle().setProperty("display", "inline-block");
      tempFlowPanel.sinkEvents(Event.ONDBLCLICK);
      tempFlowPanel.sinkEvents(Event.ONCONTEXTMENU);

      final CheckBox chckbxFileName = new CheckBox(fileWrapper.getName());

      Image imgFileIcon;
      switch (fileWrapper.getKind()) {
        case DIR:
          imgFileIcon = new Image("/img/folder.png");
          tempFlowPanel.addHandler(
              new DoubleClickHandler() {
                public void onDoubleClick(DoubleClickEvent event) {
                  presenter.changeDirectory(fileWrapper.getPath());
                }
              },
              DoubleClickEvent.getType());
          tempFlowPanel.addHandler(
              new ContextMenuHandler() {
                public void onContextMenu(ContextMenuEvent event) {
                  event.preventDefault();
                  event.stopPropagation();
                  FileContextMenu fileContextMenu =
                      new FileContextMenu(
                          presenter,
                          ContextMenuType.DIRECTORY,
                          fileWrapper.getPath(),
                          selectedFileSet);
                  fileContextMenu.setPopupPosition(
                      event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
                  fileContextMenu.show();
                  chckbxFileName.setValue(true, true);
                }
              },
              ContextMenuEvent.getType());
          break;

        default:
          imgFileIcon = new Image("/img/file.png");
          tempFlowPanel.addHandler(
              new DoubleClickHandler() {
                public void onDoubleClick(DoubleClickEvent event) {
                  presenter.downloadFiles(selectedFileSet);
                }
              },
              DoubleClickEvent.getType());
          tempFlowPanel.addHandler(
              new ContextMenuHandler() {
                public void onContextMenu(ContextMenuEvent event) {
                  event.preventDefault();
                  event.stopPropagation();
                  FileContextMenu fileContextMenu =
                      new FileContextMenu(
                          presenter,
                          ContextMenuType.OTHERS,
                          fileWrapper.getPath(),
                          selectedFileSet);
                  fileContextMenu.setPopupPosition(
                      event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
                  fileContextMenu.show();
                  chckbxFileName.setValue(true, true);
                }
              },
              ContextMenuEvent.getType());
          break;
      }
      tempFlowPanel.add(imgFileIcon);
      imgFileIcon.setSize("128px", "128px");
      imgFileIcon.getElement().getStyle().setProperty("display", "block");

      checkBoxList.add(chckbxFileName);
      tempFlowPanel.add(chckbxFileName);
      chckbxFileName.addStyleName("iconName");
      chckbxFileName.getElement().getStyle().setProperty("display", "block");

      chckbxFileName.addClickHandler(clickHandlerStopPropagation);
      chckbxFileName.addValueChangeHandler(
          new ValueChangeHandler<Boolean>() {
            public void onValueChange(ValueChangeEvent<Boolean> event) {
              if (event.getValue()) {
                tempFlowPanel.getElement().getStyle().setBackgroundColor("lightblue");
                selectedFileSet.add(fileWrapper.getPath());
              } else {
                tempFlowPanel.getElement().getStyle().clearBackgroundColor();
                selectedFileSet.remove(fileWrapper.getPath());
              }

              if (!mntmDeleteFile.isEnabled() && selectedFileSet.size() > 0) {
                mntmDeleteFile.setEnabled(true);
              } else if (selectedFileSet.size() == 0) {
                mntmDeleteFile.setEnabled(false);
              }

              if (selectedFileSet.size() == 1
                  && !mntmDownloadFile.isEnabled()
                  && !mntmRenameFile.isEnabled()) {
                mntmDownloadFile.setEnabled(true);
                mntmRenameFile.setEnabled(true);
              } else if (selectedFileSet.size() != 1
                  && mntmDownloadFile.isEnabled()
                  && mntmRenameFile.isEnabled()) {
                mntmDownloadFile.setEnabled(false);
                mntmRenameFile.setEnabled(false);
              }
            }
          });

      imgFileIcon.addClickHandler(
          new ClickHandler() {
            public void onClick(ClickEvent event) {
              event.stopPropagation();
              setAllCheckBoxFalse();
              chckbxFileName.setValue(true, true);
            }
          });
      imgFileIcon.addMouseOverHandler(
          new MouseOverHandler() {
            public void onMouseOver(MouseOverEvent event) {
              if (!chckbxFileName.getValue())
                tempFlowPanel.getElement().getStyle().setBackgroundColor("lightgray");
            }
          });
      imgFileIcon.addMouseOutHandler(
          new MouseOutHandler() {
            public void onMouseOut(MouseOutEvent event) {
              if (!chckbxFileName.getValue())
                tempFlowPanel.getElement().getStyle().clearBackgroundColor();
            }
          });
    }
  }