/*
 * Copyright (C) 2015 SAA
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package partepronta;

import controlador.Diagrama;
import controlador.Editor;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.event.MouseInputAdapter;
import javax.swing.event.MouseInputListener;
import javax.swing.plaf.basic.BasicTabbedPaneUI;
import principal.Aplicacao;

/**
 *
 * @author SAA
 */
public class FormPartes extends javax.swing.JFrame {

    /**
     * Creates new form FormPartes
     */
    public FormPartes() {
        initComponents();
        setTitle("brModelo: " + Editor.fromConfiguracao.getValor("Controler.interface.repositorio"));
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnGrp = new javax.swing.ButtonGroup();
        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        Barra = new javax.swing.JToolBar();
        jToolBar1 = new javax.swing.JToolBar();
        btnOK = new javax.swing.JButton();
        btnEdt = new javax.swing.JButton();
        btnDel = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        btnUP = new javax.swing.JButton();
        btnDown = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        btnFechar = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        Pan = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        menuOK = new javax.swing.JMenuItem();
        menuEditar = new javax.swing.JMenuItem();
        menuSalvar = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        menuFechar = new javax.swing.JMenuItem();

        jSplitPane1.setDividerLocation(260);
        jSplitPane1.setResizeWeight(0.1);

        Barra.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        Barra.setFloatable(false);
        Barra.setOrientation(javax.swing.SwingConstants.VERTICAL);
        Barra.setRollover(true);
        jScrollPane2.setViewportView(Barra);

        jToolBar1.setFloatable(false);
        jToolBar1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jToolBar1.setRollover(true);

        btnOK.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/check.png"))); // NOI18N
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("principal/Formularios_pt_BR"); // NOI18N
        btnOK.setText(bundle.getString("FormPartes.btnOK.text")); // NOI18N
        btnOK.setToolTipText(bundle.getString("FormPartes.btnOK.toolTipText")); // NOI18N
        btnOK.setFocusable(false);
        btnOK.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnOK.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOKActionPerformed(evt);
            }
        });
        jToolBar1.add(btnOK);

        btnEdt.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/edit.png"))); // NOI18N
        btnEdt.setText(bundle.getString("FormPartes.btnEdt.text")); // NOI18N
        btnEdt.setToolTipText(bundle.getString("FormPartes.btnEdt.toolTipText")); // NOI18N
        btnEdt.setFocusable(false);
        btnEdt.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnEdt.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnEdt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEdtActionPerformed(evt);
            }
        });
        jToolBar1.add(btnEdt);

        btnDel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/xis.png"))); // NOI18N
        btnDel.setText(bundle.getString("FormPartes.btnDel.text")); // NOI18N
        btnDel.setToolTipText(bundle.getString("FormPartes.btnDel.toolTipText")); // NOI18N
        btnDel.setActionCommand(bundle.getString("FormPartes.btnDel.actionCommand")); // NOI18N
        btnDel.setFocusable(false);
        btnDel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnDel.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnDel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDelActionPerformed(evt);
            }
        });
        jToolBar1.add(btnDel);
        jToolBar1.add(jSeparator1);

        btnUP.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/up.png"))); // NOI18N
        btnUP.setText(bundle.getString("FormPartes.btnUP.text")); // NOI18N
        btnUP.setToolTipText(bundle.getString("FormPartes.btnUP.toolTipText")); // NOI18N
        btnUP.setFocusable(false);
        btnUP.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnUP.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnUP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUPActionPerformed(evt);
            }
        });
        jToolBar1.add(btnUP);

        btnDown.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/down.png"))); // NOI18N
        btnDown.setToolTipText(bundle.getString("FormPartes.btnDown.toolTipText")); // NOI18N
        btnDown.setFocusable(false);
        btnDown.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnDown.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnDown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDownActionPerformed(evt);
            }
        });
        jToolBar1.add(btnDown);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
        );

        jSplitPane1.setLeftComponent(jPanel3);

        btnFechar.setText(bundle.getString("FormPartes.btnFechar.text")); // NOI18N
        btnFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFecharActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(463, Short.MAX_VALUE)
                .addComponent(btnFechar))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(btnFechar)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        Pan.setBackground(new java.awt.Color(255, 255, 255));
        Pan.setLayout(null);
        jScrollPane3.setViewportView(Pan);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jSplitPane1.setRightComponent(jPanel1);

        jMenu1.setText(bundle.getString("FormPartes.jMenu1.text")); // NOI18N

        menuOK.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/check.png"))); // NOI18N
        menuOK.setText(bundle.getString("FormPartes.menuOK.text")); // NOI18N
        menuOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuOKActionPerformed(evt);
            }
        });
        jMenu1.add(menuOK);

        menuEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/edit.png"))); // NOI18N
        menuEditar.setText(bundle.getString("FormPartes.menuEditar.text")); // NOI18N
        menuEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuEditarActionPerformed(evt);
            }
        });
        jMenu1.add(menuEditar);

        menuSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/menu_salvar.png"))); // NOI18N
        menuSalvar.setText(bundle.getString("FormPartes.menuSalvar.text")); // NOI18N
        menuSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuSalvarActionPerformed(evt);
            }
        });
        jMenu1.add(menuSalvar);
        jMenu1.add(jSeparator2);

        menuFechar.setText(bundle.getString("FormPartes.menuFechar.text")); // NOI18N
        menuFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuFecharActionPerformed(evt);
            }
        });
        jMenu1.add(menuFechar);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 794, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 794, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 461, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(2, 2, 2)
                    .addComponent(jSplitPane1)
                    .addGap(2, 2, 2)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnEdtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEdtActionPerformed
        ParteBtn btn = getBtnSelecionado();
        if (btn != null) {
            String txt = util.Dialogos.ShowDlgInputText(this.getRootPane(), btn.Parte.getTitulo());
            if (!"".equals(txt)) {
                Partes.Edit(btn.Parte, txt);
                btn.setText(txt);
                menuSalvar.setEnabled(Partes.isMudou());
            }
        }

    }//GEN-LAST:event_btnEdtActionPerformed

    private void btnDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDelActionPerformed
        ParteBtn btn = getBtnSelecionado();
        if (btn != null) {
            GerenciadorSubParte sb = btn.Parte;
            int idx = Partes.getLista().indexOf(sb);

            if (util.Dialogos.ShowMessageConfirm(this.getRootPane(), "") == JOptionPane.YES_OPTION) {
                Partes.Remova(sb);
                Barra.removeAll();
                HabiliteBtns(-1);
                Partes.getLista().stream().filter(e -> e.getTipoDeDiagrama() == TipoDeDiagrama).forEach(pa -> criaBtn(pa));
                Pan.removeAll();
                Pan.revalidate();
                Pan.repaint();
                repaint();
                if (!(Barra.getComponentCount() > idx)) {
                    idx--;
                }
                if (idx > -1) {
                    btn = ((ParteBtn) Barra.getComponent(idx));
                    btn.doClick();
                }
                menuSalvar.setEnabled(Partes.isMudou());
            }
        }
    }//GEN-LAST:event_btnDelActionPerformed

    public ParteBtn getBtnSelecionado() {
        for (int i = 0; i < Barra.getComponentCount(); i++) {
            ParteBtn btn = ((ParteBtn) Barra.getComponent(i));
            if (btn.isSelected()) {
                return btn;
            }
        }
        return null;
    }

    private void btnUPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUPActionPerformed
        ParteBtn btn = getBtnSelecionado();
        if (btn != null) {
            GerenciadorSubParte sb = btn.Parte;
            int idx = Partes.getLista().indexOf(sb);
            if (idx > 0) {
                Partes.Remova(sb);
                Partes.getLista().add(idx - 1, sb);

                Barra.removeAll();
                Partes.getLista().stream().filter(e -> e.getTipoDeDiagrama().equals(TipoDeDiagrama)).forEach(pa -> criaBtn(pa));

                ParteBtn btn2 = ((ParteBtn) Barra.getComponent(idx - 1));
                Barra.repaint();
                btn2.doClick();
            }
        }
    }//GEN-LAST:event_btnUPActionPerformed

    private void btnFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFecharActionPerformed
        setVisible(false);
    }//GEN-LAST:event_btnFecharActionPerformed

    private void btnDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownActionPerformed
        ParteBtn btn = getBtnSelecionado();
        if (btn != null) {
            GerenciadorSubParte sb = btn.Parte;
            int idx = Partes.getLista().indexOf(sb);
            if (idx < Barra.getComponentCount() - 1) {
                Partes.Remova(sb);
                Partes.getLista().add(idx + 1, sb);

                Barra.removeAll();
                Partes.getLista().stream().filter(e -> e.getTipoDeDiagrama().equals(TipoDeDiagrama)).forEach(pa -> criaBtn(pa));
                btn = ((ParteBtn) Barra.getComponent(idx + 1));
                Barra.repaint();
                btn.doClick();
            }
        }
    }//GEN-LAST:event_btnDownActionPerformed

    private final Editor Mananger = Aplicacao.fmPrincipal.getEditor();

    private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
        ParteBtn btn = getBtnSelecionado();
        if (btn != null) {
            GerenciadorSubParte sb = btn.Parte;
            if (!Mananger.diagramaAtual.doPaste(sb.getXMLCopiado())) {
                util.Dialogos.ShowMessageERROR(this, Editor.fromConfiguracao.getValor("Controler.MSG_ERRO_PASTE"));
            } else {
                setVisible(false);
            }
        }
    }//GEN-LAST:event_btnOKActionPerformed

    private void menuFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFecharActionPerformed
        btnFecharActionPerformed(evt);
    }//GEN-LAST:event_menuFecharActionPerformed

    private void menuSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuSalvarActionPerformed
        Salva();
    }//GEN-LAST:event_menuSalvarActionPerformed

    private void menuEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuEditarActionPerformed
        btnEdtActionPerformed(evt);
    }//GEN-LAST:event_menuEditarActionPerformed

    private void menuOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuOKActionPerformed
        btnOKActionPerformed(evt);
    }//GEN-LAST:event_menuOKActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToolBar Barra;
    private javax.swing.JPanel Pan;
    private javax.swing.JButton btnDel;
    private javax.swing.JButton btnDown;
    private javax.swing.JButton btnEdt;
    private javax.swing.JButton btnFechar;
    private javax.swing.ButtonGroup btnGrp;
    private javax.swing.JButton btnOK;
    private javax.swing.JButton btnUP;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JMenuItem menuEditar;
    private javax.swing.JMenuItem menuFechar;
    private javax.swing.JMenuItem menuOK;
    private javax.swing.JMenuItem menuSalvar;
    // End of variables declaration//GEN-END:variables

    public GerenciadorPartes Partes = new GerenciadorPartes();

    public void NovoBotao(String texto, Diagrama diag) {
        GerenciadorSubParte sp = Partes.Add(texto, diag);
        ParteBtn btn = criaBtn(sp);
        btn.doClick();
    }

    private ParteBtn criaBtn(GerenciadorSubParte sp) {
        String texto = sp.getTitulo();
        ParteBtn btn = new ParteBtn(texto);
        btn.setFocusable(false);
        btn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btn.Parte = sp;
        btnGrp.add(btn);
        Barra.add(btn);
        btn.setSelected(true);
        btn.addActionListener((ActionEvent e) -> {
            GerenciadorSubParte sp1 = ((ParteBtn) e.getSource()).Parte;
            ImageIcon img = new ImageIcon(sp1.getByteImage());
            JLabel picLabel = new JLabel(img);

            picLabel.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
            //picLabel.setLocation(0, 0);
            //picLabel.setPreferredSize(new Dimension(img.getIconWidth(), img.getIconHeight()));
            Pan.removeAll();
            //picLabel.setLocation(10, 10);
            Pan.add(picLabel);//, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));
            Pan.revalidate();
            Pan.repaint();
            HabiliteBtns(Partes.getLista().indexOf(sp));
        });
        btn.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                if (evt.getClickCount() == 2) {
                    if (btnOK.isEnabled()) {
                        btnOKActionPerformed(null);
                    }
                }
            }
        });
        return btn;
    }

    public Diagrama.TipoDeDiagrama TipoDeDiagrama = null;

    public void Popule(Diagrama.TipoDeDiagrama tp) {
        if (TipoDeDiagrama == tp) {
            return;
        }
        TipoDeDiagrama = tp;
        Barra.removeAll();
        HabiliteBtns(-1);
        Partes.getLista().stream().filter(e -> e.getTipoDeDiagrama().equals(tp)).forEach(pa -> criaBtn(pa));
        Pan.removeAll();
        if (Barra.getComponentCount() > 0) {
            ((ParteBtn) Barra.getComponent(0)).doClick();
        }
        Pan.revalidate();
        Pan.repaint();
        repaint();
    }

    public boolean LoadData() {
        Partes = GerenciadorPartes.LoadDataTemplate();
        if (Partes == null) {
            Partes = new GerenciadorPartes();
            if (!GerenciadorPartes.SaveDataTemplate(Partes)) {
                Partes = null;
            }
        }
        menuSalvar.setEnabled(Partes.isMudou());
        return (Partes != null);
    }

    public JMenuItem externalSalvar = null;

    private void HabiliteBtns(int indexOf) {
        btnDel.setEnabled(indexOf > -1 && Barra.getComponentCount() > 0);
        btnDown.setEnabled(indexOf > -1 && indexOf < Barra.getComponentCount() - 1);
        btnUP.setEnabled(indexOf > 0 && Barra.getComponentCount() > 0);
        btnEdt.setEnabled(indexOf > -1 && Barra.getComponentCount() > 0);
        btnOK.setEnabled(btnEdt.isEnabled());
        menuEditar.setEnabled(btnEdt.isEnabled());
        menuOK.setEnabled(btnEdt.isEnabled());
        menuSalvar.setEnabled(Partes.isMudou());
        externalSalvar.setEnabled(Partes.isMudou());
    }

    public void Salva() {
        GerenciadorPartes.SaveDataTemplate(Partes);
        menuSalvar.setEnabled(Partes.isMudou());
        externalSalvar.setEnabled(Partes.isMudou());
    }
}
