Search in sources :

Example 26 with Shell

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;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData)

Example 27 with Shell

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;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) SrxConfigurationDialog(net.heartsome.cat.ts.ui.advanced.dialogs.srx.SrxConfigurationDialog)

Example 28 with Shell

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;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ExportConfig(net.heartsome.cat.ts.ui.external.ExportConfig) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) IFolder(org.eclipse.core.resources.IFolder)

Example 29 with Shell

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;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) ExportDocxDialog(net.heartsome.cat.ts.ui.docx.dialog.ExportDocxDialog) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput)

Example 30 with Shell

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;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExportExternalDialog(net.heartsome.cat.ts.ui.docx.dialog.ExportExternalDialog) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

Shell (org.eclipse.swt.widgets.Shell)324 Display (org.eclipse.swt.widgets.Display)49 Button (org.eclipse.swt.widgets.Button)30 SelectionEvent (org.eclipse.swt.events.SelectionEvent)28 Point (org.eclipse.swt.graphics.Point)28 Composite (org.eclipse.swt.widgets.Composite)28 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)27 GridData (org.eclipse.swt.layout.GridData)27 GridLayout (org.eclipse.swt.layout.GridLayout)26 ArrayList (java.util.ArrayList)25 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)23 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)22 IFile (org.eclipse.core.resources.IFile)22 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 File (java.io.File)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)19 Text (org.eclipse.swt.widgets.Text)19 FillLayout (org.eclipse.swt.layout.FillLayout)17 Label (org.eclipse.swt.widgets.Label)17 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)16