Search in sources :

Example 1 with NewFolderDialogOfHs

use of net.heartsome.cat.ts.ui.dialog.NewFolderDialogOfHs in project translationstudio8 by heartsome.

the class NewFolderHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    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() && selection instanceof IStructuredSelection) {
            List<?> lstObj = ((IStructuredSelection) selection).toList();
            if (lstObj == null || lstObj.size() != 1) {
                MessageDialog.openInformation(shell, Messages.getString("handlers.NewFolderHandler.msgTitle"), Messages.getString("handlers.NewFolderHandler.msg1"));
                return null;
            }
            IContainer container = null;
            for (Object obj : lstObj) {
                if (obj instanceof IFile) {
                    IFile file = (IFile) obj;
                    container = file.getParent();
                } else if (obj instanceof IFolder) {
                    container = (IFolder) obj;
                } else if (obj instanceof IProject) {
                    container = (IProject) obj;
                }
            }
            ResourcesPlugin.getPlugin().getPluginPreferences().setValue(ResourcesPlugin.PREF_DISABLE_LINKING, true);
            NewFolderDialogOfHs dialog = new NewFolderDialogOfHs(shell, container);
            dialog.open();
        } else {
            MessageDialog.openInformation(shell, Messages.getString("handlers.NewFolderHandler.msgTitle"), Messages.getString("handlers.NewFolderHandler.msg2"));
            return null;
        }
    } else {
        MessageDialog.openInformation(shell, Messages.getString("handlers.NewFolderHandler.msgTitle"), Messages.getString("handlers.NewFolderHandler.msg2"));
        return null;
    }
    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) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) NewFolderDialogOfHs(net.heartsome.cat.ts.ui.dialog.NewFolderDialogOfHs) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

NewFolderDialogOfHs (net.heartsome.cat.ts.ui.dialog.NewFolderDialogOfHs)1 IContainer (org.eclipse.core.resources.IContainer)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Shell (org.eclipse.swt.widgets.Shell)1 IViewPart (org.eclipse.ui.IViewPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1