if (isDownloadUebersicht && selectedItems != null && selectedItems.length == 1) { if ( (selectedItems[0].getClass() == DownloadMainNode.class && ( (DownloadMainNode) selectedItems[0]).getType() == DownloadMainNode.ROOT_NODE) || (selectedItems[0].getClass() == DownloadSourceDO.class)) { item7.setVisible(true); if (selectedItems[0].getClass() != DownloadSourceDO.class) { item4.setVisible(true); item5.setVisible(true);
if (selectedItems != null) { if (selectedItems.length == 1) { if ( (selectedItems[0].getClass() == DownloadMainNode.class && ( (DownloadMainNode) selectedItems[0]). getType() == DownloadMainNode.ROOT_NODE) || (selectedItems[0].getClass() == DownloadSourceDO.class)) { item7.setVisible(true); if (selectedItems[0].getClass() != DownloadSourceDO.class) { item4.setVisible(true); item5.setVisible(true); } } } else { for (int i = 0; i < selectedItems.length; i++) { if ( (selectedItems[i].getClass() == DownloadMainNode.class && ( (DownloadMainNode) selectedItems[i]). getType() == DownloadMainNode.ROOT_NODE)) { item5.setVisible(true); }
    private void init() throws Exception {        setLayout(new BorderLayout());        JPanel topPanel = new JPanel();        topPanel.setLayout(new GridBagLayout());        JPanel bottomPanel = new JPanel();        bottomPanel.setLayout(new BorderLayout());        item1 = new JMenuItem("Abbrechen");        item2 = new JMenuItem("Pause/Fortsetzen");        item4 = new JMenuItem("Umbenennen");        item5 = new JMenuItem("Zielordner ndern");        item6 = new JMenuItem("Fertige bertragungen entfernen");        item7 = new JMenuItem("Partliste anzeigen");        popup.add(item1);        popup.add(item2);        popup.add(item4);        popup.add(item5);        popup.add(item6);        popup.add(itemCopyToClipboard);        popup.add(item7);        item7.setVisible(false);        itemCopyToClipboard.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent ae) {                Object[] selectedItems = getSelectedDownloadItems();                if (selectedItems != null && selectedItems.length == 1) {                    Clipboard cb = Toolkit.getDefaultToolkit().                        getSystemClipboard();                    StringBuffer toCopy = new StringBuffer();                    toCopy.append("ajfsp://file|");                    if (selectedItems[0].getClass() == DownloadMainNode.class                        &&                        ( (DownloadMainNode) selectedItems[0]).getType() ==                        DownloadMainNode.ROOT_NODE) {                        DownloadDO downloadDO = ( (DownloadMainNode)                                                 selectedItems[0]).                            getDownloadDO();                        toCopy.append(downloadDO.getFilename() + "|" +                                      downloadDO.getHash() + "|" +                                      downloadDO.getGroesse() + "/");                        StringSelection contents = new StringSelection(toCopy.                            toString());                        cb.setContents(contents, null);                    }                    else if (selectedItems[0].getClass() == DownloadSourceDO.class) {                        DownloadSourceDO downloadSourceDO = (DownloadSourceDO)                            selectedItems[0];                        HashMap downloads = ApplejuiceFassade.getInstance().                            getDownloadsSnapshot();                        MapSetStringKey key = new MapSetStringKey(                            downloadSourceDO.getDownloadId());                        DownloadDO downloadDO = (DownloadDO) downloads.get(key);                        if (downloadDO != null) {                            toCopy.append(downloadSourceDO.getFilename() + "|" +                                          downloadDO.getHash() + "|" +                                          downloadDO.getGroesse() + "/");                            StringSelection contents = new StringSelection(                                toCopy.toString());                            cb.setContents(contents, null);                        }                    }                }            }        });        item1.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent ae) {                Object[] selectedItems = getSelectedDownloadItems();                if (selectedItems != null && selectedItems.length != 0) {                    int result = JOptionPane.showConfirmDialog(AppleJuiceDialog.                        getApp(),                        downloadAbbrechen, dialogTitel,                        JOptionPane.YES_NO_OPTION);                    if (result == JOptionPane.YES_OPTION) {                        ArrayList indizesAbbrechen = new ArrayList();                        for (int i = 0; i < selectedItems.length; i++) {                            if (selectedItems[i].getClass() == DownloadMainNode.class) {                                DownloadDO downloadDO = ( (DownloadMainNode)                                    selectedItems[i]).getDownloadDO();                                indizesAbbrechen.add(new Integer(downloadDO.                                    getId()));                            }                        }                        int size = indizesAbbrechen.size();                        if (size > 0) {                            final int[] abbrechen = new int[size];                            for (int i = 0; i < size; i++) {                                abbrechen[i] = ( (Integer) indizesAbbrechen.get(                                    i)).intValue();                            }                            new Thread() {                                public void run() {                                    ApplejuiceFassade.getInstance().                                        cancelDownload(                                        abbrechen);                                    SoundPlayer.getInstance().playSound(                                        SoundPlayer.                                        ABGEBROCHEN);                                }                            }                            .start();                        }                    }                }            }        });        item2.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent ae) {                Object[] selectedItems = getSelectedDownloadItems();                if (selectedItems != null && selectedItems.length != 0 &&                    !powerDownloadPanel.isAutomaticPwdlActive()) {                    ArrayList indizesPausieren = new ArrayList();                    ArrayList indizesFortsetzen = new ArrayList();                    for (int i = 0; i < selectedItems.length; i++) {                        if (selectedItems[i].getClass() == DownloadMainNode.class) {                            DownloadDO downloadDO = ( (DownloadMainNode)                                selectedItems[i]).getDownloadDO();                            if (downloadDO.getStatus() == DownloadDO.PAUSIERT) {                                indizesFortsetzen.add(new Integer(downloadDO.                                    getId()));                            }                            else {                                indizesPausieren.add(new Integer(downloadDO.                                    getId()));                            }                        }                    }                    int size = indizesPausieren.size();                    if (size > 0) {                        final int[] pausieren = new int[size];                        for (int i = 0; i < size; i++) {                            pausieren[i] = ( (Integer) indizesPausieren.get(i)).                                intValue();                        }                        new Thread() {                            public void run() {                                ApplejuiceFassade.getInstance().pauseDownload(                                    pausieren);                            }                        }                        .start();                    }                    size = indizesFortsetzen.size();                    if (size > 0) {                        final int[] fortsetzen = new int[size];                        for (int i = 0; i < size; i++) {                            fortsetzen[i] = ( (Integer) indizesFortsetzen.get(i)).                                intValue();                        }                        new Thread() {                            public void run() {                                ApplejuiceFassade.getInstance().resumeDownload(                                    fortsetzen);                            }                        }                        .start();                    }                }            }        });        item4.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent ae) {                Object[] selectedItems = getSelectedDownloadItems();                if (selectedItems != null && selectedItems.length == 1) {                    if (selectedItems[0].getClass() == DownloadMainNode.class                        &&                        ( (DownloadMainNode) selectedItems[0]).getType() ==                        DownloadMainNode.ROOT_NODE) {                        DownloadDO downloadDO = ( (DownloadMainNode) selectedItems[0]).                            getDownloadDO();                        String neuerName = JOptionPane.showInputDialog(                            AppleJuiceDialog.getApp(), neuerDateiname + ":",                            downloadDO.getFilename());                        if (neuerName == null) {                            return;                        }                        neuerName = neuerName.trim();                        if (neuerName.length() != 0) {                            if (downloadDO.getFilename().compareTo(neuerName)!=0){                                ApplejuiceFassade.getInstance().renameDownload(                                    downloadDO.getId(), neuerName);                            }                        }                    }                }            }        });        item5.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent ae) {                Object[] selectedItems = getSelectedDownloadItems();                if (selectedItems != null && selectedItems.length == 1) {                    if (selectedItems[0].getClass() == DownloadMainNode.class                        &&                        ( (DownloadMainNode) selectedItems[0]).getType() ==                        DownloadMainNode.ROOT_NODE) {                        DownloadDO downloadDO = ( (DownloadMainNode) selectedItems[0]).                            getDownloadDO();                        String neuerName = JOptionPane.showInputDialog(                            AppleJuiceDialog.getApp(), neuesVerzeichnis + ":",                            downloadDO.getTargetDirectory());                        if (neuerName == null) {                            return;                        }                        else{                            neuerName = neuerName.trim();                            if (neuerName.indexOf(File.separator)==0 ||                                neuerName.indexOf(ApplejuiceFassade.separator)==0 ){                                neuerName = neuerName.substring(1);                            }                        }                        if (downloadDO.getTargetDirectory().compareTo(neuerName)!=0){                            ApplejuiceFassade.getInstance().setTargetDir(                                downloadDO.getId(), neuerName);                        }                    }                }            }        });        item6.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent ae) {                ApplejuiceFassade.getInstance().cleanDownloadList();            }        });        item7.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent ae) {                Object[] selectedItems = getSelectedDownloadItems();                if (selectedItems != null && selectedItems.length == 1) {                    if (selectedItems[0].getClass() == DownloadMainNode.class                        &&                        ( (DownloadMainNode) selectedItems[0]).getType() ==                        DownloadMainNode.ROOT_NODE) {                        downloadPartListWatcher.setDownloadNode(selectedItems[0]);                    }                    else if (selectedItems[0].getClass() == DownloadSourceDO.class) {                        downloadPartListWatcher.setDownloadNode(selectedItems[0]);                    }                }            }        });        GridBagConstraints constraints = new GridBagConstraints();        constraints.anchor = GridBagConstraints.NORTH;        constraints.fill = GridBagConstraints.BOTH;        constraints.gridx = 0;        constraints.gridy = 0;        constraints.gridwidth = 3;        constraints.gridheight = 1;        JPanel tempPanel = new JPanel();        tempPanel.setLayout(new BorderLayout());        tempPanel.add(linkLabel, BorderLayout.WEST);        tempPanel.add(downloadLink, BorderLayout.CENTER);        tempPanel.add(btnStartDownload, BorderLayout.EAST);        topPanel.add(tempPanel, constraints);        constraints.gridwidth = 3;        constraints.gridx = 0;        constraints.gridy = 1;        constraints.weighty = 1;        constraints.weightx = 1;        downloadLink.addKeyListener(new KeyAdapter() {            public void keyPressed(KeyEvent ke) {                if (ke.getKeyCode() == KeyEvent.VK_ENTER) {                    btnStartDownload.doClick();                }            }        });        downloadModel = new DownloadModel();        downloadTable = new JTreeTable(downloadModel);        DownloadTableCellRenderer renderer = new DownloadTableCellRenderer();        for (int i = 1; i < downloadTable.getColumnModel().getColumnCount(); i++) {            downloadTable.getColumnModel().getColumn(i).setCellRenderer(                renderer);        }        btnStartDownload.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent ae) {                startDownload();            }        });        aScrollPane = new JScrollPane(downloadTable);        aScrollPane.setBackground(downloadTable.getBackground());        downloadTable.getTableHeader().setBackground(downloadTable.            getBackground());        aScrollPane.getViewport().setOpaque(false);        downloadTable.addMouseListener(new MouseAdapter() {            public void mouseClicked(MouseEvent e) {                super.mouseClicked(e);                if (!DownloadRootNode.isInitialized()) {                    return;                }                Point p = e.getPoint();                int selectedRow = downloadTable.rowAtPoint(p);                Object node = ( (TreeTableModelAdapter) downloadTable.getModel()).                    nodeForRow(selectedRow);                if (downloadTable.columnAtPoint(p) != 0) {                    if (e.getClickCount() == 2) {                        ( (TreeTableModelAdapter) downloadTable.getModel()).                            expandOrCollapseRow(selectedRow);                    }                }                if (node.getClass() == DownloadMainNode.class                    &&                    ( (DownloadMainNode) node).getType() ==                    DownloadMainNode.ROOT_NODE) {                    if (!powerDownloadPanel.isAutomaticPwdlActive()) {                        powerDownloadPanel.btnPdl.setEnabled(true);                    }                    downloadDOOverviewPanel.enableHoleListButton(true);                }                else if (node.getClass() == DownloadSourceDO.class) {                    if (!powerDownloadPanel.isAutomaticPwdlActive()) {                        powerDownloadPanel.btnPdl.setEnabled(true);                    }                    downloadDOOverviewPanel.enableHoleListButton(true);                }                else {                    powerDownloadPanel.btnPdl.setEnabled(false);                    downloadDOOverviewPanel.enableHoleListButton(false);                }            }            public void mousePressed(MouseEvent me) {                super.mousePressed(me);                maybeShowPopup(me);            }            public void mouseReleased(MouseEvent e) {                super.mouseReleased(e);                maybeShowPopup(e);            }            private void maybeShowPopup(MouseEvent e) {                if (!DownloadRootNode.isInitialized()) {                    return;                }                if (e.isPopupTrigger()) {                    Point p = e.getPoint();                    int selectedRow = downloadTable.rowAtPoint(p);                    int[] currentSelectedRows = downloadTable.getSelectedRows();                    for (int i = 0; i < currentSelectedRows.length; i++) {                        if (currentSelectedRows[i] == selectedRow) {                            selectedRow = -1;                            break;                        }                    }                    if (selectedRow != -1) {                        downloadTable.setRowSelectionInterval(selectedRow,                            selectedRow);                    }                    Object[] selectedItems = getSelectedDownloadItems();                    item4.setVisible(false);                    item5.setVisible(false);                    item7.setVisible(false);                    if (isDownloadUebersicht && selectedItems != null &&                        selectedItems.length == 1) {                        if ( (selectedItems[0].getClass() == DownloadMainNode.class                              &&                              ( (DownloadMainNode) selectedItems[0]).getType() ==                              DownloadMainNode.ROOT_NODE)                            || (selectedItems[0].getClass() == DownloadSourceDO.class)) {                            item7.setVisible(true);                            if (selectedItems[0].getClass() != DownloadSourceDO.class) {                                item4.setVisible(true);                                item5.setVisible(true);                            }                        }                    }                    popup.show(downloadTable, e.getX(), e.getY());                }            }        });        topPanel.add(aScrollPane, constraints);        bottomPanel.add(powerDownloadPanel, BorderLayout.WEST);        bottomPanel.add(downloadDOOverviewPanel, BorderLayout.CENTER);        add(topPanel, BorderLayout.CENTER);        add(bottomPanel, BorderLayout.SOUTH);        SortButtonRenderer renderer2 = new SortButtonRenderer();        TableColumnModel model = downloadTable.getColumnModel();        int n = model.getColumnCount();        for (int i = 0; i < n; i++) {            model.getColumn(i).setHeaderRenderer(renderer2);        }        JTableHeader header = downloadTable.getTableHeader();        header.addMouseListener(new SortMouseAdapter(header, renderer2));        downloadTable.setSelectionMode(ListSelectionModel.                                       MULTIPLE_INTERVAL_SELECTION);        ApplejuiceFassade.getInstance().addDataUpdateListener(this,            DataUpdateListener.DOWNLOAD_CHANGED);    }