Example usage for org.apache.commons.vfs2 FileType FILE

List of usage examples for org.apache.commons.vfs2 FileType FILE

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileType FILE.

Prototype

FileType FILE

To view the source code for org.apache.commons.vfs2 FileType FILE.

Click Source Link

Document

A regular file.

Usage

From source file:pl.otros.vfs.browser.preview.PreviewListener.java

@Override
public void valueChanged(ListSelectionEvent listSelectionEvent) {
    if (listSelectionEvent.getValueIsAdjusting()) {
        return;//from  w  w  w.j a  va 2 s .  c  o m
    }
    boolean previewEnabled = previewComponent.isPreviewEnabled();
    if (!previewEnabled) {
        return;
    }
    FileObject fileObjectToPreview = null;
    for (FileObject fileObject : vfsBrowser.getSelectedFiles()) {
        try {
            if (fileObject.getType().equals(FileType.FILE)) {
                fileObjectToPreview = fileObject;
                break;
            }
        } catch (FileSystemException e) {
            LOGGER.error("Can't resolve file", e);
        }
    }

    if (fileObjectToPreview != null) {
        makePreview(fileObjectToPreview);
    } else {
        clearPreview();
    }
}

From source file:pl.otros.vfs.browser.table.FileNameWithTypeTableCellRenderer.java

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {

    JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
            column);/*from w  ww .ja  v  a2 s. co  m*/
    FileNameWithType fileNameWithType = (FileNameWithType) value;
    FileName fileName = fileNameWithType.getFileName();
    label.setText(fileName.getBaseName());
    label.setToolTipText(fileName.getFriendlyURI());

    FileType fileType = fileNameWithType.getFileType();
    Icon icon = null;
    Icons icons = Icons.getInstance();
    if (fileNameWithType.getFileName().getBaseName().equals(ParentFileObject.PARENT_NAME)) {
        icon = icons.getArrowTurn90();
    } else if (FileType.FOLDER.equals(fileType)) {
        icon = icons.getFolderOpen();
    } else if (VFSUtils.isArchive(fileName)) {
        if ("jar".equalsIgnoreCase(fileName.getExtension())) {
            icon = icons.getJarIcon();
        } else {
            icon = icons.getFolderZipper();
        }
    } else if (FileType.FILE.equals(fileType)) {
        icon = icons.getFile();
    } else if (FileType.IMAGINARY.equals(fileType)) {
        icon = icons.getShortCut();
    }
    label.setIcon(icon);
    return label;
}

From source file:pl.otros.vfs.browser.table.FileObjectComparator.java

private int compareTypes(FileType type1, FileType type2) {
    if (type1.equals(FileType.FILE) && !type2.equals(FileType.FILE)) {
        return 1;
    } else if (!type1.equals(FileType.FILE) && type2.equals(FileType.FILE)) {
        return -1;
    }/* ww  w . j a v a2s. com*/
    return 0;
}

From source file:pl.otros.vfs.browser.table.VfsTableModel.java

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    FileObject fileObject = fileObjects[rowIndex];
    boolean isFile = false;
    try {/*from  www. j  av  a2 s .com*/
        isFile = FileType.FILE.equals(fileObject.getType());
    } catch (FileSystemException e1) {
        LOGGER.warn("Can't check file type " + fileObject.getName().getBaseName(), e1);
    }
    if (columnIndex == COLUMN_NAME) {
        try {
            return new FileNameWithType(fileObject.getName(), fileObject.getType());
        } catch (FileSystemException e) {
            return new FileNameWithType(fileObject.getName(), null);
        }
    } else if (columnIndex == COLUMN_TYPE) {
        try {
            return fileObject.getType().getName();
        } catch (FileSystemException e) {
            LOGGER.warn("Can't get file type " + fileObject.getName().getBaseName(), e);
            return "?";
        }
    } else if (columnIndex == COLUMN_SIZE) {
        try {
            long size = -1;
            if (isFile) {
                size = fileObject.getContent().getSize();
            }
            return new FileSize(size);
        } catch (FileSystemException e) {
            LOGGER.warn("Can't get size " + fileObject.getName().getBaseName(), e);
            return new FileSize(-1);
        }
    } else if (columnIndex == COLUMN_LAST_MOD_DATE) {
        try {

            long lastModifiedTime = 0;
            if (!VFSUtils.isHttpProtocol(fileObject)) {
                lastModifiedTime = fileObject.getContent().getLastModifiedTime();
            }
            return new Date(lastModifiedTime);
        } catch (FileSystemException e) {
            LOGGER.warn("Can't get last mod date " + fileObject.getName().getBaseName(), e);
            return null;
        }
    }
    return "?";
}

