Pessoal, já rodei por vários outros fóruns e ninguém responde. De que adianta termos salas de debate se ninguém quer debater? :evil: Espero que exista um santo aqui que possa me ajudar. :shock:
É o seguinte. Eu tenho um código aqui da criação de uma JTree. Esta minha classe aqui está gerando um ClassNotFoundException. O Problema é que eu nem sei onde, muito menos o porque. Se existir alguém capaz de resolver isso, pelo amor de Deus que o faça!!
Agradeço aqueles que pelo menos tentarem decifrar isto comigo.
valeu mesmo!!!
public class AutFuncao extends javax.swing.JInternalFrame implements TreeSelectionListener,Runnable {
Vector<Funcao> func;
Hashtable<Funcao,Vector<Operacao>> opInHashtable = new Hashtable<Funcao, Vector<Operacao>>();
Vector<Operacao> opInicial;
AcessServico gt = new AcessServico();
JTree tree;
private boolean teste;
private LButtonSelect lButtonTodas;
private LButtonSelect lButtonNenhuma;
/** Creates new form AutFuncao */
public AutFuncao() {
initComponents();
initComponentsLegus();
paintIcons();
this.setSize(800, 500);
atualizar1();
// run();
}
private Vector<Funcao> getFunc() {
return gt.loadFuncoes();
}
private void initComponentsLegus() {
lButtonNenhuma = new LButtonSelect();
lButtonTodas = new LButtonSelect();
lButtonNenhuma.setText("Nenhuma");
lButtonTodas.setText("Todas");
lButtonNenhuma.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
desmarcarAction(e);
}
});
lButtonTodas.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
marcarAction(e);
}
});
jPanel2.add(lButtonTodas);
jPanel2.add(lButtonNenhuma);
}
private void jButtonRestaurarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
restaurarAction(evt);
}
private void jButtonAbandonarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.dispose();
}
private void jButtonSalvarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Vector<SSalvarOpPorFuncao> s = salvar();
boolean b= gt.salvarOpPorFuncao(s);
System.out.println(s.toString()+b);
this.dispose();
}
private void lButtonTodasActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// jButtonMarcarAction(evt);
}
private void lButtonNenhumaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// jButtonDesmarcarAction(evt);
}
private void formMouseMoved(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
//// if (!teste) {
//// run();
//// teste=true;
//// }
}
// Variables declaration - do not modify
private javax.swing.JButton jButtonAbandonar;
private javax.swing.JButton jButtonRestaurar;
private javax.swing.JButton jButtonSalvar;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanelFuncao;
private javax.swing.JPanel jPanelOperacao;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
// End of variables declaration
public void start(String[] params) {
run();
}
public void valueChanged(TreeSelectionEvent e) {
TreePath path = tree.getSelectionPath();// ERRO ?
Vector v = null;
if (path == null) {
return;
}
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) path.getLastPathComponent();// ERRO ?
if (!selectedNode.isLeaf()) {
try {
NamedVector nv = (NamedVector)selectedNode.getUserObject();
Funcao f =nv.getFuncao();
} catch (Exception exception) {
System.out.println(exception);
}
}
if (selectedNode.isLeaf()) {
String pai = selectedNode.getParent().toString();
jLabel1.setText("APLICAÇÃO : " + selectedNode.toString());
Aplicacao a = (Aplicacao) selectedNode.getUserObject();
v = a.getOperacaoV();
gerarChekBox(v);
enableSelectButton(true);
} else {
limparPanel(jPanelOperacao, 1);
jLabel1.setText("");
enableSelectButton(false);
}
}
// Método de retorno da arvore
public JTree getTree() {
Vector root = new Vector();
NamedVector v = new NamedVector("FUNÇÕES");
NamedVector funcoes = new NamedVector("");
for (int i = 0; i < func.size(); i++) {
funcoes = new NamedVector(func.get(i).getNome(), func.get(i).getAplicacaos());
v.add(funcoes);
}
root.add(v);
JTree k = new JTree(root);
return k;
}
private void gerarChekBox(Vector<Operacao> opV) {
limparPanel(jPanelOperacao, 1);
lButtonTodas.setOperacoes(opV);
lButtonNenhuma.setOperacoes(opV);
for (int i = 0; i < opV.size(); i++) {
Operacao operacao = opV.get(i);
jPanelOperacao.add(new OperacaoCheckBox(operacao));
}
}
private void marcarAction(ActionEvent e) {
limparPanel(jPanelOperacao, 1);
LButtonSelect button = (LButtonSelect) e.getSource();
Vector<Operacao> operacaos = button.getOperacoes();
for (Operacao operacao : operacaos) {
operacao.setSelected(true);
jPanelOperacao.add(new OperacaoCheckBox(operacao));
}
jPanelOperacao.repaint();
String aux = jLabel1.getText();
jLabel1.setText("Aplicativo:");
jLabel1.setText(aux);
}
private void desmarcarAction(ActionEvent e) {
limparPanel(jPanelOperacao, 1);
LButtonSelect button = (LButtonSelect) e.getSource();
Vector<Operacao> operacaos = button.getOperacoes();
for (Operacao operacao : operacaos) {
operacao.setSelected(false);
jPanelOperacao.add(new OperacaoCheckBox(operacao));
}
jPanelOperacao.repaint();
String aux = jLabel1.getText();
jLabel1.setText("Aplicativo:");
jLabel1.setText(aux);
}
private void limparPanel(JPanel panel) {
Component[] c = panel.getComponents();
int max = c.length;
for (int i = 0; i < max; i++) {
panel.remove(i);
panel.repaint();
}
}
private void limparPanel(JPanel panel, int num) {
Component[] c = panel.getComponents();
int max = c.length - num;
for (int i = max; i > 0; i--) {
panel.remove(i);
panel.repaint();
}
}
private void paintIcons() {
RunningContext context = DesktopControl.getRunningContext();
ImageIcon imgSalvar = context.getImageIcon("supervisor/images/disket.png");
ImageIcon imgAbandonar = context.getImageIcon("supervisor/images/cancel.png");
ImageIcon imgRestaurar = context.getImageIcon("supervisor/images/reload.png");
ImageIcon imgTodas = context.getImageIcon("supervisor/images/marcado.png");
ImageIcon imgNenhuma = context.getImageIcon("supervisor/images/desmarcado.png");
try {
jButtonAbandonar.setIcon(imgAbandonar);
jButtonRestaurar.setIcon(imgRestaurar);
jButtonSalvar.setIcon(imgSalvar);
lButtonTodas.setIcon(imgTodas);
lButtonNenhuma.setIcon(imgNenhuma);
this.repaint();
} catch (Exception exception) {
}
}
private void resetLabel() {
jLabel1.setText("");
}
private void restaurarAction(ActionEvent evt) {
limparPanel(jPanelFuncao);
limparPanel(jPanelOperacao, 1);
resetLabel();
// start("");
}
private void enableSelectButton(boolean b) {
lButtonNenhuma.setEnabled(b);
lButtonTodas.setEnabled(b);
}
public Vector<Operacao> copiar(Vector<Funcao> func){
Vector<Operacao> operacaos = new Vector<Operacao>();
for (Funcao funcao : func) {
int codFunc= funcao.getCodigo();
String nomeFunc = funcao.getNome();
Funcao f= new Funcao(codFunc, nomeFunc);
Vector<Aplicacao> a = funcao.getAplicacaos();
for (Aplicacao aplicacao : a) {
Vector<Operacao> o = aplicacao.getOperacaoV();
int codAplic = aplicacao.getCod();
String nomeAplic = aplicacao.getNome();
Aplicacao aplic = new Aplicacao(codAplic, nomeAplic,f);
for (Operacao operacao : o) {
int codOp = operacao.getCod();
String nomeOp = operacao.getNome();
boolean selectedOp = operacao.isSelected();
Operacao op = new Operacao(codOp, nomeOp, selectedOp, aplic);
operacaos.add(op);
}
}
}
return operacaos;
}
private Vector<SSalvarOpPorFuncao> salvar() {
Vector<SSalvarOpPorFuncao> sSalvarFuncoes = new Vector<SSalvarOpPorFuncao>();
Vector<Operacao> opFinal = copiar(func);
for(int i=0;i<opInicial.size();i++){
boolean statusInicial= opInicial.get(i).isSelected() ;
boolean statusFinal = opFinal.get(i).isSelected();
if(statusInicial!=statusFinal){
SSalvarOpPorFuncao ssf = new SSalvarOpPorFuncao();
ssf.codOp=opFinal.get(i).getCod();
ssf.codAplic =opFinal.get(i).getAplicacao().getCod();
ssf.codFunc =opFinal.get(i).getAplicacao().getFuncao().getCodigo();
String alt = null ;
if(statusInicial==false & statusFinal==true){
ssf.flag="I";
}
else if(statusInicial==true & statusFinal==false){
ssf.flag="E";
}
sSalvarFuncoes.add(ssf);
}
}
return sSalvarFuncoes;
}
public void run() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
func = getFunc();
tree = getTree();
atualizar2();
}
});
// this.paintComponents(this.getGraphics());
}
public void atualizar1(){
this.paintComponents(this.getGraphics());
RunningContext context = DesktopControl.getRunningContext();
// DesktopMainFrame mainFrame = context.getMainFrame();
this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
}
public void atualizar2(){
this.paintComponents(this.getGraphics());
tree.addTreeSelectionListener(this);
jPanelFuncao.add(tree);
tree.setCellRenderer(new RenderizarTree());
enableSelectButton(false);
this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}