コード例 #1
0
  private void makeActions() {
    encryptFilesAction =
        new Action() {
          public void run() {
            FileDialog fileDialog =
                new FileDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.MULTI);
            String tempPath = fileDialog.open();

            if (tempPath == null) return;

            final File path = new File(tempPath);
            final String[] selectedFiles = fileDialog.getFileNames();

            EncryptedFolderDob parentFolder = root;

            if (!treeViewer.getSelection().isEmpty()) {
              DroppedElement selectedElement =
                  (DroppedElement) ((TreeSelection) treeViewer.getSelection()).getFirstElement();
              if (selectedElement instanceof EncryptedFileDob)
                parentFolder = ((EncryptedFileDob) selectedElement).getParent();
              else if (selectedElement instanceof EncryptedFolderDob) {
                parentFolder = (EncryptedFolderDob) selectedElement;
                treeViewer.expandToLevel(
                    ((TreeSelection) treeViewer.getSelection()).getFirstElement(), 1);
              }
            }

            final EncryptedFolderDob parentFolderFinal = parentFolder;

            ProgressMonitorDialog progressDialog =
                new ProgressMonitorDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
            try {
              progressDialog.open();
              progressDialog.run(
                  false,
                  false,
                  new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                      monitor.beginTask(
                          Messages.TableView_ProgressMonitorDialog_Encrypt,
                          selectedFiles.length + 2);
                      monitor.worked(1);

                      monitor.subTask(Messages.TableView_ProgressMonitor_SubTast_Handler);
                      if (fileDropHandler == null) fileDropHandler = new FileDropHandler();
                      monitor.worked(1);

                      fileDropHandler.processData(
                          selectedFiles, path.getParent(), parentFolderFinal, monitor);

                      monitor.done();
                    }
                  });
            } catch (InvocationTargetException e) {
              log.error(e.getMessage());
            } catch (InterruptedException e) {
              log.error(e.getMessage());
            }
            setSuccessfullyImported();
            treeViewer.refresh();
            SideBarView.updateFileTypeFilter();
          }
        };

    encryptFilesAction.setToolTipText(Messages.TableView_EncryptFile_Tooltip);
    encryptFilesAction.setImageDescriptor(Activator.getImageDescriptor("icons/encrypt.png"));

    newFolderAction =
        new Action() {
          public void run() {
            InputDialog newFolderDialog =
                new InputDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    Messages.TableView_NewFolderDialog_Title,
                    Messages.TableView_NewFolderDialog,
                    "",
                    new SteadyInputValidator());
            if (newFolderDialog.open() == Window.OK) {
              EncryptedFolderDob parentFolder = root;
              if (!treeViewer.getSelection().isEmpty()) {
                DroppedElement selectedElement =
                    (DroppedElement) ((TreeSelection) treeViewer.getSelection()).getFirstElement();

                if (selectedElement instanceof EncryptedFolderDob)
                  parentFolder = (EncryptedFolderDob) selectedElement;
                else if (selectedElement instanceof EncryptedFileDob)
                  parentFolder = ((EncryptedFileDob) selectedElement).getParent();
              }
              parentFolder.addFolder(
                  encryptedFolderDao.addFolder(
                      new EncryptedFolder(
                          newFolderDialog.getValue().trim(),
                          new Date(System.currentTimeMillis()),
                          "",
                          parentFolder)));

              if (!treeViewer.getSelection().isEmpty()) {
                DroppedElement selectedElement =
                    (DroppedElement) ((TreeSelection) treeViewer.getSelection()).getFirstElement();

                if (selectedElement instanceof EncryptedFolderDob)
                  treeViewer.expandToLevel(
                      ((TreeSelection) treeViewer.getSelection()).getFirstElement(), 1);
              }

              statusline.setMessage(
                  Activator.getImageDescriptor("icons/info.png").createImage(),
                  NLS.bind(Messages.StatusLine_FolderCreated, newFolderDialog.getValue().trim()));
              treeViewer.refresh();
            }
          }
        };

    newFolderAction.setToolTipText(Messages.TableView_NewFolder_Tooltip);
    newFolderAction.setImageDescriptor(Activator.getImageDescriptor("icons/folder_add.png"));

    exportSelectionAction =
        new Action() {
          public void run() {
            if (!treeViewer.getSelection().isEmpty()) {
              final TreeSelection currentSelection = (TreeSelection) treeViewer.getSelection();

              DirectoryDialog directoryDialog =
                  new DirectoryDialog(
                      PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE);
              directoryDialog.setText(Messages.TableView_ExportFileDialog_Title);
              final String path = directoryDialog.open();

              if (path != null) {
                ProgressMonitorDialog progressDialog =
                    new ProgressMonitorDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
                try {
                  progressDialog.open();
                  progressDialog.run(
                      false,
                      false,
                      new IRunnableWithProgress() {
                        public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                          monitor.beginTask(
                              Messages.TableView_ProgressMonitorDialog_Decrypt,
                              currentSelection.size() + 2);
                          monitor.worked(1);

                          monitor.subTask(Messages.TableView_ProgressMonitor_SubTast_Handler);
                          if (decryptHandler == null) decryptHandler = new DecryptHandler();
                          monitor.worked(1);

                          decryptHandler.processData(currentSelection, path, monitor);

                          monitor.done();
                        }
                      });
                } catch (InvocationTargetException e) {
                  log.error(e.getMessage());
                } catch (InterruptedException e) {
                  log.error(e.getMessage());
                }

                statusline.setMessage(
                    Activator.getImageDescriptor("icons/info.png").createImage(),
                    NLS.bind(Messages.StatusLine_Decrypted, remainingHddSpace()));
                treeViewer.refresh();
                SideBarView.updateFileTypeFilter();
              }
            }
          }
        };

    exportSelectionAction.setText(Messages.TableView_ExportFile);
    exportSelectionAction.setToolTipText(Messages.TableView_ExportFile_Tooltip);
    exportSelectionAction.setImageDescriptor(Activator.getImageDescriptor("icons/export.png"));
    exportSelectionAction.setEnabled(false);

    exportSelectionToOrigPathAction =
        new Action() {
          public void run() {
            if (!treeViewer.getSelection().isEmpty()) {
              final TreeSelection currentSelection = (TreeSelection) treeViewer.getSelection();

              if (!(((DroppedElement) currentSelection.getFirstElement()).getPath().length()
                  == 0)) {
                ProgressMonitorDialog progressDialog =
                    new ProgressMonitorDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
                try {
                  progressDialog.open();
                  progressDialog.run(
                      false,
                      false,
                      new IRunnableWithProgress() {
                        public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                          monitor.beginTask(Messages.TableView_ProgressMonitorDialog_Decrypt, 3);
                          monitor.worked(1);

                          monitor.subTask(Messages.TableView_ProgressMonitor_SubTast_Handler);
                          if (decryptHandler == null) decryptHandler = new DecryptHandler();
                          monitor.worked(1);

                          decryptHandler.processData(
                              (DroppedElement) currentSelection.getFirstElement(), monitor);

                          monitor.done();
                        }
                      });
                } catch (InvocationTargetException e) {
                  log.error(e.getMessage());
                } catch (InterruptedException e) {
                  log.error(e.getMessage());
                }

                statusline.setMessage(
                    Activator.getImageDescriptor("icons/info.png").createImage(),
                    NLS.bind(Messages.StatusLine_Decrypted, remainingHddSpace()));
                treeViewer.refresh();
                SideBarView.updateFileTypeFilter();
              } else {
                MessageDialog.openInformation(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    Messages.TableView_InfoDialog_Title,
                    Messages.TableView_ErrorDialog_SCFolder);
                exportSelectionAction.run();
              }
            }
          }
        };

    exportSelectionToOrigPathAction.setText(Messages.TableView_ExportFileToOrigPath);
    exportSelectionToOrigPathAction.setToolTipText(Messages.TableView_ExportFileToOrigPath_Tooltip);
    exportSelectionToOrigPathAction.setImageDescriptor(
        Activator.getImageDescriptor("icons/export.png"));
    exportSelectionToOrigPathAction.setEnabled(false);

    deleteSelectionAction =
        new Action() {
          public void run() {
            if (!treeViewer.getSelection().isEmpty()) {
              final TreeSelection currentSelection = (TreeSelection) treeViewer.getSelection();
              if (MessageDialog.openQuestion(
                  PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                  Messages.TableView_WarningDialog_Title,
                  Messages.TableView_WarningDialog_Delete)) {
                ProgressMonitorDialog progressDialog =
                    new ProgressMonitorDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
                try {
                  progressDialog.open();
                  progressDialog.run(
                      false,
                      false,
                      new IRunnableWithProgress() {
                        public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                          monitor.beginTask(
                              Messages.TableView_ProgressMonitorDialog_Delete,
                              currentSelection.size() + 2);
                          monitor.worked(1);

                          monitor.subTask(Messages.TableView_ProgressMonitor_SubTast_Handler);
                          if (deleteFileHandler == null)
                            deleteFileHandler = new DeleteFileHandler();
                          monitor.worked(1);

                          deleteFileHandler.processData(currentSelection, monitor);

                          monitor.done();
                        }
                      });
                } catch (InvocationTargetException e) {
                  log.error(e.getMessage());
                  e.printStackTrace();
                } catch (InterruptedException e) {
                  log.error(e.getMessage());
                }

                statusline.setMessage(
                    Activator.getImageDescriptor("icons/info.png").createImage(),
                    NLS.bind(Messages.StatusLine_TDeleted, remainingHddSpace()));
                treeViewer.refresh();
                SideBarView.updateFileTypeFilter();
              }
            }
          }
        };

    deleteSelectionAction.setText(Messages.TableView_DeleteFile);
    deleteSelectionAction.setToolTipText(Messages.TableView_DeleteFile_Tooltip);
    deleteSelectionAction.setImageDescriptor(
        Activator.getImageDescriptor(ISharedImages.IMG_ETOOL_DELETE));
    deleteSelectionAction.setEnabled(false);

    renameAction =
        new Action() {
          @SuppressWarnings("unchecked")
          public void run() {
            if (!treeViewer.getSelection().isEmpty()) {
              Iterator<DroppedElement> selectedElementsIterator =
                  ((TreeSelection) treeViewer.getSelection()).iterator();

              while (selectedElementsIterator.hasNext()) {
                DroppedElement selectedElement = selectedElementsIterator.next();
                String nameWithoutExtension =
                    selectedElement instanceof EncryptedFileDob
                        ? selectedElement
                            .getName()
                            .substring(0, selectedElement.getName().lastIndexOf("."))
                        : selectedElement.getName();
                InputDialog renameDialog =
                    new InputDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        Messages.TableView_RenameDialog_Title,
                        NLS.bind(Messages.TableView_RenameDialog, nameWithoutExtension),
                        nameWithoutExtension,
                        new SteadyInputValidator());

                if (renameDialog.open() == Window.OK) {
                  if (selectedElement instanceof EncryptedFolderDob) {
                    selectedElement.setName(renameDialog.getValue());
                    encryptedFolderDao.updateFolder((EncryptedFolderDob) selectedElement);
                  } else if (selectedElement instanceof EncryptedFileDob) {
                    selectedElement.setName(
                        renameDialog.getValue()
                            + "."
                            + ((EncryptedFileDob) selectedElement).getType());
                    encryptedFileDao.updateFile((EncryptedFileDob) selectedElement);
                  }
                }
              }
              treeViewer.refresh();
            }
          }
        };

    renameAction.setText(Messages.TableView_Rename);
    renameAction.setToolTipText(Messages.TableView_Rename);
    renameAction.setImageDescriptor(Activator.getImageDescriptor("icons/rename.png"));
    renameAction.setEnabled(false);

    expandAllAction =
        new Action() {
          public void run() {
            treeViewer.expandAll();
          }
        };

    expandAllAction.setToolTipText(Messages.TableView_ExpandAll_Tooltip);
    expandAllAction.setImageDescriptor(Activator.getImageDescriptor("icons/expandall.gif"));

    expandChildrenAction =
        new Action() {
          public void run() {
            treeViewer.expandToLevel(
                ((TreeSelection) treeViewer.getSelection()).getFirstElement(),
                TreeViewer.ALL_LEVELS);
          }
        };

    expandChildrenAction.setText(Messages.TableView_ExpandChildren);
    expandChildrenAction.setToolTipText(Messages.TableView_ExpandChildren_Tooltip);
    expandChildrenAction.setImageDescriptor(Activator.getImageDescriptor("icons/expandall.gif"));
    expandChildrenAction.setEnabled(false);

    collapseAllAction =
        new Action() {
          public void run() {
            treeViewer.collapseAll();
          }
        };

    collapseAllAction.setToolTipText(Messages.TableView_CollapseAll_Tooltip);
    collapseAllAction.setImageDescriptor(
        Activator.getImageDescriptor(ISharedImages.IMG_ELCL_COLLAPSEALL));

    collapseChildrenAction =
        new Action() {
          public void run() {
            treeViewer.collapseToLevel(
                ((TreeSelection) treeViewer.getSelection()).getFirstElement(),
                TreeViewer.ALL_LEVELS);
          }
        };

    collapseChildrenAction.setText(Messages.TableView_CollapseChildren);
    collapseChildrenAction.setToolTipText(Messages.TableView_CollapseChildren_Tooltip);
    collapseChildrenAction.setImageDescriptor(
        Activator.getImageDescriptor(ISharedImages.IMG_ELCL_COLLAPSEALL));
    collapseChildrenAction.setEnabled(false);
  }