From source file:pl.otros.vfs.browser.util.VFSUtils.java

/**
 * Returns whether a file object is a local file
 *
 * @param fileObject/*from  w  ww.j a v  a2s.  c o m*/
 * @return true of {@link FileObject} is a local file
 */
public static boolean isLocalFile(FileObject fileObject) {
    try {
        return fileObject.getURL().getProtocol().equalsIgnoreCase("file")
                && FileType.FILE.equals(fileObject.getType());
    } catch (FileSystemException e) {
        LOGGER.info("Exception when checking if fileobject is local file", e);
        return false;
    }
}

From source file:pl.otros.vfs.browser.util.VFSUtils.java

public static void checkForSftpLinks(FileObject[] files, TaskContext taskContext) {
    LOGGER.debug("Checking for SFTP links");
    taskContext.setMax(files.length);/*from   w  w w . j av a2  s .  co  m*/
    long ts = System.currentTimeMillis();
    for (int i = 0; i < files.length && !taskContext.isStop(); i++) {
        FileObject fileObject = files[i];
        try {
            if (fileObject instanceof SftpFileObject && FileType.FILE.equals(fileObject.getType())) {
                SftpFileObject sftpFileObject = (SftpFileObject) fileObject;
                long size = sftpFileObject.getContent().getSize();
                if (size < SYMBOLIC_LINK_MAX_SIZE && size != 0) {
                    if (!pointToItself(sftpFileObject)) {
                        files[i] = new LinkFileObject(sftpFileObject);
                    }
                }

            }

        } catch (Exception e) {
            //ignore
        } finally {
            taskContext.setCurrentProgress(i);
        }

    }
    long checkDuration = System.currentTimeMillis() - ts;
    LOGGER.info("Checking SFTP links took {} ms [{}ms/file]", checkDuration,
            (float) checkDuration / files.length);
}

From source file:pl.otros.vfs.browser.util.VFSUtils.java

public static boolean pointToItself(FileObject fileObject) throws FileSystemException {
    if (!fileObject.getURL().getProtocol().equalsIgnoreCase("file")
            && FileType.FILE.equals(fileObject.getType())) {
        LOGGER.debug("Checking if {} is pointing to itself", fileObject.getName().getFriendlyURI());
        FileObject[] children = VFSUtils.getChildren(fileObject);
        LOGGER.debug("Children number of {} is {}", fileObject.getName().getFriendlyURI(), children.length);
        if (children.length == 1) {
            FileObject child = children[0];
            if (child.getContent().getSize() != child.getContent().getSize()) {
                return false;
            }/*from  w w w .  j ava  2s. c  o  m*/
            if (child.getName().getBaseName().equals(fileObject.getName().getBaseName())) {
                return true;
            }
        }
    }
    return false;
}

From source file:pl.otros.vfs.browser.VfsBrowser.java

License:asdf

