📄 accreditgroupmodel.java
字号:
.println("---ERROR--- Could not get cpl destination paths for group "
+ group
+ "\n---ERROR--- Probably, the group does not exist in the ListOfFeatureServers"
+ "\n---ERROR--- Or there is no server configured for this feature.");
return;
}
String filename = userName + ".cpl";
String filegroup;
for (int i = 1; i < calledPaths.length; i++) {
filegroup = calledPaths[i];
psInterface.put(filegroup, filename, calledCpl);
filegroup = calledPaths[i].replaceFirst("Called", "Calling");
psInterface.put(filegroup, filename, callingCpl);
}
}
public Vector loadUserAt(int row) throws SAXException, IOException,
VPPException {
Vector groupData = (Vector) data.elementAt(row);
// if there is one element in the data vector for the selected user,
// this
// means that only the user's name has been loaded, not his xml file
if (groupData.size() <= 1) {
// find the name of the user in the selected row
String userName = (String) groupData
.elementAt(AccreditGroupModel.GROUP_NAME);
// load the user's xml file fron the pserver
Document doc = psInterface.getGroupNamed(userName);
// convert the xml to a vector
groupData = convertGroupToVector(doc);
// save the vector in the appropriate row
data.set(row, groupData);
fireTableDataChanged();
}
return groupData;
}
/**
* Return a new vector which contains the "default" configuration for a
* user.
* <p>
* This is used when adding a new user to the system
*/
public Vector getDummyGroup() {
return (Vector) dummyGroup.clone();
}
public Vector getGroupAt(int row) {
return (Vector) data.elementAt(row);
}
private Vector createAliasVector(String name, String masterName) {
Vector alias = new Vector(this.MAX_COLUMN_ID);
for (int j = 0; j <= this.MAX_COLUMN_ID; j++) {
alias.addElement("");
}
alias.set(this.GROUP_NAME, name);
alias.set(this.IS_ALIAS, "true");
alias.set(this.MASTER_NAME, masterName);
alias.set(this.MASTER_INDEX, null);
return alias;
}
public void showAliases(boolean show) {
isShowingAliases = show;
if (show) {
if (aliasesLoadedFromServer) {
// if the aliases have been loaded from the server
// add them to the main data vector
for (int i = 0; i < aliases.size(); i++) {
data.addElement(aliases.elementAt(i));
}
this.fireTableDataChanged();
} else {
// if the aliases have not been loaded from the server
String[] aliasNames;
try {
aliasNames = psInterface.getAllAliasNames();
} catch (VPPNoSuchFileException e) {
// there are no aliases defined - that's ok
return;
}
for (int i = 0; i < aliasNames.length; i++) {
try {
// get the file for this alias
String aliasXml = psInterface
.getAliasNamed(aliasNames[i]);
// get the master user name this alias belongs to
String masterName = psInterface
.getMasterUserNameFromXml(aliasXml);
// create a new vector for this alias
Vector alias = createAliasVector(aliasNames[i],
masterName);
// add the vector to the list of aliases and to the main
// data vector
// If a new user was created along with some aliases,
// before others
// were loaded from the server, these may have already
// been added to
// the aliases vector
boolean found = false;
for (int j = 0; j < aliases.size(); j++) {
Vector aliasVector = (Vector) aliases.elementAt(j);
String aliasName = (String) aliasVector
.elementAt(this.GROUP_NAME);
if (aliasName.equals(aliasNames[i])) {
found = true;
break;
}
}
if (!found) {
aliases.addElement(alias);
}
data.addElement(alias);
} catch (VPPNoSuchFileException e) {
e.printStackTrace();
// this shouldn't have happenend. It was just found out
// above that
// a file with this name exists ... so we'll just
// quietly suppress
// this expception
}
this.fireTableDataChanged();
aliasesLoadedFromServer = true;
}
}
sortByGroupName();
} else {
// if the aliases have been loaded, remove them from the main data
// list
if (aliases.size() != 0) {
for (int i = 0; i < aliases.size(); i++) {
Object alias = aliases.elementAt(i);
data.remove(alias);
}
fireTableDataChanged();
}
}
}
public int findMasterIndex(String masterName) {
for (int i = 0; i < data.size(); i++) {
String name = (String) getValueAt(i, this.GROUP_NAME);
if (name.equals(masterName)) {
return i;
}
}
return -1; // let's hope it doesn't get here
}
/**
* Returns the array which stores the information about column width and
* title
*/
public ColumnInfo[] getColumns() {
return columns;
}
public String getColumnName(int column) {
System.out.println(column);
System.out.println(columns[column].getName());
return columns[column].getName();
}
/**
* Performs a binary search and relies on the fact that the list of users in
* the table will be sorted from lowest to highest.
*/
public int findRowStartingWithName(String substring) {
int low = 0;
int high = data.size() - 1; // index, not count
int mid = 0;
while (low <= high) {
mid = (low + high) / 2;
Vector user = (Vector) data.elementAt(mid);
String userName = (String) user.elementAt(this.GROUP_NAME);
if (substring.compareTo(userName) > 0) {
low = mid + 1;
} else if (substring.compareTo(userName) < 0) {
// because, for example, 4 < 4000. Otherwise, the closest match
// ends up
// being 3999
if (userName.startsWith(substring)) {
if (mid > 0) {
Vector previousUser = (Vector) data.elementAt(mid - 1);
String previousName = (String) previousUser
.elementAt(this.GROUP_NAME);
if (substring.compareTo(previousName) > 0) {
return mid;
}
}
}
high = mid - 1;
} else {
return mid;
}
}
return mid;
}
public void sortByGroupName() {
java.util.Collections.sort(data, new NameComparator());
}
private class NameComparator implements java.util.Comparator {
public int compare(Object object1, Object object2) {
String name1 = (String) ((Vector) object1)
.elementAt(AccreditGroupModel.GROUP_NAME);
String name2 = (String) ((Vector) object2)
.elementAt(AccreditGroupModel.GROUP_NAME);
return name1.compareTo(name2);
}
}
public void setValueAt(String value, int row, int column)
throws VPPException, IOException, SAXException {
Vector user = (Vector) data.elementAt(row);
// if the data being set is the list of aliases, need to do some extra
// work:
// need to determine whether any aliases for this user were created or
// removed so that the overall list of aliases in the table is also
// appropriately updated
if (column == this.ALIASES) {
Vector newAliases = new Vector();
Vector oldAliases = new Vector();
String currentAliases = (String) user.elementAt(this.ALIASES);
StringTokenizer tokenizer = new StringTokenizer(currentAliases, ";");
while (tokenizer.hasMoreTokens()) {
oldAliases.addElement(tokenizer.nextToken());
}
tokenizer = new StringTokenizer(value, ";");
while (tokenizer.hasMoreElements()) {
newAliases.addElement(tokenizer.nextToken());
}
// find out if any aliases have been removed (old aliases contain an
// element the new ones don't)
for (int j = 0; j < oldAliases.size(); j++) {
String alias = (String) oldAliases.elementAt(j);
if (!newAliases.contains(alias)) // then the alias has been
// removed
{
// find the vector for this alias
for (int i = 0; i < aliases.size(); i++) {
Vector aliasVector = (Vector) aliases.elementAt(i);
String aliasName = (String) aliasVector
.elementAt(this.GROUP_NAME);
if (aliasName.equals(alias)) // if this is the alias
// that has been deleted
{
// remove it from the list of aliases and the master
// list
aliases.remove(aliasVector);
if (data.contains(aliasVector)) {
data.remove(aliasVector);
}
} // end if names match
} // end for all alias vectors
} // end if alias has been removed
} // end for all old aliases
// now see if there have been any aliases added -> are in the new
// list but not the old one
for (int i = 0; i < newAliases.size(); i++) {
String alias = (String) newAliases.elementAt(i);
if (!oldAliases.contains(alias)) // the alias has been added
{
Vector newAlias = this.createAliasVector(alias,
(String) user.elementAt(this.GROUP_NAME));
aliases.add(newAlias);
if (isShowingAliases) {
data.addElement(newAlias);
}
}
}
}
// Load the data for this user. If the data is being set, it has changed
// and it is assumed it will be written back. Since the entire data set
// has
// to be written at once, it must be completely loaded before it is
// written
// back. It is loaded here, before the new values are set, so that they
// are
// not overwritten later by data from the server
if (user.size() <= 1) // if data for this user has not been loaded yet
{
user = loadUserAt(row);
}
user.set(column, value);
// can't sort ailases into table here because the user data may not have
// been completely saved yet and sorting may change the row which the
// user
// being saved is at which will produce the wrong result.
}
public Object getValueAt(int row, int column) {
Vector user = (Vector) data.elementAt(row);
if (column == GROUP_NAME) // name should always be available
{
return (String) user.elementAt(GROUP_NAME);
}
/*
if (column == USER_PASSWD)
{
return (String) user.elementAt(USER_PASSWD);
}
*/
// if the user's data vector contains only one element, the xml has not
// been
// loaded yet
if (user.size() <= 1) {
return "";
}
String value = (String) user.elementAt(column);
return value;
}
public Class getColumnClass(int columnIndex) {
if (Boolean.class.isInstance(getValueAt(0, columnIndex))) {
return Boolean.class;
}
return String.class;
}
public int getRowCount() {
return data.size();
}
public int getColumnCount() {
return columns.length;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -