use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project translationstudio8 by heartsome.
the class OpenConversionDialogHandler method execute.
@Override
public Object execute(ExecutionEvent event, List<IFile> list) {
CommonFunction.removeRepeateSelect(list);
if (list == null || list.size() == 0) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.OpenConversionDialogHandler.msgTitle1"), Messages.getString("handler.OpenConversionDialogHandler.msg1"));
return null;
}
ArrayList<ConverterViewModel> converterViewModels = new ArrayList<ConverterViewModel>();
for (int i = 0; i < list.size(); i++) {
Object adapter = Platform.getAdapterManager().getAdapter(list.get(i), IConversionItem.class);
IConversionItem sourceItem = null;
if (adapter instanceof IConversionItem) {
sourceItem = (IConversionItem) adapter;
}
ConverterViewModel converterViewModel = new ConverterViewModel(Activator.getContext(), Converter.DIRECTION_POSITIVE);
// 记住所选择的文件
converterViewModel.setConversionItem(sourceItem);
converterViewModels.add(converterViewModel);
}
IProject project = list.get(0).getProject();
ConversionWizard wizard = new ConversionWizard(converterViewModels, project);
TSWizardDialog dialog = new TSWizardDialog(shell, wizard) {
@Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
getButton(IDialogConstants.FINISH_ID).setText(Messages.getString("handler.OpenConversionDialogHandler.finishLbl"));
}
};
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
final List<ConverterViewModel> models = wizard.getConverterViewModels();
final List<IFile> targetFiles = new ArrayList<IFile>();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.setTaskName(Messages.getString("handler.OpenConversionDialogHandler.task1"));
monitor.beginTask(Messages.getString("handler.OpenConversionDialogHandler.task2"), models.size());
for (ConverterViewModel converterViewModel : models) {
try {
IProgressMonitor subMonitor = Progress.getSubMonitor(monitor, 1);
subMonitor.setTaskName(Messages.getString("handler.OpenConversionDialogHandler.task3") + converterViewModel.getConversionItem().getLocation().toOSString());
converterViewModel.convertWithoutJob(subMonitor);
List<File> tgtFileList = converterViewModel.getGenerateTgtFileList();
for (File f : tgtFileList) {
IFile tgtIfile = ConverterUtil.localPath2IFile(f.getAbsolutePath());
if (tgtIfile != null) {
targetFiles.add(tgtIfile);
}
}
// 若新转换的 xliff 文件重复,那么关闭已经打开的重复文件,防止文件同步冲突 robert 2013-04-01
Display.getDefault().syncExec(new Runnable() {
public void run() {
CommonFunction.closePointEditor(targetFiles);
}
});
} catch (ConverterException e) {
final String message = e.getMessage();
LOGGER.error("", e);
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(shell, Messages.getString("handler.OpenConversionDialogHandler.msgTitle2"), message);
}
});
} catch (Exception e) {
final String message = e.getMessage();
LOGGER.error("", e);
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(shell, Messages.getString("handler.OpenConversionDialogHandler.msgTitle2"), message);
}
});
}
}
monitor.done();
}
};
try {
new ProgressMonitorDialog(shell).run(true, true, runnable);
} catch (InvocationTargetException e) {
MessageDialog.openError(shell, Messages.getString("handler.OpenConversionDialogHandler.msgTitle2"), e.getMessage());
LOGGER.error("", e);
} catch (InterruptedException e) {
MessageDialog.openError(shell, Messages.getString("handler.OpenConversionDialogHandler.msgTitle2"), e.getMessage());
LOGGER.error(e.getMessage());
}
if (wizard.isOpenPreTranslation()) {
// 加载转换器扩展
final IExecutePretranslation[] impls = new IExecutePretranslation[1];
IConfigurationElement[] config2 = Platform.getExtensionRegistry().getConfigurationElementsFor("net.heartsome.converter.extension.pretranslation");
try {
for (IConfigurationElement e : config2) {
final Object o = e.createExecutableExtension("class");
if (o instanceof IExecutePretranslation) {
ISafeRunnable runnable1 = new ISafeRunnable() {
public void handleException(Throwable exception) {
LOGGER.error(Messages.getString("handler.OpenConversionDialogHandler.logger1"), exception);
}
public void run() throws Exception {
impls[0] = (IExecutePretranslation) o;
}
};
SafeRunner.run(runnable1);
}
}
} catch (CoreException ex) {
LOGGER.error(Messages.getString("handler.OpenConversionDialogHandler.logger1"), ex);
}
if (impls[0] != null) {
if (targetFiles.size() < 1) {
return null;
}
impls[0].executePreTranslation(targetFiles);
}
}
}
return null;
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project translationstudio8 by heartsome.
the class OpenReverseConversionDialogHandler method execute.
public Object execute(ExecutionEvent event, List<IFile> list) {
if (list == null || list.size() == 0) {
MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindow(event).getShell(), Messages.getString("handler.OpenReverseConversionDialogHandler.msgTitle1"), Messages.getString("handler.OpenReverseConversionDialogHandler.msg1"));
return null;
}
// 首先验证是否是合并打开的文件 --robert 2012-10-17
System.out.println(list.get(0).getFullPath().toOSString());
if (isEditor) {
// 针对合并打开
if (list.get(0).getFullPath().toOSString().endsWith(".xlp")) {
List<String> multiFiles = new XLFHandler().getMultiFiles(list.get(0));
if (multiFiles.size() > 0) {
list = new ArrayList<IFile>();
}
for (String filePath : multiFiles) {
list.add(ResourceUtils.fileToIFile(filePath));
}
}
}
List<IFile> lstFiles = new ArrayList<IFile>();
XLFValidator.resetFlag();
for (IFile iFile : list) {
if (!XLFValidator.validateXliffFile(iFile)) {
lstFiles.add(iFile);
}
}
CommonFunction.removeRepeateSelect(list);
XLFValidator.resetFlag();
if (!(list instanceof ArrayList)) {
list = new ArrayList<IFile>(list);
}
list.removeAll(lstFiles);
if (list.size() == 0) {
return null;
}
ArrayList<ConverterViewModel> converterViewModels = new ArrayList<ConverterViewModel>();
for (int i = 0; i < list.size(); i++) {
Object adapter = Platform.getAdapterManager().getAdapter(list.get(i), IConversionItem.class);
IConversionItem sourceItem = null;
if (adapter instanceof IConversionItem) {
sourceItem = (IConversionItem) adapter;
}
ConverterViewModel converterViewModel = new ConverterViewModel(Activator.getContext(), Converter.DIRECTION_REVERSE);
// 记住所选择的文件
converterViewModel.setConversionItem(sourceItem);
converterViewModels.add(converterViewModel);
}
IProject project = list.get(0).getProject();
ReverseConversionWizard wizard = new ReverseConversionWizard(converterViewModels, project);
TSWizardDialog dialog = new TSWizardDialog(shell, wizard) {
@Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
getButton(IDialogConstants.FINISH_ID).setText(Messages.getString("handler.OpenConversionDialogHandler.finishLbl"));
}
};
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
final List<ConverterViewModel> models = wizard.getConverterViewModels();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.setTaskName(Messages.getString("handler.OpenReverseConversionDialogHandler.task1"));
monitor.beginTask(Messages.getString("handler.OpenReverseConversionDialogHandler.task2"), models.size());
for (ConverterViewModel converterViewModel : models) {
try {
IProgressMonitor subMonitor = Progress.getSubMonitor(monitor, 1);
subMonitor.setTaskName(Messages.getString("handler.OpenReverseConversionDialogHandler.task3") + converterViewModel.getConversionItem().getLocation().toOSString());
converterViewModel.convertWithoutJob(subMonitor);
} catch (ConverterException e) {
// Bug #2485:转换文件失败时,提示框显示有问题
throw new InvocationTargetException(e, e.getMessage());
}
}
monitor.done();
}
};
try {
new ProgressMonitorDialog(shell).run(true, true, runnable);
} catch (InvocationTargetException e) {
MessageDialog.openInformation(shell, Messages.getString("handler.OpenReverseConversionDialogHandler.msgTitle2"), e.getMessage());
LOGGER.error("", e);
} catch (InterruptedException e) {
MessageDialog.openInformation(shell, Messages.getString("handler.OpenReverseConversionDialogHandler.msgTitle2"), e.getMessage());
LOGGER.error("", e);
}
}
return null;
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project translationstudio8 by heartsome.
the class PreviewTranslationHandler method previewFiles.
/**
* 预览翻译多个文件
* @param files
* 文件集合
* @throws ExecutionException
* ;
*/
private void previewFiles(final List<IFile> files) throws ExecutionException {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InvocationTargetException {
monitor.setTaskName(Messages.getString("handler.PreviewTranslationHandler.task1"));
monitor.beginTask(Messages.getString("handler.PreviewTranslationHandler.task2"), files.size());
for (IFile file : files) {
IProgressMonitor subMonitor = Progress.getSubMonitor(monitor, 1);
subMonitor.setTaskName(Messages.getString("handler.PreviewTranslationHandler.task3") + file.getLocation().toOSString());
try {
// 预览单个文件
preview(file, subMonitor);
} catch (ExecutionException e) {
throw new InvocationTargetException(e, e.getMessage());
}
}
monitor.done();
}
};
try {
new ProgressMonitorDialog(shell).run(true, true, runnable);
} catch (InvocationTargetException e) {
throw new ExecutionException(e.getMessage(), e);
} catch (InterruptedException e) {
throw new ExecutionException(e.getMessage(), e);
}
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.
the class FileToTableMappingComposite method parseData.
@SuppressWarnings("unchecked")
private void parseData(final Map<String, String> tableToFile) throws Exception {
allTableList = (List<ICubridNode>) treeViewer.getInput();
final List<ICubridNode> newMappedNodeList = new ArrayList<ICubridNode>();
final ImportConfig importConfig = importSettingPage.getImportDataWizard().getImportConfig();
ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
progress.setCancelable(true);
progress.run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
monitor.beginTask(Messages.taskParsingData, tableToFile.size());
for (Entry<String, String> entry : tableToFile.entrySet()) {
// FIXME move this logic to core module
String tableName = entry.getKey();
String filePath = entry.getValue();
File file = new File(filePath);
String fileName = file.getName();
monitor.subTask(Messages.bind(Messages.taskParsingFile, fileName));
List<String> fileColumnList = new ArrayList<String>();
List<String> firstRowColsLst = new ArrayList<String>();
List<String> colNameList = new ArrayList<String>();
List<String> colTypeList = new ArrayList<String>();
int totalLine = 0;
List<Integer> itemsNumberOfSheets = null;
/*Find the class node*/
ICubridNode classNode = getTableNode(tableName);
/*Process file*/
ImportFileHandler importFileHandler = ImportFileHandlerFactory.getHandler(file.getAbsolutePath(), importConfig);
ImportFileDescription ifd = getFileDescription(importFileHandler);
firstRowColsLst.addAll(ifd.getFirstRowCols());
totalLine = ifd.getTotalCount();
itemsNumberOfSheets = ifd.getItemsNumberOfSheets();
boolean isFirstLineAsColumnName = isFirstLineAsColumnName(tableName);
fillInFromList(fileColumnList, firstRowColsLst, isFirstLineAsColumnName);
if (isFirstLineAsColumnName) {
handleSelectEventForFirstRowAsColBtn(itemsNumberOfSheets, fileColumnList, firstRowColsLst, totalLine, isFirstLineAsColumnName);
}
if (classNode != null) {
Object isNew = classNode.getData(ImportObjectLabelProvider.IS_NEW);
if (isNew == null || !(Boolean) isNew) {
SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(tableName);
List<DBAttribute> attributes = schemaInfo == null ? null : schemaInfo.getAttributes();
if (attributes == null) {
return;
}
for (DBAttribute attr : attributes) {
String column = attr.getName();
String dataType = attr.getType();
colNameList.add(column);
colTypeList.add(dataType);
}
} else {
removeClassNode(classNode);
classNode = createClassNode(tableName, isFirstLineAsColumnName(tableName), firstRowColsLst, colNameList, colTypeList);
}
} else if (importConfig.isCreateTableAccordingData()) {
classNode = createClassNode(tableName, isFirstLineAsColumnName(tableName), firstRowColsLst, colNameList, colTypeList);
} else {
failedFileList.add(file.getAbsolutePath());
continue;
}
if (fileColumnList.size() == colNameList.size()) {
classNode.setData(ImportObjectLabelProvider.IS_MAPPED, true);
classNode.setData(ImportObjectLabelProvider.FILE_PAHT, fileName);
classNode.setData(ImportObjectLabelProvider.ROW_COUNT, totalLine);
List<PstmtParameter> parameterList = new ArrayList<PstmtParameter>();
for (int i = 0; i < fileColumnList.size(); i++) {
PstmtParameter pstmtParameter = new PstmtParameter(colNameList.get(i), i + 1, colTypeList.get(i), String.valueOf(i));
pstmtParameter.setFileColumnName(fileColumnList.get(i));
parameterList.add(pstmtParameter);
}
TableConfig tableConfig = new TableConfig(classNode.getName());
tableConfig.setPstmList(parameterList);
tableConfig.setFilePath(file.getAbsolutePath());
tableConfig.setInsertDML(getInsertDML(classNode, colNameList, colTypeList));
tableConfig.setLineCount(totalLine);
tableConfig.setMapped(true);
Object isNew = classNode.getData(ImportObjectLabelProvider.IS_NEW);
if (isNew != null && (Boolean) isNew) {
tableConfig.setCreateDDL(classNode.getData(ImportObjectLabelProvider.CREATE_DDL).toString());
}
importConfig.addTableConfig(tableConfig);
newMappedNodeList.add(classNode);
} else {
classNode.setData(ImportObjectLabelProvider.IS_MAPPED, false);
classNode.setData(ImportObjectLabelProvider.FILE_PAHT, fileName);
classNode.setData(ImportObjectLabelProvider.ROW_COUNT, totalLine);
TableConfig tableConfig = importConfig.getSelectedMap().get(classNode.getName());
if (tableConfig != null) {
tableConfig.setMapped(false);
tableConfig.setFilePath(filePath);
tableConfig.setLineCount(totalLine);
tableConfig.getPstmList().clear();
tableConfig.setInsertDML("");
}
failedFileList.add(fileName);
}
monitor.worked(1);
if (monitor.isCanceled()) {
return;
}
}
}
});
for (ICubridNode node : allTableList) {
if (newMappedNodeList.contains(node)) {
treeViewer.setChecked(node, true);
}
}
treeViewer.refresh();
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.
the class ExportSettingForLoadDBPage method initTableColumnInfo.
/**
* load tables and columns
*/
public void initTableColumnInfo() {
// FIXME move this logic to core module
try {
ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
progress.setCancelable(true);
progress.run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
monitor.beginTask(Messages.taskLoading, 2);
tablesOrViewLst = new ArrayList<ICubridNode>();
List<String> tableNames = new ArrayList<String>();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
StringBuilder sql = new StringBuilder();
sql.append("SELECT c.class_name, c.class_type ");
sql.append("FROM db_class c, db_attribute a ");
sql.append("WHERE c.class_name=a.class_name AND c.is_system_class='NO' ");
sql.append("AND a.from_class_name IS NULL ");
sql.append("GROUP BY c.class_name, c.class_type ");
sql.append("ORDER BY c.class_type, c.class_name");
String query = sql.toString();
// [TOOLS-2425]Support shard broker
if (getDatabase() != null) {
query = DatabaseInfo.wrapShardQuery(getDatabase().getDatabaseInfo(), query);
}
try {
monitor.subTask(Messages.taskLoadingTable);
conn = JDBCConnectionManager.getConnection(getDatabase().getDatabaseInfo(), true);
stmt = conn.createStatement();
rs = stmt.executeQuery(query);
while (rs.next()) {
//$NON-NLS-1$
String tableName = rs.getString(1);
//$NON-NLS-1$
String tableType = rs.getString(2);
if (ConstantsUtil.isExtensionalSystemTable(tableName)) {
continue;
}
String iconPath = "icons/navigator/schema_table_item.png";
if ("VCLASS".equalsIgnoreCase(tableType)) {
//export all view now so don't need select view node
continue;
}
ICubridNode classNode = new DefaultSchemaNode(tableName, tableName, iconPath);
classNode.setContainer(true);
classNode.setType(NodeType.TABLE_COLUMN_FOLDER);
tablesOrViewLst.add(classNode);
tableNames.add(tableName);
}
QueryUtil.freeQuery(rs);
monitor.worked(1);
} catch (SQLException e) {
CommonUITool.openErrorBox(getShell(), e.getErrorCode() + System.getProperty("line.separator") + Messages.importErrorHead + e.getMessage());
LOGGER.error("", e);
} finally {
QueryUtil.freeQuery(conn, stmt, rs);
}
}
});
} catch (Exception e) {
LOGGER.error("", e);
}
}
Aggregations