private void initGui(final String initialPath) {
    this.setLayout(new BorderLayout());
    JLabel pathLabel = new JLabel(Messages.getMessage("browser.location"));
    pathLabel.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3));
    pathField = new JTextField(80);
    pathField.setFont(pathLabel.getFont().deriveFont(pathLabel.getFont().getSize() * 1.2f));
    pathField.setToolTipText(Messages.getMessage("nav.pathTooltip"));
    GuiUtils.addBlinkOnFocusGain(pathField);
    pathLabel.setLabelFor(pathField);//from  w  w w . j  ava  2 s. c o m
    pathLabel.setDisplayedMnemonic(Messages.getMessage("browser.location.mnemonic").charAt(0));

    InputMap inputMapPath = pathField.getInputMap(JComponent.WHEN_FOCUSED);
    inputMapPath.put(KeyStroke.getKeyStroke("ENTER"), "OPEN_PATH");
    inputMapPath.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), ACTION_FOCUS_ON_TABLE);
    pathField.getActionMap().put("OPEN_PATH", new BaseNavigateAction(this) {

        @Override
        protected void performLongOperation(CheckBeforeActionResult actionResult) {
            try {
                FileObject resolveFile = VFSUtils.resolveFileObject(pathField.getText().trim());
                if (resolveFile != null && resolveFile.getType() == FileType.FILE) {
                    loadAndSelSingleFile(resolveFile);
                    pathField.setText(resolveFile.getURL().toString());
                    actionApproveDelegate.actionPerformed(
                            // TODO:  Does actionResult provide an ID for 2nd param here,
                            // or should use a Random number?
                            new ActionEvent(actionResult, (int) new java.util.Date().getTime(),
                                    "SELECTED_FILE"));
                    return;
                }
            } catch (FileSystemException fse) {
                // Intentionally empty
            }
            goToUrl(pathField.getText().trim());
        }

        @Override
        protected boolean canGoUrl() {
            return true;
        }

        @Override
        protected boolean canExecuteDefaultAction() {
            return false;
        }

    });
    actionFocusOnTable = new

    AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tableFiles.requestFocusInWindow();
            if (tableFiles.getSelectedRow() < 0 && tableFiles.getRowCount() == 0) {
                tableFiles.getSelectionModel().setSelectionInterval(0, 0);
            }
        }
    };
    pathField.getActionMap().put(ACTION_FOCUS_ON_TABLE, actionFocusOnTable);

    BaseNavigateActionGoUp goUpAction = new BaseNavigateActionGoUp(this);
    goUpButton = new JButton(goUpAction);

    BaseNavigateActionRefresh refreshAction = new BaseNavigateActionRefresh(this);
    JButton refreshButton = new JButton(refreshAction);

    JToolBar upperPanel = new JToolBar(Messages.getMessage("nav.ToolBarName"));
    upperPanel.setRollover(true);
    upperPanel.add(pathLabel);
    upperPanel.add(pathField, "growx");
    upperPanel.add(goUpButton);
    upperPanel.add(refreshButton);

    AddCurrentLocationToFavoriteAction addCurrentLocationToFavoriteAction = new AddCurrentLocationToFavoriteAction(
            this);
    JButton addCurrentLocationToFavoriteButton = new JButton(addCurrentLocationToFavoriteAction);
    addCurrentLocationToFavoriteButton.setText("");
    upperPanel.add(addCurrentLocationToFavoriteButton);

    previewComponent = new PreviewComponent();

    vfsTableModel = new VfsTableModel();

    tableFiles = new JTable(vfsTableModel);
    tableFiles.setFillsViewportHeight(true);
    tableFiles.getColumnModel().getColumn(0).setMinWidth(140);
    tableFiles.getColumnModel().getColumn(1).setMaxWidth(80);
    tableFiles.getColumnModel().getColumn(2).setMaxWidth(80);
    tableFiles.getColumnModel().getColumn(3).setMaxWidth(180);
    tableFiles.getColumnModel().getColumn(3).setMinWidth(120);

    sorter = new TableRowSorter<VfsTableModel>(vfsTableModel);
    final FileNameWithTypeComparator fileNameWithTypeComparator = new FileNameWithTypeComparator();
    sorter.addRowSorterListener(new RowSorterListener() {
        @Override
        public void sorterChanged(RowSorterEvent e) {
            RowSorterEvent.Type type = e.getType();
            if (type.equals(RowSorterEvent.Type.SORT_ORDER_CHANGED)) {
                List<? extends RowSorter.SortKey> sortKeys = e.getSource().getSortKeys();
                for (RowSorter.SortKey sortKey : sortKeys) {
                    if (sortKey.getColumn() == VfsTableModel.COLUMN_NAME) {
                        fileNameWithTypeComparator.setSortOrder(sortKey.getSortOrder());
                    }
                }
            }
        }
    });
    sorter.setComparator(VfsTableModel.COLUMN_NAME, fileNameWithTypeComparator);

    tableFiles.setRowSorter(sorter);
    tableFiles.setShowGrid(false);
    tableFiles.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            try {
                selectionChanged();
            } catch (FileSystemException e1) {
                LOGGER.error("Error during update state", e);
            }
        }
    });
    tableFiles.setColumnSelectionAllowed(false);
    vfsTableModel.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            updateStatusText();
        }
    });

    tableFiles.setDefaultRenderer(FileSize.class, new FileSizeTableCellRenderer());
    tableFiles.setDefaultRenderer(FileNameWithType.class, new FileNameWithTypeTableCellRenderer());
    tableFiles.setDefaultRenderer(Date.class, new MixedDateTableCellRenderer());
    tableFiles.setDefaultRenderer(FileType.class, new FileTypeTableCellRenderer());

    tableFiles.getSelectionModel().addListSelectionListener(new PreviewListener(this, previewComponent));

    JPanel favoritesPanel = new JPanel(new MigLayout("wrap, fillx", "[grow]"));
    favoritesUserListModel = new MutableListModel<Favorite>();

    List<Favorite> favSystemLocations = FavoritesUtils.getSystemLocations();
    List<Favorite> favUser = FavoritesUtils.loadFromProperties(configuration);
    List<Favorite> favJVfsFileChooser = FavoritesUtils.getJvfsFileChooserBookmarks();
    for (Favorite favorite : favUser) {
        favoritesUserListModel.add(favorite);
    }
    favoritesUserListModel.addListDataListener(new ListDataListener() {
        @Override
        public void intervalAdded(ListDataEvent e) {
            saveFavorites();

        }

        @Override
        public void intervalRemoved(ListDataEvent e) {
            saveFavorites();
        }

        @Override
        public void contentsChanged(ListDataEvent e) {
            saveFavorites();
        }

        protected void saveFavorites() {
            FavoritesUtils.storeFavorites(configuration, favoritesUserListModel.getList());
        }
    });

    favoritesUserList = new JList(favoritesUserListModel);
    favoritesUserList.setTransferHandler(new MutableListDropHandler(favoritesUserList));
    new MutableListDragListener(favoritesUserList);
    favoritesUserList.setCellRenderer(new FavoriteListCellRenderer());
    favoritesUserList.addFocusListener(new SelectFirstElementFocusAdapter());

    addOpenActionToList(favoritesUserList);
    addEditActionToList(favoritesUserList, favoritesUserListModel);

    favoritesUserList.getActionMap().put(ACTION_DELETE, new AbstractAction(
            Messages.getMessage("favorites.deleteButtonText"), Icons.getInstance().getMinusButton()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            Favorite favorite = favoritesUserListModel.getElementAt(favoritesUserList.getSelectedIndex());
            if (!Favorite.Type.USER.equals(favorite.getType())) {
                return;
            }
            int response = JOptionPane.showConfirmDialog(VfsBrowser.this,
                    Messages.getMessage("favorites.areYouSureToDeleteConnections"),
                    Messages.getMessage("favorites.confirm"), JOptionPane.YES_NO_OPTION);

            if (response == JOptionPane.YES_OPTION) {
                favoritesUserListModel.remove(favoritesUserList.getSelectedIndex());
            }
        }
    });
    InputMap favoritesListInputMap = favoritesUserList.getInputMap(JComponent.WHEN_FOCUSED);
    favoritesListInputMap.put(KeyStroke.getKeyStroke("DELETE"), ACTION_DELETE);

    ActionMap actionMap = tableFiles.getActionMap();
    actionMap.put(ACTION_OPEN, new BaseNavigateActionOpen(this));
    actionMap.put(ACTION_GO_UP, goUpAction);
    actionMap.put(ACTION_APPROVE, new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (actionApproveButton.isEnabled()) {
                actionApproveDelegate.actionPerformed(e);
            }
        }
    });

    InputMap inputMap = tableFiles.getInputMap(JComponent.WHEN_FOCUSED);
    inputMap.put(KeyStroke.getKeyStroke("ENTER"), ACTION_OPEN);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_MASK), ACTION_APPROVE);

    inputMap.put(KeyStroke.getKeyStroke("BACK_SPACE"), ACTION_GO_UP);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), ACTION_GO_UP);
    addPopupMenu(favoritesUserList, ACTION_OPEN, ACTION_EDIT, ACTION_DELETE);

    JList favoriteSystemList = new JList(new Vector<Object>(favSystemLocations));
    favoriteSystemList.setCellRenderer(new FavoriteListCellRenderer());
    addOpenActionToList(favoriteSystemList);
    addPopupMenu(favoriteSystemList, ACTION_OPEN);
    favoriteSystemList.addFocusListener(new SelectFirstElementFocusAdapter());

    JList favoriteJVfsList = new JList(new Vector<Object>(favJVfsFileChooser));
    addOpenActionToList(favoriteJVfsList);
    favoriteJVfsList.setCellRenderer(new FavoriteListCellRenderer());
    addPopupMenu(favoriteJVfsList, ACTION_OPEN);
    favoriteJVfsList.addFocusListener(new SelectFirstElementFocusAdapter());

    JLabel favoritesSystemLocationsLabel = getTitleListLabel(Messages.getMessage("favorites.systemLocations"),
            COMPUTER_ICON);
    favoritesSystemLocationsLabel.setLabelFor(favoriteSystemList);
    favoritesSystemLocationsLabel
            .setDisplayedMnemonic(Messages.getMessage("favorites.systemLocations.mnemonic").charAt(0));
    favoritesPanel.add(favoritesSystemLocationsLabel, "gapleft 16");
    favoritesPanel.add(favoriteSystemList, "growx");
    JLabel favoritesFavoritesLabel = getTitleListLabel(Messages.getMessage("favorites.favorites"),
            Icons.getInstance().getStar());
    favoritesFavoritesLabel.setLabelFor(favoritesUserList);
    favoritesFavoritesLabel.setDisplayedMnemonic(Messages.getMessage("favorites.favorites.mnemonic").charAt(0));
    favoritesPanel.add(favoritesFavoritesLabel, "gapleft 16");
    favoritesPanel.add(favoritesUserList, "growx");

    if (favoriteJVfsList.getModel().getSize() > 0) {
        JLabel favoritesJVfsFileChooser = getTitleListLabel(
                Messages.getMessage("favorites.JVfsFileChooserBookmarks"), null);
        favoritesJVfsFileChooser.setDisplayedMnemonic(
                Messages.getMessage("favorites.JVfsFileChooserBookmarks.mnemonic").charAt(0));
        favoritesJVfsFileChooser.setLabelFor(favoriteJVfsList);
        favoritesPanel.add(favoritesJVfsFileChooser, "gapleft 16");
        favoritesPanel.add(favoriteJVfsList, "growx");
    }

    tableFiles.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
                tableFiles.getActionMap().get(ACTION_OPEN).actionPerformed(null);
            }
        }
    });
    tableFiles.addKeyListener(new QuickSearchKeyAdapter());

    cardLayout = new CardLayout();
    tablePanel = new JPanel(cardLayout);
    loadingProgressBar = new JProgressBar();
    loadingProgressBar.setStringPainted(true);
    loadingProgressBar.setString(Messages.getMessage("browser.loading"));
    loadingProgressBar.setIndeterminate(true);
    loadingIconLabel = new JLabel(Icons.getInstance().getNetworkStatusOnline());
    skipCheckingLinksButton = new JToggleButton(Messages.getMessage("browser.skipCheckingLinks"));
    skipCheckingLinksButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            if (taskContext != null) {
                taskContext.setStop(skipCheckingLinksButton.isSelected());
            }
        }
    });

    showHidCheckBox = new JCheckBox(Messages.getMessage("browser.showHidden.label"), showHidden);
    showHidCheckBox.setToolTipText(Messages.getMessage("browser.showHidden.tooltip"));
    showHidCheckBox.setMnemonic(Messages.getMessage("browser.showHidden.mnemonic").charAt(0));
    Font tmpFont = showHidCheckBox.getFont();
    showHidCheckBox.setFont(tmpFont.deriveFont(tmpFont.getSize() * 0.9f));
    showHidCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateUiFilters();
        }
    });

    final String defaultFilterText = Messages.getMessage("browser.nameFilter.defaultText");
    filterField = new JTextField("", 16);
    filterField.setForeground(filterField.getDisabledTextColor());
    filterField.setToolTipText(Messages.getMessage("browser.nameFilter.tooltip"));
    PromptSupport.setPrompt(defaultFilterText, filterField);
    filterField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            documentChanged();
        }

        void documentChanged() {
            if (filterField.getText().length() == 0) {
                updateUiFilters();
            }
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            documentChanged();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            documentChanged();
        }
    });
    filterField.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            updateUiFilters();
        }
    });

    AbstractAction actionClearRegexFilter = new

    AbstractAction(Messages.getMessage("browser.nameFilter.clearFilterText")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            filterField.setText("");
        }
    };
    filterField.getActionMap().put(ACTION_FOCUS_ON_TABLE, actionFocusOnTable);
    filterField.getActionMap().put(ACTION_CLEAR_REGEX_FILTER, actionClearRegexFilter);

    filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), ACTION_FOCUS_ON_TABLE);
    filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), ACTION_FOCUS_ON_TABLE);
    filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0),
            ACTION_FOCUS_ON_TABLE);
    filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            ACTION_FOCUS_ON_TABLE);
    filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            ACTION_CLEAR_REGEX_FILTER);

    JLabel nameFilterLabel = new JLabel(Messages.getMessage("browser.nameFilter"));
    nameFilterLabel.setLabelFor(filterField);
    nameFilterLabel.setDisplayedMnemonic(Messages.getMessage("browser.nameFilter.mnemonic").charAt(0));

    sorter.setRowFilter(createFilter());
    statusLabel = new JLabel();

    actionApproveButton = new JButton();
    actionApproveButton.setFont(actionApproveButton.getFont().deriveFont(Font.BOLD));
    actionCancelButton = new JButton();

    ActionMap browserActionMap = this.getActionMap();
    browserActionMap.put(ACTION_FOCUS_ON_REGEX_FILTER, new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            filterField.requestFocus();
            filterField.selectAll();
            GuiUtils.blinkComponent(filterField);
        }
    });

    browserActionMap.put(ACTION_FOCUS_ON_PATH, new SetFocusOnAction(pathField));
    browserActionMap.put(ACTION_SWITCH_SHOW_HIDDEN, new ClickOnJComponentAction(showHidCheckBox));
    browserActionMap.put(ACTION_REFRESH, refreshAction);
    browserActionMap.put(ACTION_ADD_CURRENT_LOCATION_TO_FAVORITES, addCurrentLocationToFavoriteAction);
    browserActionMap.put(ACTION_GO_UP, goUpAction);
    browserActionMap.put(ACTION_FOCUS_ON_TABLE, new SetFocusOnAction(tableFiles));

    InputMap browserInputMap = this.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    browserInputMap.put(KeyStroke.getKeyStroke("control F"), ACTION_FOCUS_ON_REGEX_FILTER);
    browserInputMap.put(KeyStroke.getKeyStroke("control L"), ACTION_FOCUS_ON_PATH);
    browserInputMap.put(KeyStroke.getKeyStroke("F4"), ACTION_FOCUS_ON_PATH);
    browserInputMap.put(KeyStroke.getKeyStroke("control H"), ACTION_SWITCH_SHOW_HIDDEN);
    browserInputMap.put(KeyStroke.getKeyStroke("control R"), ACTION_REFRESH);
    browserInputMap.put(KeyStroke.getKeyStroke("F5"), ACTION_REFRESH);
    browserInputMap.put(KeyStroke.getKeyStroke("control D"), ACTION_ADD_CURRENT_LOCATION_TO_FAVORITES);
    browserInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK), ACTION_GO_UP);
    browserInputMap.put(KeyStroke.getKeyStroke("control T"), ACTION_FOCUS_ON_TABLE);

    //DO layout
    // create the layer for the panel using our custom layerUI
    tableScrollPane = new JScrollPane(tableFiles);

    JPanel tableScrollPaneWithFilter = new JPanel(new BorderLayout());
    tableScrollPaneWithFilter.add(tableScrollPane);
    JToolBar filtersToolbar = new JToolBar("Filters");
    filtersToolbar.setFloatable(false);
    filtersToolbar.setBorderPainted(true);
    tableScrollPaneWithFilter.add(filtersToolbar, BorderLayout.SOUTH);
    filtersToolbar.add(nameFilterLabel);
    filtersToolbar.add(filterField);
    filtersToolbar.add(showHidCheckBox);
    JSplitPane tableWithPreviewPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true,
            tableScrollPaneWithFilter, previewComponent);
    tableWithPreviewPane.setOneTouchExpandable(true);

    JPanel loadingPanel = new JPanel(new MigLayout());
    loadingPanel.add(loadingIconLabel, "right");
    loadingPanel.add(loadingProgressBar, "left, w 420:420:500,wrap");
    loadingPanel.add(skipCheckingLinksButton, "span, right");
    tablePanel.add(loadingPanel, LOADING);
    tablePanel.add(tableWithPreviewPane, TABLE);

    JSplitPane jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(favoritesPanel),
            tablePanel);
    jSplitPane.setOneTouchExpandable(true);
    jSplitPane.setDividerLocation(180);

    JPanel southPanel = new JPanel(new MigLayout("", "[]push[][]", ""));
    southPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    southPanel.add(statusLabel);
    southPanel.add(actionApproveButton);
    southPanel.add(actionCancelButton);

    this.add(upperPanel, BorderLayout.NORTH);
    this.add(jSplitPane, BorderLayout.CENTER);
    this.add(southPanel, BorderLayout.SOUTH);

    try {
        selectionChanged();
    } catch (FileSystemException e) {
        LOGGER.error("Can't initialize default selection mode", e);
    }
    // Why this not done in EDT?
    // Is it assume that constructor is invoked from an  EDT?
    try {
        if (initialPath == null) {
            goToUrl(VFSUtils.getUserHome());
        } else {
            try {
                FileObject resolveFile = VFSUtils.resolveFileObject(initialPath);
                if (resolveFile != null && resolveFile.getType() == FileType.FILE) {
                    loadAndSelSingleFile(resolveFile);
                    pathField.setText(resolveFile.getURL().toString());
                    targetFileSelected = true;
                    return;
                }
            } catch (FileSystemException fse) {
                // Intentionally empty
            }
            goToUrl(initialPath);
        }
    } catch (FileSystemException e1) {
        LOGGER.error("Can't initialize default location", e1);
    }
    showTable();
}

