use of com.centurylink.mdw.plugin.designer.dialogs.FileSaveDialog in project mdw-designer by CenturyLinkCloud.
the class ConvertApplicationProperties method run.
public void run(IAction action) {
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
if (structuredSelection.getFirstElement() instanceof IFile) {
final IFile inputFile = (IFile) structuredSelection.getFirstElement();
final WorkflowProject project = WorkflowProjectManager.getInstance().getWorkflowProject(inputFile.getProject().getName());
String ext = project == null || project.isOsgi() ? "cfg" : "properties";
FileSaveDialog saveDialog = new FileSaveDialog(MdwPlugin.getActiveWorkbenchWindow().getShell());
saveDialog.setFilterPath(inputFile.getParent().getRawLocation().makeAbsolute().toFile().getAbsolutePath());
saveDialog.setFilterExtensions(new String[] { "*" + ext });
final String filePath = saveDialog.open();
if (filePath != null) {
BusyIndicator.showWhile(MdwPlugin.getActiveWorkbenchWindow().getShell().getDisplay(), new Runnable() {
public void run() {
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(inputFile.getContents());
doc.getDocumentElement().normalize();
StringBuffer sb = new StringBuffer();
NodeList nList = doc.getElementsByTagName("PropertyGroup");
// for every property group
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
String propertyGroupName = eElement.getAttribute("Name");
// create PropertyGroup comment
sb.append("\n");
sb.append("#");
sb.append(propertyGroupName);
sb.append("\n");
NodeList propertyList = eElement.getElementsByTagName("Property");
// group
for (int temp2 = 0; temp2 < propertyList.getLength(); temp2++) {
Node nNode2 = propertyList.item(temp2);
if (nNode2.getNodeType() == Node.ELEMENT_NODE) {
Element eElement2 = (Element) nNode2;
// format to:
// propertyGroup-propertyName=elementValue
sb.append(propertyGroupName);
if (project == null || project.isOsgi())
sb.append("-");
else
sb.append("/");
sb.append(eElement2.getAttribute("Name"));
sb.append("=");
sb.append(nNode2.getTextContent());
sb.append("\n");
}
}
}
}
PluginUtil.writeFile(new File(filePath), sb.toString().getBytes());
inputFile.getParent().refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
} catch (Exception ex) {
PluginMessages.uiError(shell, ex, "Convert Application Properties", project);
}
}
});
}
}
}
}
use of com.centurylink.mdw.plugin.designer.dialogs.FileSaveDialog in project mdw-designer by CenturyLinkCloud.
the class ImportExportPage method createFileControls.
protected void createFileControls(Composite parent, int ncol) {
new Label(parent, SWT.NONE).setText(isExport ? "Export File:" : "Import File:");
filePathText = new Text(parent, SWT.SINGLE | SWT.BORDER);
GridData gd = new GridData(GridData.BEGINNING);
gd.widthHint = 350;
gd.horizontalSpan = ncol - 2;
filePathText.setLayoutData(gd);
filePathText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
filePath = filePathText.getText().trim();
handleFieldChanged();
}
});
Button browseFileButton = new Button(parent, SWT.PUSH);
browseFileButton.setText("Browse...");
browseFileButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (isExport) {
FileSaveDialog dlg = new FileSaveDialog(getShell());
dlg.setFilterExtensions(new String[] { "*" + getFileExtension() });
dlg.setFileName(getDefaultFileName());
String path = dlg.open();
if (path != null)
filePathText.setText(path);
} else {
FileDialog dlg = new FileDialog(getShell());
dlg.setFilterExtensions(new String[] { "*" + getFileExtension() });
String path = dlg.open();
if (path != null)
filePathText.setText(path);
}
}
});
}
Aggregations