use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.
the class PvTransferHandler method importData.
/* (non-Javadoc)
* @see javax.swing.TransferHandler#importData(javax.swing.TransferHandler.TransferSupport)
*/
@Override
public boolean importData(TransferSupport support) {
try {
if (support.getComponent() instanceof JTree) {
JTree tree = (JTree) support.getComponent();
Point dropPoint = support.getDropLocation().getDropPoint();
TreePath path = tree.getPathForLocation(dropPoint.x, dropPoint.y);
Object node = path.getLastPathComponent();
if (support.isDataFlavorSupported(processVarFlavor)) {
ProcessVar tVar = (ProcessVar) ((PvTreeNode) node).getUserObject();
ProcessVar chldPv = (ProcessVar) support.getTransferable().getTransferData(processVarFlavor);
Object chldKey = chldPv.getKeyValue();
tVar.put(chldKey, chldPv, PvChangeEvent.PV_ADDED);
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
model.nodeStructureChanged((TreeNode) model.getRoot());
return true;
}
}
} catch (UnsupportedFlavorException e) {
ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
} catch (IOException e) {
ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
}
// anything else is handled by superclass
return super.importData(support);
}
use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.
the class PvExplorer method valueChanged.
@Override
public void valueChanged(TreeSelectionEvent e) {
TreePath selPath = e.getNewLeadSelectionPath();
if (selPath == null)
return;
ProcessVar pv = PvTreeNode.getPvFromTreePath(selPath);
if (pv instanceof PvList) {
// if process var is a PV list itself then show it in table
pvTable.setProcessVar(pv);
} else {
// ... otherwise create a list with PV as contained element
tblList.clear();
tblList.put(pv.getKeyValue(), pv);
pvTable.setProcessVar(tblList);
}
}
use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.
the class PvDetailPanel method setProcessVar.
/**
* set the process var which is assigned to this editor panel
* this creates all corresponding data fields
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public void setProcessVar(ProcessVar data) {
if (dataSource == null || !dataSource.equals(data)) {
// remove all child components, if they have been set already
if (dataSource != null && !dataSource.equals(data)) {
dataSource.removePvChangeListener(this);
fields.clear();
removeAll();
}
// update data source variable
dataSource = data;
// if data source is anything real ...
if (data != null) {
Object currKey = null;
Object currVal = null;
JLabel hdrCmp = null;
JComponent dataCmp = null;
GridBagConstraints attr = new GridBagConstraints();
// ... fill content panel with data
ArrayList keys = new ArrayList(data.keySet());
// sort list alphabetically
Collections.sort(keys);
Iterator it = keys.iterator();
// loop through all attributes
while (it.hasNext()) {
/* set default attributes */
attr.gridwidth = 1;
attr.gridheight = 1;
attr.weightx = 0.0;
attr.fill = GridBagConstraints.BOTH;
if ((currKey = it.next()) != null) {
hdrCmp = new JLabel(currKey.toString());
hdrCmp.setBackground(labelColor);
hdrCmp.setBorder(lineBorder);
// setup data component based on it's value
if ((currVal = data.get(currKey)) == null) {
dataCmp = new JLabel();
} else {
if (currVal instanceof ProcessVar) {
dataCmp = new PvDetailPanel((ProcessVar) currVal, editable);
} else {
dataCmp = new JTextField(data.get(currKey).toString());
((JTextField) dataCmp).setEditable(editable);
((JTextField) dataCmp).addActionListener(this);
}
}
dataCmp.setName(currKey.toString());
// add the components
add(hdrCmp, attr);
attr.gridwidth = GridBagConstraints.REMAINDER;
attr.weightx = 1.0;
add(dataCmp, attr);
// add data component to Hashmap of fields
fields.put(currKey, dataCmp);
}
}
// add 'this' panel as PvChangeListener to Process variable
data.addPvChangeListener(this, PvChangeEvent.PV_ADDED | PvChangeEvent.PV_MODIFIED);
}
validate();
}
}
use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.
the class PvTransferHandler method exportDone.
/* (non-Javadoc)
* @see javax.swing.TransferHandler#exportDone(javax.swing.JComponent, java.awt.datatransfer.Transferable, int)
*/
@Override
protected void exportDone(JComponent c, Transferable t, int action) {
try {
if (action == MOVE) {
ProcessVar pv = (ProcessVar) t.getTransferData(processVarFlavor);
pv.firePvChanged(new PvChangeEvent(pv, pv.getKeyAttribute(), pv, PvChangeEvent.PV_ELIMINATED));
}
} catch (UnsupportedFlavorException e) {
ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
} catch (IOException e) {
ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
}
}
use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.
the class PvTransferHandler method createTransferable.
/* (non-Javadoc)
* @see javax.swing.TransferHandler#createTransferable(javax.swing.JComponent)
*/
@Override
protected Transferable createTransferable(JComponent c) {
if (c instanceof JTree) {
try {
JTree tree = (JTree) c;
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
ProcessVar pv = (ProcessVar) node.getUserObject();
return (Transferable) pv;
} catch (ClassCastException ex) {
ProcessVar.log.severe(this.toString() + ":" + ex.getMessage());
}
} else if (c instanceof PvTable) {
PvTable tab = (PvTable) c;
ProcessVar pv = (ProcessVar) tab.getPvModel().getElementAt(tab.getSelectedRow());
return (Transferable) pv;
}
// anything else is handled by superclass
return super.createTransferable(c);
}
Aggregations