From source file:pl.otros.vfs.browser.VfsBrowser.java

License:asdf

private void selectionChanged() throws FileSystemException {
    LOGGER.debug("Updating selection");
    boolean acceptEnabled = false;
    if (getSelectedFiles().length == 0) {
        acceptEnabled = false;//from w w w.j ava  2 s.c  o m
    } else if (isMultiSelectionEnabled()) {
        boolean filesSelected = false;
        boolean folderSelected = false;

        for (FileObject fo : getSelectedFiles()) {
            FileType fileType = fo.getType();
            if (fileType == FileType.FILE) {
                filesSelected = true;
            } else if (fileType == FileType.FOLDER) {
                folderSelected = true;
            }
        }
        if (selectionMode == SelectionMode.FILES_ONLY && filesSelected && !folderSelected) {
            acceptEnabled = true;
        } else if (selectionMode == SelectionMode.DIRS_ONLY && !filesSelected && folderSelected) {
            acceptEnabled = true;
        } else if (selectionMode == SelectionMode.DIRS_AND_FILES) {
            acceptEnabled = true;
        }
    } else {
        FileObject selectedFileObject = getSelectedFileObject();
        FileType type = selectedFileObject.getType();
        if (selectionMode == SelectionMode.FILES_ONLY && type == FileType.FILE
                || selectionMode == SelectionMode.DIRS_ONLY && type == FileType.FOLDER) {
            acceptEnabled = true;
        } else if (SelectionMode.DIRS_AND_FILES == selectionMode) {
            acceptEnabled = true;
        }
    }

    if (actionApproveDelegate != null) {
        actionApproveDelegate.setEnabled(acceptEnabled);
    }
    actionApproveButton.setEnabled(acceptEnabled);
}

