/**
* This file is part of HIDB2.
*
* HIDB2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PoJamas 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 Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser Public License
* along with HIDB2. If not, see <http://www.gnu.org/licenses/>.
*/
package hidb2.gui.editor;
import hidb2.gui.util.FormLayoutFactory;
import hidb2.gui.util.PojoCellModifier;
import hidb2.gui.util.PojoColumnDescr;
import hidb2.gui.util.PoserTableViewer;
import hidb2.kern.AttrType;
import hidb2.kern.DBAction;
import hidb2.kern.DeltaMMFile;
import hidb2.kern.HIDBConst;
import java.util.List;
import java.util.logging.Logger;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
/**
* Check directory result dialog.
*
*/
public class DlgDeltaFile extends Dialog implements HIDBConst
{
final static Logger log = Logger.getLogger("hidb2.gui");
private int _res = C_FAIL;
private Shell _dlg;
private PoserTableViewer _tbl;
/**
* Search dialog creation.
* @param parent
* @param searchView
*/
public DlgDeltaFile(Shell parent)
{
super(parent, SWT.DIALOG_TRIM);
_dlg = new Shell(parent.getShell(), SWT.DIALOG_TRIM);
_dlg.setText("Check Directory Results");
_dlg.setLayout(new GridLayout(1, false));
// Create FolderDescriptionList Panel
createDeltaPanel();
// Validation Button
Composite panButton = new Group(_dlg, SWT.NONE);
GridData gdPan = new GridData();
gdPan.grabExcessHorizontalSpace = true;
gdPan.horizontalAlignment = SWT.FILL;
panButton.setLayoutData(gdPan);
RowLayout rowLayout2 = new RowLayout(SWT.HORIZONTAL);
rowLayout2.fill = true;
rowLayout2.wrap = false;
rowLayout2.justify = true;
rowLayout2.pack = false;
panButton.setLayout(rowLayout2);
Button btnValid = new Button(panButton, SWT.PUSH);
btnValid.setText("OK");
// Cancel Button
Button btnCancel = new Button(panButton, SWT.PUSH);
btnCancel.setText("Cancel");
btnValid.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
_res = C_OK;
_dlg.close();
}
});
btnCancel.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
_res = C_FAIL;
_dlg.close();
}
});
_dlg.setDefaultButton(btnValid);
_dlg.pack();
}
/**
* Create FolderDescriptionList Panel
*/
private void createDeltaPanel()
{
Group panel = new Group(_dlg, SWT.NONE);
GridData gdPan = new GridData();
gdPan.grabExcessHorizontalSpace = true;
gdPan.horizontalAlignment = SWT.FILL;
gdPan.minimumWidth = 500;
panel.setLayoutData(gdPan);
panel.setLayout(new GridLayout(1, false));
// Label labA = new Label(panel, SWT.NONE);
// labA.setText("Attributes");
_tbl = new PoserTableViewer(panel, SWT.SINGLE | SWT.FULL_SELECTION);
GridData gdTbl = new GridData();
gdTbl.grabExcessHorizontalSpace = true;
gdTbl.horizontalAlignment = SWT.FILL;
gdTbl.minimumHeight = 200;
gdTbl.heightHint = 300;
_tbl.setLayoutData(gdTbl);
_tbl.addROAttribut("AttrFile", AttrType.T_Image, "Image", 130);
_tbl.addROAttribut("FileName", AttrType.T_String, "File", 120);
_tbl.addROAttribut("Status", AttrType.T_Enum, "Status", 60);
_tbl.addAttribut(new PojoColumnDescr("Action", AttrType.T_Enum, "Action", 80)
{
public CellEditor createCellEditor(final Table table)
{
if ((_cellEdt == null) && editable)
{
String[] tblAttrName = new String[]
{
"Ignore", "Create", "Update", "Delete"
};
_cellEdt = new ComboBoxCellEditor(table, tblAttrName, SWT.READ_ONLY);
}
return _cellEdt;
}
});
HIDB2Toolkit toolkit = new HIDB2Toolkit(_dlg.getDisplay());
Composite containerBtn = toolkit.createComposite(panel, SWT.NONE);
containerBtn.setLayout(FormLayoutFactory.createClearGridLayout(true, 1));
_tbl.createMMI();
// Add a specific CellModifier to manage Combo indexes <-> Real Value
_tbl.setCellModifier(new PojoCellModifier(_tbl)
{
@Override
public Object getValue(Object element, String property)
{
Object o = null;
if (property.equals("Action"))
{
int idx = ((DeltaMMFile) element).getAction().ordinal();
o = new Integer(idx);
}
return o;
}
@Override
public void modify(Object element, String property, Object value)
{
if (property.equals("Action"))
{
int index = (Integer) value;
value = DBAction.values()[index];
}
super.modify(element, property, value);
}
});
}
/**
* Open the search specification dialog.
*
* @return
*/
public int open(List<DeltaMMFile> lstDelta)
{
// Fill fields
_tbl.setInput(lstDelta);
_dlg.open();
while (!_dlg.isDisposed())
{
if (!_dlg.getDisplay().readAndDispatch())
_dlg.getDisplay().sleep();
}
_dlg.dispose();
return _res;
}
}