コード例 #2
0
 public static void setSuccessfullyImported() {
   statusline.setMessage(
       Activator.getImageDescriptor("icons/info.png").createImage(),
       NLS.bind(Messages.StatusLine_Encrypted, remainingHddSpace()));
 }
コード例 #3
0
  public void createPartControl(Composite parent) {
    statusline = getViewSite().getActionBars().getStatusLineManager();
    statusline.setMessage(
        Activator.getImageDescriptor("icons/info.png").createImage(),
        Messages.StatusLine_DropFilesHint);
    makeActions();

    ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL);
    scrolledComposite.setExpandVertical(true);
    scrolledComposite.setExpandHorizontal(true);
    Composite content = new Composite(scrolledComposite, SWT.NONE);
    content.setLayout(new GridLayout(1, false));
    scrolledComposite.setContent(content);

    toolBarManager = new ToolBarManager();
    toolBarManager.add(encryptFilesAction);
    toolBarManager.add(newFolderAction);
    toolBarManager.add(new Separator("static"));
    toolBarManager.add(exportSelectionAction);
    toolBarManager.add(renameAction);
    toolBarManager.add(deleteSelectionAction);
    toolBarManager.add(new Separator("static"));
    toolBarManager.add(expandAllAction);
    toolBarManager.add(collapseAllAction);

    ToolBar toolbar = toolBarManager.createControl(content);
    toolbar.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));

    // Create the tree viewer as a child of the composite parent
    treeViewer =
        new TreeViewer(
            content, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);

    // Anpassungen für TreeTable
    tree = treeViewer.getTree();

    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    treeViewer.getControl().setLayoutData(gridData);

    treeViewer.setUseHashlookup(true);

    /** * Tree table specific code starts ** */
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);

    for (SteadyTableIdentifier identifier : SteadyTableIdentifier.values()) {
      new TreeColumn(tree, SWT.NONE).setText(Messages.getSteadyTableColumnTitle(identifier));
      tree.getColumn(identifier.ordinal()).setWidth(identifier.columnWidth);
    }

    /** * Tree table specific code ends ** */

    // layout the tree viewer below the text field
    gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    treeViewer.getControl().setLayoutData(gridData);

    treeViewer.setContentProvider(new SteadyTreeTableContentProvider());
    treeViewer.setLabelProvider(new SteadyTreeTableLabelProvider());

    root = getInitialInput();
    treeViewer.setInput(root);
    treeViewer.expandToLevel(1);

    // Drag-Part //////////////////////////////////////////////////////////
    DragSource source = new DragSource(tree, DND.DROP_COPY | DND.DROP_MOVE);
    source.setTransfer(new Transfer[] {TextTransfer.getInstance()});
    source.addDragListener(new TreeDragSourceListener(tree));

    // Drop-Part //////////////////////////////////////////////////////////
    DropTarget dropTarget = new DropTarget(tree, DND.DROP_COPY | DND.DROP_DEFAULT);
    dropTarget.setTransfer(new Transfer[] {TextTransfer.getInstance(), FileTransfer.getInstance()});
    dropTarget.addDropListener(new TreeDropTargetAdapter(treeViewer, root));

    addListeners();
    createContextMenu();
    createFiltersAndSorters();
  }