From source file:pt.webdetails.cpk.elements.impl.kettleoutputs.ResultFilesKettleOutput.java

@Override
public void processResult(KettleResult result) {
    logger.debug("Process Result Files");

    List<FileObject> files = new ArrayList<FileObject>();
    for (ResultFile resultFile : result.getFiles()) {
        files.add(resultFile.getFile());
    }//from   w w w  .j a  v a2 s  .  c o  m

    if (files.isEmpty()) {
        logger.warn("Processing result files but no files found");
        this.getResponse().setStatus(HttpServletResponse.SC_NO_CONTENT);
        return;
    }

    String defaultAttachmentName = this.getConfiguration().getAttachmentName();
    try {
        if (files.size() == 1 && files.get(0).getType() == FileType.FILE) {
            // Singe file
            FileObject file = files.get(0);
            InputStream fileInputStream = KettleVFS.getInputStream(file);
            FileName fileName = file.getName();
            String defaultMimeType = this.getConfiguration().getMimeType();
            String mimeType = defaultMimeType != null ? defaultMimeType
                    : MimeTypes.getMimeType(fileName.getBaseName());
            String attachmentName = defaultAttachmentName != null ? defaultAttachmentName
                    : fileName.getBaseName();

            CpkUtils.send(this.getResponse(), fileInputStream, mimeType, attachmentName,
                    this.getConfiguration().getSendResultAsAttachment());

        } else {
            // More than one file, or folder
            // Build a zip / tar and ship it over!
            ZipUtil zip = new ZipUtil();
            zip.buildZipFromFileObjectList(files);

            String attachmentName = defaultAttachmentName != null ? defaultAttachmentName
                    : zip.getZipNameToDownload();
            CpkUtils.send(this.getResponse(), zip.getZipInputStream(), MimeTypes.ZIP, attachmentName, true);
        }
    } catch (FileSystemException ex) {
        logger.error("Failed sending files from kettle result.", ex);
    }
}