use of net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog in project translationstudio8 by heartsome.
the class ExportDocxDialog method initListener.
/**
* 初始化按钮监听 ;
*/
private void initListener() {
btnBrowseXLIFF.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(getShell(), false, IResource.FILE) {
// 打开对话框时展开树形目录
public void create() {
super.create();
super.getTreeViewer().expandAll();
}
};
dialog.setTitle(Messages.getString("ExportDocxDialog.browseXLIFFBtn.msg0"));
dialog.setMessage(Messages.getString("ExportDocxDialog.browseXLIFFBtn.msg1"));
dialog.setDoubleClickSelects(true);
dialog.setAllowMultiple(false);
try {
dialog.setInput(EFS.getStore(root.getLocationURI()));
} catch (CoreException e1) {
LOGGER.error(Messages.getString("ExportDocxDialog.logger.getXliffError"), e1);
MessageDialog.openInformation(getShell(), Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxDialog.browseXLIFFBtn.msg2"));
}
dialog.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof LocalFile) {
LocalFile folder = (LocalFile) element;
if (folder.getName().equalsIgnoreCase(".hsConfig") || folder.getName().equalsIgnoreCase(".metadata")) {
return false;
}
if (lstProject.contains(folder.toString())) {
return true;
}
String xliffFolderPath = folder.toString();
for (String projectPath : lstProject) {
String path1 = projectPath + System.getProperty("file.separator") + Constant.FOLDER_XLIFF;
if (xliffFolderPath.startsWith(path1)) {
return true;
}
}
}
return false;
}
});
dialog.create();
dialog.open();
if (dialog.getResult() != null) {
Object obj = dialog.getFirstResult();
IFile file = root.getFileForLocation(Path.fromOSString(obj.toString()));
xliffPathTxt.setText(file.getFullPath().toOSString());
strXliffFullPath = ResourceUtils.iFileToOSPath(file);
}
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
browseDocxBtn.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(getShell());
dialog.setText(Messages.getString("ExportDocxDialog.browseDocxBtn.msg0"));
String defaultPath = System.getProperty("user.home");
if (docxPathTxt.getText() != null && !docxPathTxt.getText().trim().equals("")) {
defaultPath = docxPathTxt.getText();
}
dialog.setFilterPath(defaultPath);
String path = dialog.open();
if (path != null) {
docxPathTxt.setText(path);
}
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
excludeBtn.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
boolean isSelection = excludeBtn.getSelection();
excludeGroup.setEnabled(isSelection);
excludeLockedBtn.setEnabled(isSelection);
exclude101Btn.setEnabled(isSelection);
exclude100Btn.setEnabled(isSelection);
onlyExportGroup.setEnabled(!isSelection);
onlyExportNoteBtn.setEnabled(!isSelection);
onlyExportReviewBtn.setEnabled(!isSelection);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
onlyExportBtn.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
boolean isSelection = onlyExportBtn.getSelection();
excludeGroup.setEnabled(!isSelection);
excludeLockedBtn.setEnabled(!isSelection);
exclude101Btn.setEnabled(!isSelection);
exclude100Btn.setEnabled(!isSelection);
onlyExportGroup.setEnabled(isSelection);
onlyExportNoteBtn.setEnabled(isSelection);
onlyExportReviewBtn.setEnabled(isSelection);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
use of net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog in project translationstudio8 by heartsome.
the class ImportDocxDialog method initListener.
/**
* 初始化按钮监听 ;
*/
private void initListener() {
browseXLIFFBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(getShell(), false, IResource.FILE) {
// 打开对话框时展开树形目录
public void create() {
super.create();
super.getTreeViewer().expandAll();
}
};
dialog.setTitle(Messages.getString("ImportDocxDialog.browseXLIFFBtn.msg0"));
dialog.setMessage(Messages.getString("ImportDocxDialog.browseXLIFFBtn.msg1"));
dialog.setDoubleClickSelects(true);
dialog.setAllowMultiple(false);
try {
dialog.setInput(EFS.getStore(root.getLocationURI()));
} catch (CoreException e1) {
LOGGER.error(Messages.getString("ImportDocxDialog.LOGGER.logger1"), e1);
}
dialog.addFilter(new ViewerFilter() {
@SuppressWarnings("restriction")
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof LocalFile) {
LocalFile folder = (LocalFile) element;
if (folder.getName().equalsIgnoreCase(".hsConfig") || folder.getName().equalsIgnoreCase(".metadata")) {
return false;
}
if (lstProject.contains(folder.toString())) {
return true;
}
String xliffFolderPath = folder.toString();
for (String projectPath : lstProject) {
String path1 = projectPath + System.getProperty("file.separator") + Constant.FOLDER_XLIFF;
if (xliffFolderPath.startsWith(path1)) {
return true;
}
}
}
return false;
}
});
dialog.create();
dialog.open();
if (dialog.getResult() != null) {
Object obj = dialog.getFirstResult();
IFile file = root.getFileForLocation(Path.fromOSString(obj.toString()));
xliffPathTxt.setText(file.getFullPath().toOSString());
xliffFullPath = ResourceUtils.iFileToOSPath(file);
}
}
});
browseDocxBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(getShell());
dialog.setText(Messages.getString("ImportDocxDialog.browseDocx.title"));
dialog.setFilterExtensions(new String[] { "*.docx", "*.*" });
dialog.setFilterNames(new String[] { Messages.getString(Messages.getString("ImportDocxDialog.browseDocx.filter")) });
String fileSep = System.getProperty("file.separator");
if (docxPathTxt.getText() != null && !docxPathTxt.getText().trim().equals("")) {
dialog.setFilterPath(docxPathTxt.getText().substring(0, docxPathTxt.getText().lastIndexOf(fileSep)));
dialog.setFileName(docxPathTxt.getText().substring(docxPathTxt.getText().lastIndexOf(fileSep) + 1));
} else {
dialog.setFilterPath(System.getProperty("user.home"));
}
String path = dialog.open();
if (path != null) {
docxPathTxt.setText(path);
}
}
});
}
use of net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog in project translationstudio8 by heartsome.
the class ImportExternalDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
composite.setLayout(new GridLayout(1, false));
GridDataFactory.fillDefaults().hint(500, 180).grab(true, true).applyTo(composite);
Group groupXLIFF = new Group(composite, SWT.None);
groupXLIFF.setLayoutData(new GridData(GridData.FILL_BOTH));
groupXLIFF.setLayout(new GridLayout(3, false));
groupXLIFF.setText(Messages.getString("ImportDocxDialog.XLIFFgroup"));
Label lblXLIFF = new Label(groupXLIFF, SWT.None);
lblXLIFF.setText(Messages.getString("ImportDocxDialog.lable.xliff"));
xliffPathTxt = new Text(groupXLIFF, SWT.BORDER);
xliffPathTxt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
xliffPathTxt.setEditable(false);
if (xliffRelativePath != null) {
xliffPathTxt.setText(xliffRelativePath);
}
browseXLIFFBtn = new Button(groupXLIFF, SWT.None);
browseXLIFFBtn.setText(Messages.getString("ImportDocxDialog.browseXLIFFBtn"));
browseXLIFFBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(getShell(), false, IResource.FILE) {
// 打开对话框时展开树形目录
public void create() {
super.create();
super.getTreeViewer().expandAll();
}
};
dialog.setTitle(Messages.getString("ImportDocxDialog.browseXLIFFBtn.msg0"));
dialog.setMessage(Messages.getString("ImportDocxDialog.browseXLIFFBtn.msg1"));
dialog.setDoubleClickSelects(true);
dialog.setAllowMultiple(false);
try {
dialog.setInput(EFS.getStore(root.getLocationURI()));
} catch (CoreException e1) {
LOGGER.error(Messages.getString("ImportDocxDialog.LOGGER.logger1"), e1);
}
dialog.addFilter(new ViewerFilter() {
@SuppressWarnings("restriction")
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof LocalFile) {
LocalFile folder = (LocalFile) element;
if (folder.getName().equalsIgnoreCase(".hsConfig") || folder.getName().equalsIgnoreCase(".metadata")) {
return false;
}
if (lstProject.contains(folder.toString())) {
return true;
}
String xliffFolderPath = folder.toString();
for (String projectPath : lstProject) {
String path1 = projectPath + System.getProperty("file.separator") + Constant.FOLDER_XLIFF;
if (xliffFolderPath.startsWith(path1)) {
return true;
}
}
}
return false;
}
});
dialog.create();
if (Window.OK == dialog.open()) {
if (dialog.getResult() != null) {
Object obj = dialog.getFirstResult();
IFile file = root.getFileForLocation(Path.fromOSString(obj.toString()));
xliffPathTxt.setText(file.getFullPath().toOSString());
xliffFullPath = ResourceUtils.iFileToOSPath(file);
}
getButton(IDialogConstants.OK_ID).setEnabled(!docxPathTxt.getText().isEmpty());
}
}
});
Group groupExternal = new Group(composite, SWT.NONE);
groupExternal.setText(Messages.getString("ImportDocxDialog.label.docx.title"));
groupExternal.setLayout(new GridLayout(3, false));
groupExternal.setLayoutData(new GridData(GridData.FILL_BOTH));
Label lblRTF = new Label(groupExternal, SWT.None);
lblRTF.setText(Messages.getString("ImportDocxDialog.label.docx"));
GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).grab(false, false).applyTo(lblRTF);
docxPathTxt = new Text(groupExternal, SWT.BORDER);
docxPathTxt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
docxPathTxt.setEditable(false);
browseDocxBtn = new Button(groupExternal, SWT.None);
browseDocxBtn.setText(Messages.getString("ImportDocxDialog.browseDocxBtn"));
browseDocxBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(getShell());
dialog.setText(Messages.getString("ImportDocxDialog.browseDocx.title"));
dialog.setFilterExtensions(new String[] { "*.docx;", "*.*" });
dialog.setFilterPath(dialogSetting.get("defaultPath"));
String path = dialog.open();
if (path != null) {
if (testFileType(path)) {
dialogSetting.put("defaultPath", path.substring(0, path.lastIndexOf(File.separator)));
docxPathTxt.setText(path);
getButton(IDialogConstants.OK_ID).setEnabled(true && (!xliffPathTxt.getText().isEmpty()));
} else {
getButton(IDialogConstants.OK_ID).setEnabled(false);
}
}
}
});
txtImportType = new Label(composite, SWT.READ_ONLY);
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BOTTOM).span(1, 3).grab(true, true).applyTo(txtImportType);
return composite;
}
use of net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog in project translationstudio8 by heartsome.
the class MergeXliffWizardPage method createMergeXlfGroup.
public void createMergeXlfGroup(Composite tparent) {
final Group xliffDataGroup = new Group(tparent, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(2).margins(8, 8).applyTo(xliffDataGroup);
GridDataFactory.fillDefaults().grab(true, true).applyTo(xliffDataGroup);
xliffDataGroup.setText(Messages.getString("wizard.MergeXliffWizardPage.xliffDataGroup"));
tableViewer = new TableViewer(xliffDataGroup, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
final Table table = tableViewer.getTable();
GridData tableData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
tableData.heightHint = 50;
table.setLayoutData(tableData);
table.setLinesVisible(true);
table.setHeaderVisible(true);
String[] columnNames = new String[] { Messages.getString("wizard.MergeXliffWizardPage.columnNames1"), Messages.getString("wizard.MergeXliffWizardPage.columnNames2") };
int[] columnAlignments = new int[] { SWT.LEFT, SWT.LEFT };
for (int i = 0; i < columnNames.length; i++) {
TableColumn tableColumn = new TableColumn(table, columnAlignments[i]);
tableColumn.setText(columnNames[i]);
}
tableViewer.setLabelProvider(new TableViewerLabelProvider());
tableViewer.setContentProvider(new ArrayContentProvider());
tableViewer.setInput(getSplitTableInfos());
validXlf();
// 让列表列宽动态变化
table.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event event) {
final Table table = ((Table) event.widget);
final TableColumn[] columns = table.getColumns();
event.widget.getDisplay().syncExec(new Runnable() {
public void run() {
double[] columnWidths = new double[] { 0.15, 0.75 };
for (int i = 0; i < columns.length; i++) columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
}
});
}
});
Composite buttonComp = new Composite(xliffDataGroup, SWT.None);
GridLayoutFactory.fillDefaults().numColumns(1).margins(8, 8).applyTo(buttonComp);
GridDataFactory.fillDefaults().grab(false, true).hint(100, SWT.DEFAULT).applyTo(buttonComp);
Button addbutton = new Button(buttonComp, SWT.NONE);
addbutton.setText(Messages.getString("wizard.MergeXliffWizardPage.addbutton"));
addbutton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
addbutton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(xliffDataGroup.getShell(), true, IResource.FILE);
dialog.setMessage(Messages.getString("wizard.MergeXliffWizardPage.dialogMsg"));
dialog.setTitle(Messages.getString("wizard.MergeXliffWizardPage.dialogTitle"));
dialog.setDoubleClickSelects(true);
try {
dialog.setInput(EFS.getStore(root.getLocationURI()));
} catch (CoreException e1) {
LOGGER.error("", e1);
e1.printStackTrace();
}
dialog.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof LocalFile) {
LocalFile folder = (LocalFile) element;
if (folder.getName().equalsIgnoreCase(".hsConfig") || folder.getName().equalsIgnoreCase(".metadata") || folder.getName().equalsIgnoreCase(".config") || folder.getName().equalsIgnoreCase(".nonTransElement")) {
return false;
}
if (projectPath.equals(folder.toString())) {
return true;
}
String xliffFolderPath = folder.toString();
String tempPath = projectPath + System.getProperty("file.separator") + ".TEMP";
String configPath = projectPath + System.getProperty("file.separator") + ".config";
String projectFilePath = projectPath + System.getProperty("file.separator") + ".project";
if (xliffFolderPath.startsWith(tempPath) || xliffFolderPath.startsWith(configPath) || xliffFolderPath.startsWith(projectFilePath)) {
return false;
} else if (xliffFolderPath.startsWith(projectPath)) {
return xliffFolderPath.substring(projectPath.length()).startsWith(System.getProperty("file.separator"));
}
}
return false;
}
});
dialog.create();
dialog.open();
if (dialog.getResult() != null) {
Object[] selectFiles = dialog.getResult();
XLFValidator.resetFlag();
for (int i = 0; i < selectFiles.length; i++) {
IFile iFile = root.getFileForLocation(Path.fromOSString(selectFiles[i].toString()));
if (XLFValidator.validateXliffFile(iFile)) {
// 如果该文件已经存在于列表中,就向添加到重复集合中
if (model.getMergeXliffFile().indexOf(iFile) >= 0) {
exsistFileList.add(iFile);
}
model.getMergeXliffFile().add(iFile);
}
}
XLFValidator.resetFlag();
tableViewer.setInput(getSplitTableInfos());
if (!validIsRepeate()) {
validXlf();
}
// for (int i = 0; i < selectFiles.length; i++) {
// IFile file = root.getFileForLocation(Path.fromOSString(selectFiles[i].toString()));
// // 如果该文件已经存在于列表中,就向添加到重复集合中
// if (model.getMergeXliffFile().indexOf(file) >= 0) {
// exsistFileList.add(file);
// }
// model.getMergeXliffFile().add(file);
// }
// tableViewer.setInput(getSplitTableInfos());
// if (!validIsRepeate()) {
// validXlf();
// }
}
}
});
Button deleteButton = new Button(buttonComp, SWT.NONE);
deleteButton.setText(Messages.getString("wizard.MergeXliffWizardPage.deleteButton"));
deleteButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
deleteButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
ISelection selection = tableViewer.getSelection();
Table table = tableViewer.getTable();
if (selection != null && !selection.isEmpty()) {
int[] indices = table.getSelectionIndices();
for (int index : indices) {
String fileFullPath = table.getItem(index).getText(1);
for (int i = 0; i < model.getMergeXliffFile().size(); i++) {
if (model.getMergeXliffFile().get(i).getFullPath().toOSString().equals(fileFullPath)) {
model.getMergeXliffFile().remove(i);
break;
}
}
// 如果该文件存在于重复集合中,则从该集合中删除
for (int j = 0; j < exsistFileList.size(); j++) {
if (exsistFileList.get(j).getFullPath().toOSString().equals(fileFullPath)) {
exsistFileList.remove(j);
break;
}
}
}
tableViewer.setInput(getSplitTableInfos());
}
if (!validIsRepeate()) {
validXlf();
}
}
});
}
use of net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog in project translationstudio8 by heartsome.
the class AddOrEditCatalogDialog method browseFiles.
/**
* 选择文件 ;
*/
public void browseFiles() {
FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(getShell(), false, IResource.FILE);
dialog.setMessage(Messages.getString("dialogs.AddOrEditCatalogDialog.dialogMsg"));
dialog.setDoubleClickSelects(true);
try {
dialog.setInput(EFS.getStore(URIUtil.toURI(root.getLocation().append(ADConstants.cataloguePath))));
} catch (CoreException e1) {
e1.printStackTrace();
}
dialog.create();
dialog.getShell().setText(Messages.getString("dialogs.AddOrEditCatalogDialog.dialogTitle"));
dialog.open();
if (dialog.getFirstResult() != null) {
Object object = dialog.getFirstResult();
if (object instanceof LocalFile) {
LocalFile localFile = (LocalFile) object;
String location = localFile.toString();
String catalogurePath = root.getLocation().append(ADConstants.cataloguePath).toOSString();
String uriStr = "";
if (location.indexOf(catalogurePath) != -1) {
uriStr = location.substring(location.indexOf(catalogurePath) + catalogurePath.length(), location.length());
}
uriStr = uriStr.substring(1, uriStr.length());
urlTxt.setText(uriStr);
}
}
}
Aggregations