use of org.eclipse.swt.widgets.Shell in project translationstudio8 by heartsome.
the class WizardExportResourcesPage2 method createButton.
/**
* Creates a new button with the given id.
* <p>
* The <code>Dialog</code> implementation of this framework method creates a standard push button, registers for
* selection events including button presses and registers default buttons with its shell. The button id is stored
* as the buttons client data. Note that the parent's layout is assumed to be a GridLayout and the number of columns
* in this layout is incremented. Subclasses may override.
* </p>
* @param parent
* the parent composite
* @param id
* the id of the button (see <code>IDialogConstants.*_ID</code> constants for standard dialog button ids)
* @param label
* the label from the button
* @param defaultButton
* <code>true</code> if the button is to be the default button, and <code>false</code> otherwise
*/
protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
// increment the number of columns in the button bar
((GridLayout) parent.getLayout()).numColumns++;
Button button = new Button(parent, SWT.PUSH);
GridData buttonData = new GridData(GridData.FILL_HORIZONTAL);
button.setLayoutData(buttonData);
button.setData(new Integer(id));
button.setText(label);
button.setFont(parent.getFont());
if (defaultButton) {
Shell shell = parent.getShell();
if (shell != null) {
shell.setDefaultButton(button);
}
button.setFocus();
}
button.setFont(parent.getFont());
setButtonLayoutData(button);
return button;
}
use of org.eclipse.swt.widgets.Shell in project translationstudio8 by heartsome.
the class SRXConfigrationHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
// IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
Shell shell = HandlerUtil.getActiveShell(event);
// String srxConfigLocation = ADConstants.configLocation + File.separator + ADConstants.AD_SRXConfigFolder;
// // 首先验证本次所要用到的SRX(分段规则)文件是否存在于工作空间中。如果没有,那么将相关文件拷贝到指定工作空间的目录
// File srxConfigFolderFile = new File(srxConfigLocation);
// // 如果不存在,则将安装文件中的相关配置文件复制到工作工间
// if (!srxConfigFolderFile.exists() || !srxConfigFolderFile.isDirectory()
// || new File(srxConfigLocation).list().length <= 0) {
// String srcLocation = Platform.getConfigurationLocation().getURL().getPath() + "net.heartsome.cat.converter"
// + System.getProperty("file.separator") + "srx";
// try {
// ResourceUtils.copyDirectory(new File(srcLocation), new File(srxConfigLocation));
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// File _srxConfigFolderFile = new File(srxConfigLocation);
// if (!_srxConfigFolderFile.exists() || !_srxConfigFolderFile.isDirectory()) {
// MessageDialog.openInformation(shell, Messages.getString("handlers.SRXConfigrationHandler.msgTitle"),
// Messages.getString("handlers.SRXConfigrationHandler.msg"));
// return null;
// }
// }
SrxConfigurationDialog dialog = new SrxConfigurationDialog(shell);
dialog.open();
return null;
}
use of org.eclipse.swt.widgets.Shell in project translationstudio8 by heartsome.
the class AbstractExportHandler method initExportConfig.
public boolean initExportConfig(ExecutionEvent event) throws ExecutionException {
config = new ExportConfig();
Shell shell = HandlerUtil.getActiveShell(event);
String partId = HandlerUtil.getActivePartId(event);
if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
// 导航视图处于激活状态
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (selection != null && !selection.isEmpty()) {
for (Object obj : selection.toList()) {
if (obj instanceof IFile) {
addXLFFile((IFile) obj);
} else if (obj instanceof IFolder) {
traversalFile((IFolder) obj);
} else if (obj instanceof IProject) {
IProject proj = (IProject) obj;
traversalFile(proj.getFolder(XLF));
}
}
if (config.getProjects() == null || config.getProjects().size() < 1) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("xlf2tmx.info.notfoundxlf"));
return false;
}
}
} else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
// nattable 处于激活状态
IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
IXliffEditor xliffEditor = (IXliffEditor) editor;
if (xliffEditor.isMultiFile()) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg2"));
return false;
} else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
addXLFFile(iFile);
}
}
return true;
}
use of org.eclipse.swt.widgets.Shell in project translationstudio8 by heartsome.
the class ExportDocxHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveShell(event);
String partId = HandlerUtil.getActivePartId(event);
IFile file = null;
if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
// 导航视图处于激活状态
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
// ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
List<?> lstObj = ((IStructuredSelection) selection).toList();
ArrayList<IFile> lstXliff = new ArrayList<IFile>();
for (Object obj : lstObj) {
if (obj instanceof IFile) {
IFile tempFile = (IFile) obj;
// Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
if (tempFile.getFileExtension() != null && CommonFunction.validXlfExtension(tempFile.getFileExtension())) {
lstXliff.add(tempFile);
}
}
}
if (lstXliff.size() > 1) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg1"));
return null;
}
if (lstXliff.size() == 1) {
file = lstXliff.get(0);
}
}
} else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
// nattable 处于激活状态
IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
IXliffEditor xliffEditor = (IXliffEditor) editor;
if (xliffEditor.isMultiFile()) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg2"));
return null;
} else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
file = iFile;
}
}
if (file != null) {
XLFValidator.resetFlag();
if (!XLFValidator.validateXliffFile(file)) {
return null;
}
XLFValidator.resetFlag();
}
ExportDocxDialog dialog = new ExportDocxDialog(shell, file == null ? "" : file.getFullPath().toOSString(), file == null ? "" : ResourceUtils.iFileToOSPath(file));
dialog.open();
return null;
}
use of org.eclipse.swt.widgets.Shell in project translationstudio8 by heartsome.
the class ExportExternalHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveShell(event);
if (!initExportConfig(event)) {
return null;
}
config.setShell(shell);
ExportExternalDialog dialog = new ExportExternalDialog(config);
if (Dialog.OK == dialog.open()) {
if (config.getExportType() == ExportExternal.EXPORT_HSPROOF) {
try {
config.doExport();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
try {
progressDialog.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
config.setMonitor(monitor);
try {
config.doExport();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
return null;
}
Aggregations