/*
* Collaborator.java
*
* Created on 18 Февраль 2008 г., 18:36
*/
package clips.accountant;
import cli_fmw.main.DirectoryItemNotFoundException;
import clips.delegate.client.CollaboratorLocal;
import cli_fmw.delegate.directory.DirectoryItem;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.main.ActivateSensitive;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageException;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Persistentable;
import cli_fmw.main.Printable;
import cli_fmw.report.FormReportCreator;
import cli_fmw.report.ReporterFactory;
import clips.delegate.directory.ro.DirectoryLpuItem;
import clips.userseach.PanelClientEdit;
import clips.userseach.PanelUserSearch;
import cli_fmw.utils.EmptyDialog;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.chooser.ChoosePanelComboException;
import java.awt.event.ContainerEvent;
import cli_fmw.main.ClipsException;
import cli_fmw.main.ContentStateListener;
import cli_fmw.main.MainWindow;
import cli_fmw.report.panels.model.FilteredComboBoxModel;
import cli_fmw.report.panels.model.delegate.DelegateTextModel;
import cli_fmw.report.panels.model.delegate.DirectoryComboBoxModel;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.accountant.config.PanelConfigCollab;
import clips.accountant.dialog.DialogNewFunction;
import clips.delegate.directory.complex.DirectoryCollaboratorFunctions;
import clips.delegate.directory.ro.DirectoryCollaborator;
import clips.delegate.directory.ro.DirectoryCollaboratorItem;
import clips.delegate.directory.ro.DirectoryLpu;
import clips.login.UserInfo;
import java.awt.event.ContainerListener;
import java.text.ParseException;
import java.util.HashMap;
import javax.swing.JPanel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
* Панель просмотра, редактирования и создания сотрудников
* @author petr
*/
public class PanelCollaboratorView extends PageGeneric implements Persistentable,
PageContainer, Printable {
public static final int STATE_EMPTY = 0;
public static final int STATE_EDITING = 1;
public static final int STATE_CREATING = 2;
private CollaboratorLocal collabLoc;
private PanelClientEdit panel;
DirectoryCollaborator dirCollab;
private DelegateTextModel<CollaboratorLocal> ldapModel;
private DelegateTextModel<CollaboratorLocal> codeModel;
private DelegateTextModel<CollaboratorLocal> loginModel;
private final DirectoryComboBoxModel<CollaboratorLocal, DirectoryLpuItem> lpuContModel;
/** Creates new form Collaborator
* @param container
* @throws ClipsException
*/
public PanelCollaboratorView(PageContainer container) throws ClipsException {
super(container);
initComponents();
btCertificateCreate.setVisible(false);
btCertificateView.setEnabled(false);
dirCollab = DirectoryLocator.getDirectory(DirectoryCollaborator.class, false);
//SelectorEditableExceptional<DirectoryCollaboratorItem> items = dirCollab.getItems();
/*DirectoryCollaboratorItem[] arrayItem = new DirectoryCollaboratorItem[items.size()];
for (int i = 0; i < items.size(); i++) {
DirectoryCollaboratorItem item = items.get(i);
arrayItem[i] = item;
}*/
panelSelColl.setWithNull(false);
panelSelColl.addContentStateListener(new ContentStateListener() {
@Override
public void contentStateChanged() {
DirectoryCollaboratorItem item = panelSelColl.getSelectedItem();
int id = item == null ? 0 : item.getID();
try {
chooseDone(0, id);
} catch (ChoosePanelComboException ex) {
try {
MessageBox.showWarning(MessageBox.W_NOT_CLOSE_EDITING);
int collID = collabLoc.getID();
panelSelColl.setSelectedCollaborator(collID == 0 ? null : dirCollab.getItemFromID(collID));
} catch (DirectoryItemNotFoundException ex1) {
setErrorMode();
MessageBox.showException(ex1);
}
}
}
});
tblFunctions.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
btRemove.setEnabled(tblFunctions.getSelectedRowCount()>0
&& tblFunctions.getRowCount() > 1
&& tblFunctions.getSelectedRowCount() != tblFunctions.getRowCount());
}
});
resetTableFunctions();
ldapModel = new DelegateTextModel<CollaboratorLocal>(tfLdap, collabLoc) {
@Override
protected void setModelTextChecked(String text) throws ClipsException, ParseException, NumberFormatException {
getObject().setLDAPName(text);
}
@Override
protected String getModelTextChecked() throws ClipsException {
return getObject().getLDAPName();
}
};
codeModel = new DelegateTextModel<CollaboratorLocal>(tfCollabCode, collabLoc) {
@Override
protected void setModelTextChecked(String text) throws ClipsException, ParseException, NumberFormatException {
getObject().setCode(text);
}
@Override
protected String getModelTextChecked() throws ClipsException {
return getObject().getCode();
}
};
loginModel = new DelegateTextModel<CollaboratorLocal>(tfLogin, collabLoc) {
@Override
protected void setModelTextChecked(String text) throws ClipsException, ParseException, NumberFormatException {
//DO nothing
}
@Override
protected String getModelTextChecked() throws ClipsException {
return Integer.toString(getObject().getID());
}
};
lpuContModel = new DirectoryComboBoxModel<CollaboratorLocal, DirectoryLpuItem>(cbLpu, DirectoryLocator.getDirectory(DirectoryLpu.class), collabLoc) {
@Override
public DirectoryLpuItem getSelectedDirectoryItem() throws ClipsException {
return getObject().getLpu();
}
@Override
public void setSelectedDirectoryItem(DirectoryLpuItem item) throws ClipsException {
getObject().setLpu(item);
}
@Override
public boolean isEnabled() {
return getObject() != null && (getObject().isNewlyCreated() || UserInfo.get().isSuperUser());
}
};
FilteredComboBoxModel lpuModel = new FilteredComboBoxModel(cbLpu, false) {
@Override
public Object addItem(String txt) {
return null;
}
};
lpuModel.setContainModel(lpuContModel);
setState(STATE_EMPTY);
StateSaver.attachTo(this);
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
pnlEditClient = new javax.swing.JPanel();
jPanel5 = new javax.swing.JPanel();
btCreateNewCollab = new javax.swing.JButton();
jTabbedPane1 = new javax.swing.JTabbedPane();
jPanel4 = new javax.swing.JPanel();
extraPanelM = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jPanel12 = new javax.swing.JPanel();
jPanel14 = new javax.swing.JPanel();
jPanel11 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
tfCollabCode = new javax.swing.JTextField();
firedCheckBox = new javax.swing.JCheckBox();
sheduledBox = new javax.swing.JCheckBox();
jPanel16 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
cbLpu = new javax.swing.JComboBox();
jPanel17 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
jPanel6 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
tfLogin = new javax.swing.JTextField();
jPanel9 = new javax.swing.JPanel();
lbLdap = new javax.swing.JLabel();
tfLdap = new javax.swing.JTextField();
jPanel13 = new javax.swing.JPanel();
jPanel18 = new javax.swing.JPanel();
jPanel15 = new javax.swing.JPanel();
btConfig = new javax.swing.JButton();
jPanel10 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
lblCertificate = new javax.swing.JLabel();
btCertificateView = new javax.swing.JButton();
btCertificateCreate = new javax.swing.JButton();
panelSelColl = new clips.accountant.PanelCollaboratorSelect();
jPanel7 = new javax.swing.JPanel();
jScrollPane3 = new javax.swing.JScrollPane();
tblFunctions = new cli_fmw.utils.sorted_table.SortedTable();
jPanel8 = new javax.swing.JPanel();
btRemove = new javax.swing.JButton();
btAdd = new javax.swing.JButton();
jPanel1.setLayout(new java.awt.BorderLayout());
jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Личные данные"));
jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
pnlEditClient.setLayout(new javax.swing.BoxLayout(pnlEditClient, javax.swing.BoxLayout.LINE_AXIS));
jScrollPane1.setViewportView(pnlEditClient);
jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);
jPanel5.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
btCreateNewCollab.setText("Создать нового сотрудника");
btCreateNewCollab.setToolTipText("Создать нового сотрудника");
btCreateNewCollab.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btCreateNewCollabActionPerformed(evt);
}
});
jPanel5.add(btCreateNewCollab);
jPanel1.add(jPanel5, java.awt.BorderLayout.PAGE_END);
extraPanelM.setBorder(javax.swing.BorderFactory.createTitledBorder("Сотрудник"));
extraPanelM.setLayout(new java.awt.BorderLayout());
jPanel2.setLayout(new java.awt.BorderLayout());
jPanel12.setLayout(new java.awt.BorderLayout(0, 5));
jPanel14.setLayout(new java.awt.BorderLayout());
jPanel11.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
jLabel3.setText("Табельный номер");
jPanel11.add(jLabel3);
tfCollabCode.setColumns(10);
jPanel11.add(tfCollabCode);
firedCheckBox.setFont(firedCheckBox.getFont().deriveFont(firedCheckBox.getFont().getStyle() | java.awt.Font.BOLD));
firedCheckBox.setText("Уволен");
firedCheckBox.setEnabled(false);
firedCheckBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
firedCheckBoxActionPerformed(evt);
}
});
jPanel11.add(firedCheckBox);
sheduledBox.setText("В расписании");
sheduledBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sheduledBoxActionPerformed(evt);
}
});
jPanel11.add(sheduledBox);
jPanel14.add(jPanel11, java.awt.BorderLayout.WEST);
jPanel16.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
jLabel4.setText("ЛПУ:");
jPanel16.add(jLabel4);
cbLpu.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jPanel16.add(cbLpu);
jPanel14.add(jPanel16, java.awt.BorderLayout.CENTER);
jPanel12.add(jPanel14, java.awt.BorderLayout.PAGE_START);
jPanel2.add(jPanel12, java.awt.BorderLayout.NORTH);
jPanel17.setLayout(new java.awt.BorderLayout(0, 5));
jPanel3.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 0));
jPanel3.setLayout(new java.awt.GridLayout(1, 0, 5, 5));
jPanel6.setLayout(new java.awt.BorderLayout(5, 5));
jLabel1.setText("Логин");
jPanel6.add(jLabel1, java.awt.BorderLayout.WEST);
tfLogin.setColumns(10);
tfLogin.setEditable(false);
jPanel6.add(tfLogin, java.awt.BorderLayout.CENTER);
jPanel3.add(jPanel6);
jPanel9.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 0));
jPanel9.setLayout(new java.awt.BorderLayout(5, 5));
lbLdap.setText("LDAP login:");
jPanel9.add(lbLdap, java.awt.BorderLayout.WEST);
jPanel9.add(tfLdap, java.awt.BorderLayout.CENTER);
jPanel3.add(jPanel9);
jPanel17.add(jPanel3, java.awt.BorderLayout.NORTH);
jPanel13.setLayout(new java.awt.BorderLayout(0, 5));
jPanel18.setLayout(new java.awt.BorderLayout());
btConfig.setText("Конфигурация");
btConfig.setEnabled(false);
btConfig.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btConfigActionPerformed(evt);
}
});
jPanel15.add(btConfig);
jPanel18.add(jPanel15, java.awt.BorderLayout.EAST);
jPanel10.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
jLabel2.setText("Сертификат:");
jPanel10.add(jLabel2);
lblCertificate.setText("---");
jPanel10.add(lblCertificate);
btCertificateView.setText("Просмотр...");
btCertificateView.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btCertificateViewActionPerformed(evt);
}
});
jPanel10.add(btCertificateView);
btCertificateCreate.setText("Связать");
btCertificateCreate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btCertificateCreateActionPerformed(evt);
}
});
jPanel10.add(btCertificateCreate);
jPanel18.add(jPanel10, java.awt.BorderLayout.WEST);
jPanel13.add(jPanel18, java.awt.BorderLayout.NORTH);
jPanel17.add(jPanel13, java.awt.BorderLayout.CENTER);
jPanel2.add(jPanel17, java.awt.BorderLayout.CENTER);
extraPanelM.add(jPanel2, java.awt.BorderLayout.CENTER);
extraPanelM.add(panelSelColl, java.awt.BorderLayout.PAGE_START);
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(extraPanelM, javax.swing.GroupLayout.DEFAULT_SIZE, 667, Short.MAX_VALUE)
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(extraPanelM, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
);
jTabbedPane1.addTab("Данные сотрудника", jPanel4);
tblFunctions.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3"
}
));
jScrollPane3.setViewportView(tblFunctions);
btRemove.setText("Удалить");
btRemove.setEnabled(false);
btRemove.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btRemoveActionPerformed(evt);
}
});
btAdd.setText("Добавить");
btAdd.setEnabled(false);
btAdd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btAddActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
jPanel8.setLayout(jPanel8Layout);
jPanel8Layout.setHorizontalGroup(
jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btAdd, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
.addComponent(btRemove, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
);
jPanel8Layout.setVerticalGroup(
jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel8Layout.createSequentialGroup()
.addComponent(btAdd)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btRemove)
.addContainerGap(112, Short.MAX_VALUE))
);
javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
jPanel7.setLayout(jPanel7Layout);
jPanel7Layout.setHorizontalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
.addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 561, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
jPanel7Layout.setVerticalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
);
jTabbedPane1.addTab("Исполняемые обязанности", jPanel7);
jPanel1.add(jTabbedPane1, java.awt.BorderLayout.NORTH);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
private void resetTableFunctions() throws ClipsException{
if (collabLoc == null){
tblFunctions.setModel(new TableModelFunctions());
}else{
tblFunctions.setModel(new TableModelFunctions(collabLoc.getFunctions()));
}
btRemove.setEnabled(tblFunctions.getRowCount()>1);
DirectoryLocator.getDirectory(DirectoryCollaborator.class, true);
DirectoryLocator.getDirectory(DirectoryCollaboratorFunctions.class, true);
}
/**
* Добавляет слушателей
*/
private void addListeners() {
jScrollPane1.addContainerListener(new ContainerListener() {
@Override
public void componentAdded(ContainerEvent arg0) {
}
@Override
public void componentRemoved(ContainerEvent arg0) {
//resetCollab();
}
});
collabLoc.addContentStateListener(getContainer());
}
private void setErrorMode() {
if (panel != null) {
panel.lock();
}
panelSelColl.setEnabled(false);
}
/**
* Создание нового сотрудника
* @param evt
*/
private void btCreateNewCollabActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCreateNewCollabActionPerformed
if (isDirty()){//если дирти - ругнемся
MessageBox.showWarning(MessageBox.W_NOT_CLOSE_EDITING);
return;
}
//CollaboratorLocal newCollab=null;
// Показываем диалог выбора человека
EmptyDialog dialog = new EmptyDialog(null, "", getAuditManager());
PanelUserSearch pus = null;
try {
pus = new PanelUserSearch(dialog, PanelUserSearch.MODE_SELECT);
dialog.addNewPage(pus, null);
dialog.setVisible(true);
} catch (Exception ex) {
if ((ex instanceof ClipsException) && !(ex instanceof PageException)) {
setErrorMode();
}
MessageBox.showException(ex);
return;
}
//Если выбор сделан
if (dialog.getDlgResult() == ModalDialog.DLG_OK) {
if (!isDirty()) {
try {
if (pus.getSelectedClient() == null) {
return;
}
//попытка найти сотрудника из уже имеющихся
Integer collID = dirCollab.getByClientID(pus.getSelectedClient().getID());
if (collID == 0) {
collabLoc = new CollaboratorLocal(pus.getSelectedClient());
panelSelColl.setSelectedCollaborator(null);
setState(STATE_CREATING);
addListeners();
collabToScreen();
resetPanel();
} else {
collabLoc = new CollaboratorLocal(collID, getAuditManager());
panelSelColl.setSelectedCollaborator(dirCollab.getItemFromID(collID));
setState(STATE_EDITING);
addListeners();
collabToScreen();
resetPanel();
}
} catch (Exception ex) {
if ((ex instanceof ClipsException) &&
!(ex instanceof PageException)) {
setErrorMode();
}
MessageBox.showException(ex);
return;
}
}
}
}//GEN-LAST:event_btCreateNewCollabActionPerformed
private void firedCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_firedCheckBoxActionPerformed
try {
collabLoc.setFired(firedCheckBox.isSelected());
} catch (Exception ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_firedCheckBoxActionPerformed
private void sheduledBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sheduledBoxActionPerformed
try {
collabLoc.setSheduled(sheduledBox.isSelected());
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_sheduledBoxActionPerformed
private void btAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddActionPerformed
try {
DialogNewFunction dialogNewFunction = new DialogNewFunction(MainWindow.mainWindow, collabLoc);
dialogNewFunction.setVisible(true);
if (dialogNewFunction.getDlgResult() == ModalDialog.DLG_OK){
collabLoc.getFunctions().append(dialogNewFunction.getFunctions());
resetTableFunctions();
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btAddActionPerformed
private void btRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoveActionPerformed
int[] selectedRowsSorted = tblFunctions.getSelectedRowsSorted();
try {
for (int i = selectedRowsSorted.length - 1; i >= 0; i--) {
collabLoc.getFunctions().remove(selectedRowsSorted[i]);
}
resetTableFunctions();
} catch (ClipsException ex) {
MessageBox.showException(ex);
try {
resetTableFunctions();
} catch (ClipsException ex1) {
ex1.printStackTrace();
}
}
}//GEN-LAST:event_btRemoveActionPerformed
private void btConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btConfigActionPerformed
try {
PanelConfigCollab pcc = new PanelConfigCollab(getContainer(), collabLoc);
getContainer().addNewPage(pcc, this);
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btConfigActionPerformed
private void btCertificateViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCertificateViewActionPerformed
System.out.println("Просмотр сертификата");
}//GEN-LAST:event_btCertificateViewActionPerformed
private void btCertificateCreateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCertificateCreateActionPerformed
try {
System.out.println("Создание сертификата");
// collabLoc.createCertificate();
collabToScreen();
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btCertificateCreateActionPerformed
/**
* Разблокирует поля ввода данных коллаборатора
*/
private void setState(int state) {
System.out.println("State: " + state);
switch (state){
case STATE_CREATING:{
panelSelColl.setEnabled(false);
firedCheckBox.setEnabled(true);
//Добавить шедулебокс и на одну панель с увольнением
sheduledBox.setEnabled(true);
btConfig.setEnabled(true);
break;
}
case STATE_EDITING:{
panelSelColl.setEnabled(true);
firedCheckBox.setEnabled(true);
sheduledBox.setEnabled(true);
btConfig.setEnabled(true);
break;
}
case STATE_EMPTY: {
try {
if (panel != null){
removePage(panel, true);
}
panelSelColl.setEnabled(true);
firedCheckBox.setEnabled(false);
sheduledBox.setEnabled(false);
btConfig.setEnabled(false);
break;
} catch (PageException ex) {
MessageBox.showException(ex);
}
}
}
}
/**
* Перезагружает панель редактирования клиента
* @throws cli_fmw.delegate.exception.ClipsException
*/
private void resetPanel() throws PageException, ClipsException {
if (panel != null) {
removePage(panel, true); // Пробуем удалить страницу
}
if (panel == null && collabLoc != null) { // Сработает если страница удалена (или не существовала)
panel = new PanelClientEdit(getContainer(), collabLoc.getClient());
panel.hideToolPanel();
addNewPage((PageGeneric) panel, null);
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btAdd;
private javax.swing.JButton btCertificateCreate;
private javax.swing.JButton btCertificateView;
private javax.swing.JButton btConfig;
private javax.swing.JButton btCreateNewCollab;
private javax.swing.JButton btRemove;
private javax.swing.JComboBox cbLpu;
private javax.swing.JPanel extraPanelM;
private javax.swing.JCheckBox firedCheckBox;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel10;
private javax.swing.JPanel jPanel11;
private javax.swing.JPanel jPanel12;
private javax.swing.JPanel jPanel13;
private javax.swing.JPanel jPanel14;
private javax.swing.JPanel jPanel15;
private javax.swing.JPanel jPanel16;
private javax.swing.JPanel jPanel17;
private javax.swing.JPanel jPanel18;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JPanel jPanel8;
private javax.swing.JPanel jPanel9;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JLabel lbLdap;
private javax.swing.JLabel lblCertificate;
private clips.accountant.PanelCollaboratorSelect panelSelColl;
private javax.swing.JPanel pnlEditClient;
private javax.swing.JCheckBox sheduledBox;
private cli_fmw.utils.sorted_table.SortedTable tblFunctions;
private javax.swing.JTextField tfCollabCode;
private javax.swing.JTextField tfLdap;
private javax.swing.JTextField tfLogin;
// End of variables declaration//GEN-END:variables
@Override
public String getPageTitle() {
return "Сотрудник";
}
public boolean canSelectionChange(DirectoryItem selected) {
return true;
}
/**
* Обработка выбора сотрудника из списка
* @param type
* @param id
* @throws ChoosePanelComboException
*/
public void chooseDone(int type, int id) throws ChoosePanelComboException {
if (!isDirty() || collabLoc.isNewlyCreated()) {
try {
if (collabLoc == null || !collabLoc.isNewlyCreated()) {
collabLoc = new CollaboratorLocal(id, getAuditManager());
}
resetPanel();
ldapModel.setObject(collabLoc);
codeModel.setObject(collabLoc);
loginModel.setObject(collabLoc);
lpuContModel.setObject(collabLoc);
collabToScreen();
setState(STATE_EDITING);
addListeners();
resetTableFunctions();
btAdd.setEnabled(collabLoc != null);
} catch (ClipsException ex) {
MessageBox.showException(ex);
throw new ChoosePanelComboException();
}
} else {
throw new ChoosePanelComboException();
}
}
/**
* Отображает на экране данные коллаборатора;
*/
private void collabToScreen() throws ClipsException {
firedCheckBox.setSelected(collabLoc != null ? collabLoc.isFired() : false);
sheduledBox.setSelected(collabLoc != null ? collabLoc.isSheduled() : false);
if (collabLoc != null){
btCertificateView.setEnabled(true);
if (collabLoc.haveCertificate()){
lblCertificate.setText(collabLoc.getCertificateNumber());
btCertificateView.setVisible(true);
btCertificateCreate.setVisible(false);
}else{
lblCertificate.setText("");
btCertificateView.setVisible(false);
btCertificateCreate.setVisible(true);
}
}else{
lblCertificate.setText("---");
btCertificateCreate.setVisible(false);
btCertificateView.setVisible(true);
btCertificateView.setEnabled(false);
}
}
/**
* Попытка добавить страницу
* @param pageToAdd
* @param afterPage
* @return
* @throws PageException
*/
@Override
public PageGeneric addNewPage(PageGeneric pageToAdd, PageGeneric afterPage) throws PageException {
// if (page == null) {
// page = pageToAdd;
pnlEditClient.add((JPanel) pageToAdd, java.awt.BorderLayout.CENTER);
pnlEditClient.revalidate();
return pageToAdd;
// } else {
// throw new PageException("Страница не может быть добавлена");
// }
}
/**
* Попытка удалить страницу
* @param page
* @param forced
* @throws PageException
*/
@Override
public void removePage(PageGeneric page, boolean forced) throws PageException {
if (page != null) {//|| (this.page != page)) {
if (page instanceof ActivateSensitive) {
ActivateSensitive as = (ActivateSensitive) page;
as.beforeDeactivate();
}
if (collabLoc != null && collabLoc.getID() == 0) {
pnlEditClient.removeAll();
repaint();
this.panel = null;
} else {
pnlEditClient.removeAll();
repaint();
this.panel = null;
}
} else {
throw new PageException("Попытка удалить неизвестную страницу");
}
}
@Override
public void activatePage(PageGeneric page) throws PageException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PageGeneric getActivePage() {
throw new UnsupportedOperationException("Not supported yet.");
}
/**
* Проверка изменений
* @return
*/
@Override
public boolean isDirty() {
boolean res = false;
try {
if (collabLoc != null) {// Проверить коллаба на изменения можно только если он существует
res = collabLoc.isNewlyCreated() ||
collabLoc.isDirty() ||
collabLoc.getClient().isDirty();
} else {
res = false;
}
return res;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
@Override
public void save() throws ClipsException {
//boolean isCreating = (collabLoc.getID() == 0);
collabLoc.save1();
collabLoc.getClient().save1();
btCreateNewCollab.setEnabled(true);
panelSelColl.setEnabled(true);
//сохранение прошло успешно, обновляем каталог и список сотрудников
try {
dirCollab = DirectoryLocator.getDirectory(DirectoryCollaborator.class, true);
DirectoryCollaboratorItem cur = dirCollab.getItemFromID(collabLoc.getID());
panelSelColl.setSelectedCollaborator(cur, dirCollab);
} catch (Exception ex) {
MessageBox.showException(ex);
}
}
@Override
public void restore() {
//Включаем выбор коллаба
try {
if (collabLoc.isNewlyCreated()) {
panelSelColl.setSelectedCollaborator(null);
resetPanel();
collabLoc = null;
this.collabToScreen();
getContainer().contentStateChanged();
setState(STATE_EMPTY);
} else {
collabLoc.restore(); //Восстанавливаем коллаба
collabToScreen();
if ((collabLoc.getClient() != null) &&
(collabLoc.getClient().isDirty())) {
collabLoc.getClient().restore(); //Восстанавливаем клиента-коллаба
}
resetPanel();
btCreateNewCollab.setEnabled(true);
resetTableFunctions();
}
} catch (ChoosePanelComboException ex) {
MessageBox.showException(ex);
} catch (PageException ex) {
MessageBox.showException(ex);
} catch (ClipsException ex) {
setErrorMode();
MessageBox.showException(ex);
}
}
@Override
public void contentStateChanged() {
fireContainerEventStateChanged();
// System.out.
try {
if (collabLoc.isDirty() || collabLoc.getClient().isDirty()) {
btCreateNewCollab.setEnabled(false);
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
@Override
public int getPageCount() {
return (panel == null) ? 0:1;
}
@Override
public PageGeneric getPage(int index) {
return (PageGeneric)panel;
}
@Override
public boolean readyForPrint() {
return !(collabLoc == null || isDirty());
}
@Override
public void print() {
try {
if (readyForPrint()) {
FormReportCreator creater = ReporterFactory.createFormReporter(getClass());
HashMap<String, Object> extraFields = collabLoc.getFieldsForPrint();
creater.createReport(null, null, extraFields.entrySet(), null);
creater.finish();
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
@Override
public DelegateLine2 getDelegate() {
return collabLoc;
}
}