public Object getValueAt(int rowIndex, int columnIndex) {
if (columnIndex == 0) {
return rowIndex+1;
}
COOJAProject p = currentProjects.get(rowIndex);
if (!p.directoryExists()) {
return p + " (not found)";
}
if (!p.configExists()) {
return p + " (no config)";
}
if (!p.configRead()) {
return p + " (config error)";
}
return p;
}
});
table.setFillsViewportHeight(true);
table.setTableHeader(null);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (table.getSelectedRow() < 0) {
return;
}
selectTreeProject(currentProjects.get(table.getSelectedRow()));
showProjectInfo(currentProjects.get(table.getSelectedRow()));
}
});
table.getColumnModel().getColumn(0).setPreferredWidth(30);
table.getColumnModel().getColumn(0).setMaxWidth(30);
table.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {
private static final long serialVersionUID = 7224219223448831880L;
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
if (currentProjects.get(row).hasError()) {
setBackground(Color.RED);
} else {
setBackground(table.getBackground());
}
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
row, column);
}
});
/* Add current extensions */
for (COOJAProject project : projects) {
addProjectDir(project);
}
Box mainPane = Box.createVerticalBox();
Box buttonPane = Box.createHorizontalBox();
JPanel sortPane;
JButton button;
/* Lower buttons */
{
buttonPane.setBorder(BorderFactory.createEmptyBorder(0,3,3,3));
buttonPane.add(Box.createHorizontalGlue());
button = new JButton("View config");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
/* Default config */
ProjectConfig config = new ProjectConfig(true);
/* Merge configs */
for (COOJAProject project : getProjects()) {
config.appendConfig(project.config);
}
ConfigViewer.showDialog(ProjectDirectoriesDialog.this, config);
} catch (Exception ex) {
logger.fatal("Error when merging config: " + ex.getMessage(), ex);
return;
}
}
});
buttonPane.add(button);
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
button = new JButton("Cancel");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ProjectDirectoriesDialog.this.returnedProjects = null;
dispose();
}
});
buttonPane.add(button);
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
button = new JButton("Apply for session");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ProjectDirectoriesDialog.this.returnedProjects = currentProjects.toArray(new COOJAProject[0]);
dispose();
}
});
buttonPane.add(button);
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
button = new JButton("Save");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object[] options = { "Ok", "Cancel" };
String newDefaultProjectDirs = "";
for (COOJAProject p: currentProjects) {
if (newDefaultProjectDirs != "") {
newDefaultProjectDirs += ";";
}
newDefaultProjectDirs += gui.createPortablePath(p.dir, false).getPath();
}
newDefaultProjectDirs = newDefaultProjectDirs.replace('\\', '/');
String question = "External tools setting DEFAULT_PROJECTDIRS will change from:\n"
+ GUI.getExternalToolsSetting("DEFAULT_PROJECTDIRS", "").replace(';', '\n')
+ "\n\n to:\n\n"
+ newDefaultProjectDirs.replace(';', '\n');
String title = "Change external tools settings?";
int answer = JOptionPane.showOptionDialog(ProjectDirectoriesDialog.this, question, title,
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null,
options, options[0]);
if (answer != JOptionPane.YES_OPTION) {
return;
}
GUI.setExternalToolsSetting("DEFAULT_PROJECTDIRS", newDefaultProjectDirs);
dispose();
}
});
buttonPane.add(button);
this.getRootPane().setDefaultButton(button);
}
/* Center: Tree and list*/
{
treePanel = new DirectoryTreePanel(this);
sortPane = new JPanel(new BorderLayout());
button = new JButton("Move up");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int selectedIndex = table.getSelectedRow();
if (selectedIndex <= 0) {
return;
}
COOJAProject project = currentProjects.get(selectedIndex);
removeProjectDir(project);
addProjectDir(project, selectedIndex - 1);
table.getSelectionModel().setSelectionInterval(selectedIndex - 1, selectedIndex - 1);
}
});
sortPane.add(BorderLayout.NORTH, button);
button = new JButton("Move down");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int selectedIndex = table.getSelectedRow();
if (selectedIndex < 0) {
return;
}
if (selectedIndex >= currentProjects.size() - 1) {
return;
}
COOJAProject project = currentProjects.get(selectedIndex);
removeProjectDir(project);
addProjectDir(project, selectedIndex + 1);
table.getSelectionModel().setSelectionInterval(selectedIndex + 1, selectedIndex + 1);
}
});
sortPane.add(BorderLayout.SOUTH, button);
{
button = new JButton("Remove");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int selectedIndex = table.getSelectedRow();
if (selectedIndex < 0) {
return;
}
if (selectedIndex >= currentProjects.size()) {
return;
}
COOJAProject project = currentProjects.get(selectedIndex);
String s1 = "Remove";
String s2 = "Cancel";
Object[] options = { s1, s2 };
int n = JOptionPane.showOptionDialog(GUI.getTopParentContainer(),