use of org.talend.expressionbuilder.ExpressionFileOperation in project tdi-studio-se by Talend.
the class ExpressionBuilderDialog method createButtonsForButtonBar.
/**
* Create contents of the button bar
*
* @param parent
*/
@Override
protected void createButtonsForButtonBar(Composite parent) {
((GridLayout) parent.getLayout()).numColumns++;
Composite buttons = new Composite(parent, SWT.NONE);
buttons.setLayout(new GridLayout(2, false));
final Button importButton = new Button(buttons, SWT.PUSH);
//$NON-NLS-1$
importButton.setToolTipText(Messages.getString("ExpressionBuilderDialog.import"));
importButton.setImage(ImageProvider.getImage(EImage.IMPORT_ICON));
final Button exportButton = new Button(buttons, SWT.PUSH);
//$NON-NLS-1$
exportButton.setToolTipText(Messages.getString("ExpressionBuilderDialog.export"));
exportButton.setImage(ImageProvider.getImage(EImage.EXPORT_ICON));
//$NON-NLS-1$
createButton(parent, IDialogConstants.OK_ID, Messages.getString("ExpressionBuilderDialog.ok.button"), true);
//$NON-NLS-1$
createButton(parent, IDialogConstants.CANCEL_ID, Messages.getString("ExpressionBuilderDialog.cancel.button"), false);
exportButton.addMouseListener(new MouseAdapter() {
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
*/
@Override
public void mouseUp(MouseEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
//$NON-NLS-1$
dialog.setFilterExtensions(new String[] { "*.xml" });
String filePath = dialog.open();
if (filePath != null) {
String expresionContent = expressionComposite.getExpression();
List<Variable> variables = new ArrayList<Variable>();
variables = testComposite.getVariableList();
File file = new File(filePath);
ExpressionFileOperation operation = new ExpressionFileOperation();
try {
if (file != null) {
file.createNewFile();
}
operation.saveExpressionToFile(file, variables, expresionContent);
} catch (IOException e1) {
RuntimeExceptionHandler.process(e1);
} catch (ParserConfigurationException e1) {
RuntimeExceptionHandler.process(e1);
}
}
}
});
importButton.addMouseListener(new MouseAdapter() {
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
*/
@Override
public void mouseUp(MouseEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
//$NON-NLS-1$
dialog.setFilterExtensions(new String[] { "*.xml" });
String filePath = dialog.open();
if (filePath != null) {
File file = new File(filePath);
ExpressionFileOperation operation = new ExpressionFileOperation();
try {
List list = operation.importExpressionFromFile(file, getShell());
if (list != null && list.size() != 0) {
expressionComposite.setExpression((String) list.get(0), false);
list.remove(0);
if (list.size() > 0) {
testComposite.addVariables(list);
}
}
} catch (IOException e1) {
RuntimeExceptionHandler.process(e1);
} catch (ParserConfigurationException e1) {
RuntimeExceptionHandler.process(e1);
} catch (SAXException e1) {
RuntimeExceptionHandler.process(e1);
}
}
}
});
}
Aggregations