⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gantttreetable.java

📁 It is all about project scheduling. GanttProject is a tool for creating a project schedule by means
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                        .undoableEdit("displayAllColumns", new Runnable() {                            public void run() {                                displayAllColumns();                            }                        });            }        });        /*         * To delete a custom column the user has to right click on the column         * header. If the colum header match with a custom column the menu item         * will be enable. Otherwise it is disable.         */        jmiDeleteColumn = new JMenuItem(language.getText("deleteCustomColumn"));        jmiDeleteColumn.setIcon(new ImageIcon(getClass().getResource(                "/icons/removeCol_16.gif")));        jmiDeleteColumn.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                Mediator.getGanttProjectSingleton().getUndoManager()                        .undoableEdit("deleteCustomColumn", new Runnable() {                            public void run() {                                // deleteCustomColumn(getTable().getColumnName(getTable().columnAtPoint(clickPoint)));                                int ind = getTable().columnAtPoint(clickPoint);                                if (ind >= 0) {                                    Mediator.getCustomColumnsManager()                                            .deleteCustomColumn(                                                    getTable().getColumnName(                                                            ind));                                    jmiDeleteColumn.setEnabled(false);                                }                            }                        });            }        });        jmiDeleteColumn.setEnabled(false);        popupMenu.add(jmiDisplayAll);        popupMenu.addSeparator();        popupMenu.add(jmiAddColumn);        popupMenu.add(jmiDeleteColumn);    }    /**     * Rename the MenuItem named <code>oldName</code> intor     * <code>newName</code>.     *      * @param oldName     *            MenuItem old name.     * @param newName     *            MenuItem new name.     */    private void renameMenuItem(String oldName, String newName) {        Component[] t = popupMenu.getComponents();        JCheckBoxMenuItem jcbmi = null;        for (int i = 0; i < t.length; i++) {            if (t[i] instanceof JCheckBoxMenuItem) {                jcbmi = (JCheckBoxMenuItem) t[i];                if (jcbmi.getText().equals(oldName)) {                    jcbmi.setText(newName);                    break;                }            }        }        if (jcbmi != null) {            mapColNameMenuItem.remove(oldName);            mapColNameMenuItem.put(newName, jcbmi);        }    }    /**     * Displays all the table columns.     */    private void displayAllColumns() {        Iterator it = mapTableColumnColumnKeeper.values().iterator();        while (it.hasNext()) {            ColumnKeeper ck = (ColumnKeeper) it.next();            if (!ck.isShown)                ck.show();        }        // createPopupMenu();    }    /**     * Displays all the table columns.     */    private void hideAllColumns() {        Iterator it = mapTableColumnColumnKeeper.values().iterator();        while (it.hasNext()) {            ColumnKeeper ck = (ColumnKeeper) it.next();            if (ck.isShown)                ck.hide();        }        // createPopupMenu();    }    /**     * Display the column whose name is given in parameter.     *      * @param name     *            Name of the column to display.     */    private void displayColumn(String name) {        int indexView = -1;        int width = -1;        Iterator itDc = this.listDisplayedColumns.iterator();        while (itDc.hasNext()) {            DisplayedColumn dc = (DisplayedColumn) itDc.next();            if (getNameForId(dc.getID()).equals(name)) {                indexView = dc.getOrder();                width = dc.getWidth();            }        }        Iterator it = mapTableColumnColumnKeeper.keySet().iterator();        while (it.hasNext()) {            TableColumn c = (TableColumn) it.next();            String n = (String) c.getHeaderValue();            if (n.equals(name)) {                ColumnKeeper ck = (ColumnKeeper) mapTableColumnColumnKeeper                        .get(c);                if (indexView != -1)                    ck.index = indexView;                if (!ck.isShown)                    ck.show();                break;            }        }        getTable().getColumnExt(name).setPreferredWidth(width);        // createPopupMenu();    }    private void hideColumn(String name) {        Iterator it = mapTableColumnColumnKeeper.keySet().iterator();        while (it.hasNext()) {            TableColumn c = (TableColumn) it.next();            String n = (String) c.getHeaderValue();            if (n.equals(name)) {                ColumnKeeper ck = (ColumnKeeper) mapTableColumnColumnKeeper                        .get(c);                if (ck.isShown)                    ck.hide();                break;            }        }        // createPopupMenu();    }    /**     * Adds a new custom column. The custom column will affect all tasks and     * future tasks. Several types are available for the custom columns (string,     * date, integer, double, boolean). A default value is also set.     */    public void addNewCustomColumn(CustomColumn customColumn) {        if (customColumn == null) {            customColumn = new CustomColumn();            GanttDialogCustomColumn d = new GanttDialogCustomColumn(Mediator                    .getGanttProjectSingleton().getUIFacade(), customColumn);            d.setVisible(true);        }        if (customColumn.getName() != null) // if something has been entered        {            GanttTreeTableModel treeTableModel = (GanttTreeTableModel) getTreeTableModel();            int nbCol = treeTableModel.getColumnCountTotal(); // +            // treeTableModel.getCustomColumnCount();            String newName = customColumn.getName();            ((GanttTreeTableModel) ttModel).addCustomColumn(newName);            try {                Mediator.getCustomColumnsStorage()                        .addCustomColumn(customColumn);            } catch (CustomColumnsException ex) {                if (ex.getType() == CustomColumnsException.ALREADY_EXIST)                    addNewCustomColumn(null);                return;            }            TaskContainmentHierarchyFacade tchf = Mediator                    .getGanttProjectSingleton().getTaskManager()                    .getTaskHierarchy();            setCustomColumnValueToAllNestedTask(tchf, tchf.getRootTask(),                    customColumn.getName(), customColumn.getDefaultValue());            TableColumnExt t = new TableColumnExt(nbCol);            t.setMaxWidth(500);            t.setHeaderValue(newName);            getTable().getColumnModel().addColumn(t);            try {                if (clickPoint != null)                    getTable().getColumnModel().moveColumn(                            getTable().getColumnCount() - 1,                            getTable().columnAtPoint(clickPoint));            } catch (IllegalArgumentException e) {                e.printStackTrace();            }            int align = SwingConstants.CENTER;            if (customColumn.getType().equals(GregorianCalendar.class))                align = SwingConstants.RIGHT;            setColumnHorizontalAlignment(newName, align);            DisplayedColumn dc = new DisplayedColumn(Mediator                    .getCustomColumnsStorage().getIdFromName(newName));            dc.setDisplayed(true);            dc.setOrder(getTable().convertColumnIndexToView(                    getColumn(newName).getModelIndex()));            dc.setWidth(getColumn(newName).getPreferredWidth());            this.listDisplayedColumns.add(dc);            if (GregorianCalendar.class                    .isAssignableFrom(customColumn.getType()))                getTable().getColumnExt(newName).setCellEditor(newDateCellEditor());            //            JCheckBoxMenuItem jcbmi = new JCheckBoxMenuItem(newName);            jcbmi.setSelected(true);            ColumnKeeper ck = new ColumnKeeper(t);            jcbmi.addActionListener(ck);            mapColNameMenuItem.put(newName, jcbmi);            mapTableColumnColumnKeeper.put(t, ck);            // popupMenu.insert(jcbmi, popupMenu.getSubElements().length - 3);            //            Mediator.getGanttProjectSingleton().setAskForSave(true);        }        Runnable t = new Runnable() {            public void run() {                calculateWidth();                revalidate();            }        };        SwingUtilities.invokeLater(t);    }    /**     * Delete permanently a custom column.     *      * @param name     *            Name of the column to delete.     */    public void deleteCustomColumn(String name) {        try {            Mediator.getCustomColumnsStorage().getCustomColumn(name);        } catch (CustomColumnsException e) {            // e.printStackTrace();            return;        }        // the column has to be displayed to be removed.        this.displayColumn(name);        // DisplayedColumns        DisplayedColumn toDel = null;        Iterator it = listDisplayedColumns.iterator();        while (it.hasNext()) {            DisplayedColumn dc = (DisplayedColumn) it.next();            if (getNameForId(dc.getID()).equals(name))                toDel = dc;        }        if (toDel != null)            listDisplayedColumns.remove(toDel);        int index = getTable().getColumnModel().getColumnIndex(name);        int modelIndex = getTable().convertColumnIndexToModel(index);        TableColumnModelEvent tcme = new TableColumnModelEvent(getTable()                .getColumnModel(), modelIndex, modelIndex);        getTable().removeColumn(getTable().getColumnExt(name));        getTable().columnRemoved(tcme);        /*         * TODO There is a problem here : I don't remove the custom column from         * the treetablemodel. If I remove it there will be a problem when         * deleting a custom column if it isn't the last created.         */        // TreeTableModel        ttModel.deleteCustomColumn(name);        // CustomColumnsStorage level        Mediator.getCustomColumnsStorage().removeCustomColumn(name);        // Every tasks        TaskContainmentHierarchyFacade tchf = Mediator                .getGanttProjectSingleton().getTaskManager().getTaskHierarchy();        tchf.getRootTask().getCustomValues().removeCustomColumn(name);        removeCustomColumnToAllNestedTask(tchf, tchf.getRootTask(), name);        // MenuItem        popupMenu.remove(popupMenu                .getComponentIndex((Component) mapColNameMenuItem.get(name)));        mapColNameMenuItem.remove(name);        // newBB        Iterator it2 = mapTableColumnColumnKeeper.keySet().iterator();        while (it2.hasNext()) {            TableColumn c = (TableColumn) it2.next();            String n = (String) c.getHeaderValue();            if (n.equals(name)) {                mapTableColumnColumnKeeper.remove(c);                break;            }        }        Mediator.getGanttProjectSingleton().setAskForSave(true);    }    public void renameCustomcolumn(String name, String newName) {        Mediator.getGanttProjectSingleton().setAskForSave(true);        this.displayColumn(name);        TableColumnExt tc = (TableColumnExt) getTable().getColumn(name);        tc.setTitle(newName);        Mediator.getGanttProjectSingleton().repaint();        renameMenuItem(name, newName);        TaskContainmentHierarchyFacade tchf = Mediator                .getGanttProjectSingleton().getTaskManager().getTaskHierarchy();        tchf.getRootTask().getCustomValues().renameCustomColumn(name, newName);        renameCustomColumnForAllNestedTask(tchf, tchf.getRootTask(), name,                newName);        ttModel.renameCustomColumn(name, newName);        // newBB        Iterator it = mapTableColumnColumnKeeper.keySet().iterator();        while (it.hasNext()) {            TableColumn c = (TableColumn) it.next();            String n = (String) c.getHeaderValue();            if (n.equals(name)) {                ColumnKeeper ck = (ColumnKeeper) mapTableColumnColumnKeeper                        .get(c);                ((TableColumnExt) c).setTitle(newName);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -