package main.states;
import business.CenarioVolume;
import java.util.Iterator;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.tree.DefaultTreeModel;
import main.Configuracao;
import main.Main;
import view.helpers.IconNode;
public class ProjetoAberto extends AbstractMainState {
public ProjetoAberto(Main view) {
super(view);
}
@Override
public void doEntry() {
view.getBtnVolumeNovoCenario().setEnabled(true);
view.getBtnVolumeDuplicarCenario().setEnabled(true);
view.getBtnIndLocalNovoCenario().setEnabled(true);
view.getBtnFecharProjeto().setEnabled(true);
view.getBtnAbrirProjeto().setEnabled(false);
view.getBtnNovoProjeto().setEnabled(false);
view.getTreeNavigator().setEnabled(true);
}
@Override
public void fecharProjeto() {
view.setViewState(new ProjetoFechado(view));
view.getViewState().fecharProjeto();
}
@Override
public void abrirProjeto() {
super.removeItemSb();
try {
Configuracao.getInstance();
} catch (Exception e) {
}
view.getStbMain().add(new JLabel("Projeto: " + view.getProjeto().getNome()));
view.getStbMain().updateUI();
updateTreeModel();
view.getTreeNavigator().updateUI();
view.getTreeNavigator().expandAll();
}
@Override
public void updateTreeModel() {
IconNode projetoNode = new IconNode("Projeto", true, new ImageIcon(Configuracao.getPath() + "images/projeto1.png"), IconNode.PROJETO);
DefaultTreeModel model = new DefaultTreeModel(projetoNode);
IconNode volumeNode = new IconNode("Volume", true, new ImageIcon(Configuracao.getPath() + "images/cenario.png"), IconNode.NONE);
Iterator<CenarioVolume> itCenariosVolume = view.getProjeto().getIteratorCenario();
while (itCenariosVolume.hasNext()) {
CenarioVolume cenarioVolume = itCenariosVolume.next();
IconNode cenarioNode = new IconNode(cenarioVolume.getNome(), true, new ImageIcon(Configuracao.getPath() + "images/cenario2.png"), IconNode.CENARIO_VOLUME, cenarioVolume.getId());
IconNode arvoresNode = new IconNode("Árvores", false, new ImageIcon(Configuracao.getPath() + "images/arvores.png"), IconNode.ARVORES, cenarioVolume.getId());
cenarioNode.add(arvoresNode);
volumeNode.add(cenarioNode);
}
IconNode indiceLocalNode = new IconNode("Índice de Local", true, new ImageIcon(Configuracao.getPath() + "images/indice.png"), IconNode.NONE);
((IconNode) model.getRoot()).setAllowsChildren(true);
((IconNode) model.getRoot()).add(volumeNode);
((IconNode) model.getRoot()).add(indiceLocalNode);
view.getTreeNavigator().setModel(model);
view.getTreeNavigator().updateUI();
view.getTreeNavigator().expandAll();
}
}