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

📄 resourcetreetablemodel.java

📁 It is all about project scheduling. GanttProject is a tool for creating a project schedule by means
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        updateLineNumber();        return true;    }    public void reset() {        myResourceManager.clear();    }    public List getAllResouces() {        return myResourceManager.getResources();    }    /**     * {@inheritDoc}     */    public int getColumnCount() {        return columns.size();    }    public ArrayList getColumns() {        /*         * we reverse the column order of the enumeration to obtain the correct         * visual order         */        ArrayList res = new ArrayList();        Enumeration e = columns.elements();        while (e.hasMoreElements()) {            res.add(0, e.nextElement());        }        return res;    }    /** Returns the ResourceColumn associated to the given index */    public ResourceColumn getColumn(int index) {        return (ResourceColumn) columns.get(new Integer(index));    }    /**     * {@inheritDoc}     */    public Class getColumnClass(int colIndex) {    	if (colIndex == 0) {            return hierarchicalColumnClass;    	}    	ResourceColumn column = (ResourceColumn)columns.get(new Integer(colIndex));         return column==null ? String.class : column.getType();    }    public String getColumnName(int column) {        return ((ResourceColumn) columns.get(new Integer(column))).getTitle();    }    /**     * @inheritDoc     */    public boolean isCellEditable(Object node, int column) {        return (node instanceof ResourceNode && (column == INDEX_RESOURCE_EMAIL                || column == INDEX_RESOURCE_NAME                || column == INDEX_RESOURCE_PHONE || column == INDEX_RESOURCE_ROLE))                || (node instanceof AssignmentNode                        && (column == INDEX_RESOURCE_ROLE_TASK)                /* assumes the INDEX_RESOURCE_ID is the last mandatory column */                || column > INDEX_RESOURCE_ID);    }    /**     * @inheritDoc     */    public Object getValueAt(Object node, int column) {        Object res = null;        ResourceNode rn = null;        AssignmentNode an = null;         if (node instanceof ResourceNode)            rn = (ResourceNode) node;         else if (node instanceof AssignmentNode)            an = (AssignmentNode) node;        boolean hasChild = rn != null;        switch (column) {        case INDEX_RESOURCE_NAME: // name            if (hasChild) {                res = rn.getName();            } else {                res = an.getTask().getName();            }            break;        case INDEX_RESOURCE_ROLE: // def role            if (hasChild) {                res = rn.getDefaultRole();            } else {                res = "";            }            break;        case INDEX_RESOURCE_EMAIL: // mail            if (hasChild) {                res = rn.getEMail();            } else {                res = "";            }            break;        case INDEX_RESOURCE_PHONE: // phone            if (hasChild) {                res = rn.getPhone();            } else {                res = "";            }            break;        case INDEX_RESOURCE_ROLE_TASK: // assign role            if (hasChild) {                res = "";            } else {                res = an.getRoleForAssigment();            }            break;        case INDEX_RESOURCE_ID: // id            if (hasChild)        		res = new Integer(rn.getId());            else            	res = " - ";            break;        case INDEX_RESOURCE_LINE_NUMBER: //lineNumber        	if (hasChild) {        		res = rn.getLineNumber();        	} else {        		res = an.getLineNumber();        	}        	break;        default: // custom column            if (hasChild) {                res = rn.getCustomField(this.getColumnName(column));            } else                res = "";            break;        }        return res;    }    /**     * @inheritDoc     */    public void setValueAt(Object value, Object node, int column) {        if (isCellEditable(node, column))            switch (column) {            case INDEX_RESOURCE_NAME:                ((ResourceNode) node).setName(value.toString());                break;            case INDEX_RESOURCE_EMAIL:                ((ResourceNode) node).setEMail(value.toString());                break;            case INDEX_RESOURCE_PHONE:                ((ResourceNode) node).setPhone(value.toString());                break;            case INDEX_RESOURCE_ROLE:                ((ResourceNode) node).setDefaultRole((Role) value);                break;            case INDEX_RESOURCE_ROLE_TASK:                ((AssignmentNode) node).setRoleForAssigment((Role) value);                break;            case INDEX_RESOURCE_ID:                /* ID cannot be changed */                break;            case INDEX_RESOURCE_LINE_NUMBER:            	((ResourceNode) node).setLineNumber(value.toString());            	break;            default:                ((ResourceNode) node).setCustomField(                        this.getColumnName(column), value);                break;            }        Mediator.getGanttProjectSingleton().setAskForSave(true);    }    /** Adds a column that cannot be removed afterwards. */    public void addMandatoryColumn(ResourceColumn col) {        columns.put(new Integer(col.getIndex()), col);    }    /** Adds a custom column (which is removable) to the datamodel */    public void addCustomColumn(String title, ResourceColumn col)            throws Exception {        if (((HumanResourceManager) myResourceManager).checkCustomField(title))            /* TODO add translation */            throw (new Exception("Column exists"));        ((HumanResourceManager) myResourceManager).addCustomField(title, col                .getDefaultVal());        columns.put(new Integer(index), col);    }    /** deletes a custom column from the datamodel */    public ResourceColumn deleteCustomColumn(String name) {        ResourceColumn toDel = null;        Collection vals = columns.values();        Iterator i = vals.iterator();        while (i.hasNext()) {            toDel = (ResourceColumn) i.next();            if (name.equals(toDel.getTitle())) {                ((HumanResourceManager) myResourceManager)                        .removeCustomField(toDel.getTitle());                /* this deletes the object from the Hashtable too */                vals.remove(toDel);                return toDel;            }        }        return null;    }    /** checks if the given column is removable */    public boolean checkRemovableCol(String name) {        /* only custom columns are removable */        return ((HumanResourceManager) myResourceManager)                .checkCustomField(name);    }    public void resourceChanged(ProjectResource resource) {        ResourceNode node = getNodeForResource(resource);        if (node == null) {            return;        }        TreeNode parent = node.getParent();        int index = parent.getIndex(node);        assert index >= 0;        nodesChanged(parent, new int[] { index });    }        public void resourceAssignmentsChanged(ProjectResource[] resources) {        for (int i=0; i<resources.length; i++) {            ResourceNode nextNode = exists(resources[i]);            buildAssignmentsSubtree(nextNode);        }    }    	/** 	 * It updates the line number of 	 * the resources and their assignments.	 */    public void updateLineNumber() {		List res = myResourceManager.getResources();					int lineCounter = 1;		for (Iterator i=res.iterator();i.hasNext();){			HumanResource resource = (HumanResource) i.next();			ResourceAssignment[] tra = resource.getAssignments();			ResourceNode resNode = exists(resource);						String lineNumber = lineCounter + "";			resource.setLineNumber(lineNumber);			lineCounter++;						if ( resNode == null){				resNode = new ResourceNode(resource);			}			for(int k=0; k<tra.length; k++){				AssignmentNode an = exists(resNode, tra[k]);				lineNumber = lineCounter + "";				an.setLineNumber(lineNumber);				lineCounter++;			}		}		}        private void buildAssignmentsSubtree(ResourceNode resourceNode) {        ProjectResource resource = resourceNode.getResource();        resourceNode.removeAllChildren();        ResourceAssignment[] assignments = resource.getAssignments();        int[] indices = new int[assignments.length];        TreeNode[] children = new TreeNode[assignments.length];        if (assignments.length>0) {            for (int i = 0; i < assignments.length; i++) {                indices[i] = i;                AssignmentNode an = new AssignmentNode(assignments[i]);                children[i] = an;                resourceNode.add(an);            }        }        fireTreeStructureChanged(this, resourceNode.getPath(), indices, children);            }    }

⌨️ 快捷键说明

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