org.eclipse.ui.handlers.HandlerUtil Java Examples

The following examples show how to use org.eclipse.ui.handlers.HandlerUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EditEigenartikelUi.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	try {
		// get the parameter
		String param = event.getParameter(PARAMETERID);
		PersistentObject artikel =
			(PersistentObject) event.getCommand().getParameterType(PARAMETERID)
				.getValueConverter().convertToObject(param);
		// create and open the dialog with the parameter
		Shell parent = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
		ArtikelDetailDialog dialog = new ArtikelDetailDialog(parent, artikel);
		dialog.open();
	} catch (Exception ex) {
		throw new RuntimeException(COMMANDID, ex);
	}
	return null;
}
 
Example #2
Source File: DocumentExportHandler.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
	ISelection selection = HandlerUtil.getCurrentSelection(event);
	if (selection instanceof StructuredSelection
		&& !((StructuredSelection) selection).isEmpty()) {
		List<?> iDocuments = ((StructuredSelection) selection).toList();
		
		for (Object documentToExport : iDocuments) {
			if (documentToExport instanceof IDocument) {
				openExportDialog(shell, (IDocument) documentToExport);
			}
		}
	}
	return null;
}
 
Example #3
Source File: OpenModelHandlerDelegate.java    From tlaplus with MIT License 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException
{
    /*
     * Try to get the spec from active navigator if any
     */
    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    if (selection != null && selection instanceof IStructuredSelection
            && ((IStructuredSelection) selection).size() == 1)
    {
        Object selected = ((IStructuredSelection) selection).getFirstElement();
        if (selected instanceof Model)
        {
            Map<String, String> parameters = new HashMap<String, String>();

            // fill the model name for the handler
            parameters.put(OpenModelHandler.PARAM_MODEL_NAME, ((Model) selected).getName());
            // delegate the call to the open model handler
            UIHelper.runCommand(OpenModelHandler.COMMAND_ID, parameters);
        }
    }
    return null;
}
 
Example #4
Source File: NeedReviewSegmentHandler.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (editor instanceof XLIFFEditorImplWithNatTable) {
		XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
		XLFHandler handler = xliffEditor.getXLFHandler();
		List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
		boolean isNeedReview = true;
		//先判断所有的选择文本段的是否锁定状态
		for(String rowId : selectedRowIds){
			if (!handler.isNeedReview(rowId)) {
				isNeedReview = false;
				break;
			}
		}
		NattableUtil util = NattableUtil.getInstance(xliffEditor);
		util.changIsQuestionState(selectedRowIds, isNeedReview ? "no" : "yes");
	}
	return null;
}
 
Example #5
Source File: RemoveConnectionHandler.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
            .getActivePage().getSelection();
	if(selection instanceof TreeSelection) {
		TreeSelection treeSelection = (TreeSelection) selection;
		if(treeSelection.getFirstElement() instanceof File) {
			File file = (File) treeSelection.getFirstElement();
			if(file.getFileExtension().equals("bib")){
				WorkspaceBibTexEntry entry = wm.getWorkspaceBibTexEntryByUri(file.getLocationURI());
				if(entry != null) {
					if(entry.getMendeleyFolder() != null) {
						// by setting the MendeleyFolder of a WorkspaceBibTexEntry to null, the connection will be removed
						entry.setMendeleyFolder(null);
						decoratorManager.update("de.tudresden.slr.model.mendeley.decorators.MendeleyOverlayDecorator");
					}
				}
			}
		}
	}
	return null;
}
 
Example #6
Source File: CopyExperimentHandler.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    // Get selection already validated by handler in plugin.xml
    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    if (!(selection instanceof IStructuredSelection)) {
        return null;
    }
    TmfExperimentElement experiment = (TmfExperimentElement) ((IStructuredSelection) selection).getFirstElement();

    // Fire the Copy Experiment dialog
    Shell shell = HandlerUtil.getActiveShellChecked(event);
    CopyExperimentDialog dialog = new CopyExperimentDialog(shell, experiment);
    dialog.open();

    return null;
}
 
Example #7
Source File: DeleteTuHandler.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	TmxEditorViewer viewer = TmxEditorViewer.getInstance();
	if (viewer == null) {
		return null;
	}
	TmxEditor editor = viewer.getTmxEditor();
	if (editor == null) {
		return null;
	}
	if (editor.getTmxDataAccess().getDisplayTuCount() == 0
			|| editor.getTmxEditorImpWithNattable().getSelectedRows().length == 0) {
		OpenMessageUtils.openMessage(IStatus.INFO, Messages.getString("tmxeditor.deleteTuHandler.noSelectedMsg"));
		return null;
	}
	boolean confirm = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event),
			Messages.getString("tmxeditor.deleteTuHandler.warn.msg"),
			Messages.getString("tmxeditor.deleteTuHandler.warn.desc"));
	if (!confirm) {
		return null;
	}
	editor.deleteSelectedTu();
	IOperationHistory histor = OperationHistoryFactory.getOperationHistory();
	histor.dispose(PlatformUI.getWorkbench().getOperationSupport().getUndoContext(), true, true, true);
	return null;
}
 
Example #8
Source File: NotSendToTMHandler.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (editor instanceof XLIFFEditorImplWithNatTable) {
		XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
		List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
		if (selectedRowIds != null && selectedRowIds.size() > 0) {
			boolean isSendtoTm = true;
			XLFHandler handler = xliffEditor.getXLFHandler();
			for (String rowId : selectedRowIds) {
				if (!handler.isSendToTM(rowId) && isSendtoTm) {
					isSendtoTm = false;
					break;
				}
			}
			NattableUtil util = NattableUtil.getInstance(xliffEditor);
			util.changeSendToTmState(selectedRowIds, isSendtoTm ? "yes" : "no");
		}
	}
	return null;
}
 
Example #9
Source File: DeleteTemplateCommand.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	ISelection selection =
		HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
	if (selection != null) {
		IStructuredSelection strucSelection = (IStructuredSelection) selection;
		Object firstElement = strucSelection.getFirstElement();
		if (firstElement != null && firstElement instanceof TextTemplate) {
			TextTemplate textTemplate = (TextTemplate) firstElement;
			Brief template = textTemplate.getTemplate();
			textTemplate.removeTemplateReference();
			
			if (template != null) {
				template.delete();
				
				ElexisEventDispatcher.getInstance().fire(new ElexisEvent(Brief.class, null,
					ElexisEvent.EVENT_RELOAD, ElexisEvent.PRIORITY_NORMAL));
			}
		}
	}
	
	return null;
}
 
Example #10
Source File: TLAOpenElementSelectionDialogHandler.java    From tlaplus with MIT License 6 votes vote down vote up
public Object execute(final ExecutionEvent event) throws ExecutionException {
	final FilteredItemsSelectionDialog dialog = new TLAFilteredItemsSelectionDialog(HandlerUtil.getActiveShell(event));
	dialog.open();
	
	final Object[] result = dialog.getResult();
	if (result != null && result.length == 1) {
		final Map<String, String> parameters = new HashMap<String, String>();
		if (result[0] instanceof Module && ((Module) result[0]).isRoot()) {
			parameters.put(OpenSpecHandler.PARAM_SPEC, ((Module) result[0]).getModuleName());
			UIHelper.runCommand(OpenSpecHandler.COMMAND_ID, parameters);
		} else if (result[0] instanceof Module) {
			parameters.put(OpenModuleHandler.PARAM_MODULE, ((Module) result[0]).getModuleName());
			UIHelper.runCommand(OpenModuleHandler.COMMAND_ID, parameters);
		} else if (result[0] instanceof Model) {
			parameters.put(OpenModelHandler.PARAM_MODEL_NAME, ((Model) result[0]).getName());
			UIHelper.runCommand(OpenModelHandler.COMMAND_ID, parameters);
		} else if (result[0] instanceof Spec) {
			parameters.put(OpenSpecHandler.PARAM_SPEC, ((Spec) result[0]).getName());
			UIHelper.runCommand(OpenSpecHandler.COMMAND_ID, parameters);
		}
	}
	return null;
}
 
Example #11
Source File: ShowNextFuzzyHandler.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	int[] selectedRows = xliffEditor.getSelectedRows();
	if (selectedRows.length < 1) {
		return null;
	}
	Arrays.sort(selectedRows);
	int lastSelectedRow = selectedRows[selectedRows.length - 1];
	XLFHandler handler = xliffEditor.getXLFHandler();

	int row = handler.getNextFuzzySegmentIndex(lastSelectedRow);
	if (row != -1) {
		xliffEditor.jumpToRow(row);
	} else {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		MessageDialog.openWarning(window.getShell(), "", "不存在下一模糊匹配文本段。");
	}

	return null;
}
 
Example #12
Source File: OpenXFindPanelHandler.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override // IHandler
public Object execute(ExecutionEvent event) throws ExecutionException {

    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    IEditorPart part = window.getActivePage().getActiveEditor();

    XFindPanel panel = XFindPanelManager.getXFindPanel(part, true);
    if (panel != null) {
        panel.showPanel();
    }
    else {
        // failed to create XFindPanel, execute standard command "Find and Replace".   
        IHandlerService handlerService = (IHandlerService)window.getService(IHandlerService.class);
        try {
            handlerService.executeCommand(IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE, null);
        } catch (Exception ex) {
            LogHelper.logError("Command " + IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE + " not found");   //$NON-NLS-1$ //$NON-NLS-2$
        }
    }

    return null;
}
 
Example #13
Source File: ServiceUtils.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an OSGi service from {@link ExecutionEvent}. It looks up a service in the following
 * locations (if exist) in the given order:
 *
 * {@code HandlerUtil.getActiveSite(event)}
 * {@code HandlerUtil.getActiveEditor(event).getEditorSite()}
 * {@code HandlerUtil.getActiveEditor(event).getSite()}
 * {@code HandlerUtil.getActiveWorkbenchWindow(event)}
 * {@code PlatformUI.getWorkbench()}
 */
public static <T> T getService(ExecutionEvent event, Class<T> api) {
  IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
  if (activeSite != null) {
    return activeSite.getService(api);
  }

  IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
  if (activeEditor != null) {
    IEditorSite editorSite = activeEditor.getEditorSite();
    if (editorSite != null) {
      return editorSite.getService(api);
    }
    IWorkbenchPartSite site = activeEditor.getSite();
    if (site != null) {
      return site.getService(api);
    }
  }

  IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
  if (workbenchWindow != null) {
    return workbenchWindow.getService(api);
  }

  return PlatformUI.getWorkbench().getService(api);
}
 
Example #14
Source File: ProjectFromSelectionHelper.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
public static List<IProject> getProjects(ExecutionEvent event) throws ExecutionException {
  List<IProject> projects = new ArrayList<>();

  ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
  if (selection instanceof IStructuredSelection) {
    IStructuredSelection structuredSelection = (IStructuredSelection) selection;
    for (Object selected : structuredSelection.toList()) {
      IProject project = AdapterUtil.adapt(selected, IProject.class);
      if (project != null) {
        projects.add(project);
      }
    }
  }

  return projects;
}
 
Example #15
Source File: CreateEigenleistungUi.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	try {
		// create and open the dialog
		Shell parent = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
		EigenLeistungDialog dialog = new EigenLeistungDialog(parent, null);
		// open dialog and add created IVerrechenbar to the selected Leistungsblock
		if (dialog.open() == Dialog.OK) {
			Optional<ICodeElementBlock> block =
				ContextServiceHolder.get().getTyped(ICodeElementBlock.class);
			if (block.isPresent()) {
				IVerrechenbar created = dialog.getResult();
				Optional<Identifiable> createdIdentifiable = StoreToStringServiceHolder.get()
					.loadFromString(((PersistentObject) created).storeToString());
				createdIdentifiable.ifPresent(ci -> {
					block.get().addElement((ICodeElement) ci);
					ContextServiceHolder.get().postEvent(ElexisEventTopics.EVENT_UPDATE,
						block.get());
				});
			}
		}
	} catch (Exception ex) {
		throw new RuntimeException(COMMANDID, ex);
	}
	return null;
}
 
Example #16
Source File: EditLabItemUi.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	try {
		// get the parameter
		String param = event.getParameter(PARAMETERID);
		PersistentObject labitem =
			(PersistentObject) event.getCommand().getParameterType(PARAMETERID)
				.getValueConverter().convertToObject(param);
		// create and open the dialog with the parameter
		Shell parent = HandlerUtil.getActiveShell(event);
		EditLabItem dialog = new EditLabItem(parent, (LabItem) labitem);
		dialog.open();
	} catch (Exception ex) {
		throw new RuntimeException(COMMANDID, ex);
	}
	return null;
}
 
Example #17
Source File: ChangeSourceEditableHandler.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
		if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
			XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
			ICellEditor cellEditor = xliffEditor.getTable().getConfigRegistry().getConfigAttribute(
					EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, XLIFFEditorImplWithNatTable.SOURCE_EDIT_CELL_LABEL);
			if (cellEditor == null || !(cellEditor instanceof StyledTextCellEditor)) {
				return null;
			}
			HsMultiActiveCellEditor.commit(false);
			StyledTextCellEditor sce = (StyledTextCellEditor) cellEditor;
			EditableManager editableManager = sce.getEditableManager();
//			SourceEditMode nextMode = editableManager.getSourceEditMode().getNextMode();
			SourceEditMode nextMode = getSourceEditMode(editableManager);
			editableManager.setSourceEditMode(nextMode);
//			element.setIcon(Activator.getImageDescriptor(nextMode.getImagePath()));
			if (!sce.isClosed()) {
				editableManager.judgeEditable();
//				更新全局 Action 的可用状态,主要是更新编辑-删除功能的可用状态。
				sce.getActionHandler().updateActionsEnableState();
			}
			
			sce.addClosingListener(listener);
		}
		return null;
	}
 
Example #18
Source File: RefreshHandler.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    if (selection instanceof IStructuredSelection) {
        for (Object element : ((IStructuredSelection) selection).toList()) {
            if (element instanceof ITmfProjectModelElement) {
                IResource resource = ((ITmfProjectModelElement) element).getResource();
                if (resource != null) {
                    try {
                        resource.refreshLocal(IResource.DEPTH_INFINITE, null);
                    } catch (CoreException e) {
                        Activator.getDefault().logError("Error refreshing projects", e); //$NON-NLS-1$
                    }
                }
            }
        }
    }
    return null;
}
 
Example #19
Source File: OpenCiteHandler.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

	// get selection
	ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
	if (selection == null || !(selection instanceof IStructuredSelection)) {
		return null;
	}
	Map<String, Integer> data = processSelectionData((IStructuredSelection) selection);

	boolean dataWrittenSuccessfully = false;
	try {
		// overwrite csv with new data
		dataWrittenSuccessfully = overwriteCSVFile(data);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	// call website on writen file
	if (dataWrittenSuccessfully) {
		Program.launch(Activator.getUrl() + "bar.index.html");
	}

	return null;
}
 
Example #20
Source File: ShowNextUnapprovedHandler.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	int[] selectedRows = xliffEditor.getSelectedRows();
	if (selectedRows.length < 1) {
		return null;
	}
	Arrays.sort(selectedRows);
	int lastSelectedRow = selectedRows[selectedRows.length - 1];
	XLFHandler handler = xliffEditor.getXLFHandler();

	int row = handler.getNextUnapprovedSegmentIndex(lastSelectedRow);
	if (row != -1) {
		xliffEditor.jumpToRow(row);
	} else {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		MessageDialog.openWarning(window.getShell(), "", "不存在下一个未批准文本段。");
	}

	return null;
}
 
Example #21
Source File: RenameRefactoringHandler.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	RenameRefactoringInfo refactoringInfo = getRenameRefactoringInfo();
	if (refactoringInfo == null) {
		MessageDialog.openError(HandlerUtil.getActiveShell(event), Messages.RenameCompilationUnitHandler_InvalidSelection, Messages.RenameCompilationUnitHandler_CannotPerformRefactoringWithCurrentSelection);
		return null;
	}
	
	if (DebugCommons.isProjectInDebug(refactoringInfo.getProject())) {
		MessageDialog.openError(HandlerUtil.getActiveShell(event), Messages.RenameCompilationUnitHandler_ProjectDebugged, Messages.RenameCompilationUnitHandler_CannotChangeFilesOfDebuggedProject);
		return null;
	}
	
	RenameRefactoringProcessor refactoringProcessor = new RenameRefactoringProcessor(refactoringInfo);
	RenameRefactoring renameRefactoring = new RenameRefactoring(refactoringProcessor);
	RenameRefactoringWizard wizard = new RenameRefactoringWizard(renameRefactoring, refactoringInfo);
	
	RefactoringWizardOpenOperation op 
      = new RefactoringWizardOpenOperation( wizard );
    try {
      String titleForFailedChecks = ""; //$NON-NLS-1$
      op.run( HandlerUtil.getActiveShell(event), titleForFailedChecks );
    } catch( final InterruptedException irex ) {
    }
	return null;
}
 
Example #22
Source File: ShowPreviousSegmentHandler.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	int[] selectedRows = xliffEditor.getSelectedRows();
	if (selectedRows.length < 1) {
		return null;
	}
	Arrays.sort(selectedRows);
	int firstSelectedRow = selectedRows[0];
	if (firstSelectedRow == 0) {
		firstSelectedRow = 1;
	}
	xliffEditor.jumpToRow(firstSelectedRow - 1);
	return null;
}
 
Example #23
Source File: DefaultPrintRecipeHandler.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	HashMap<String, String> parameterMap = new HashMap<>();
	parameterMap.put("ch.elexis.core.ui.medication.commandParameter.medication", "fix");
	IEvaluationService evaluationService = (IEvaluationService) HandlerUtil.getActiveSite(event)
		.getService(IEvaluationService.class);
	new PrintRecipeHandler().execute(
		new ExecutionEvent(null, parameterMap, null, evaluationService.getCurrentState()));
	return null;
}
 
Example #24
Source File: PreviewTranslationHandler.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (editor == null) {
		return false;
	}
	IEditorInput input = editor.getEditorInput();
	IFile file = ResourceUtil.getFile(input);
	shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
	if (file == null) {
		MessageDialog.openInformation(shell, "提示", "未找当前编辑器打开的文件资源。");
	} else {
		String fileExtension = file.getFileExtension();
		if (fileExtension != null && "xlf".equalsIgnoreCase(fileExtension)) {
			ConverterViewModel model = getConverterViewModel(file);
			if (model != null) {
				model.convert();
			}
		} else if (fileExtension != null && "xlp".equalsIgnoreCase(fileExtension)) {
			if (file.exists()) {
				IFolder xliffFolder = file.getProject().getFolder(Constant.FOLDER_XLIFF);
				if (xliffFolder.exists()) {
					ArrayList<IFile> files = new ArrayList<IFile>();
					try {
						getChildFiles(xliffFolder, "xlf", files);
					} catch (CoreException e) {
						throw new ExecutionException(e.getMessage(), e);
					}
					previewFiles(files);
				} else {
					MessageDialog.openWarning(shell, "提示", "未找到系统默认的 XLIFF 文件夹!");
				}
			}
		} else {
			MessageDialog.openInformation(shell, "提示", "当前编辑器打开的文件不是一个合法的 XLIFF 文件。");
		}
	}
	return null;
}
 
Example #25
Source File: DeleteTermHandler.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
	if (selection == null || !(selection instanceof IStructuredSelection)) {
		return null;
	}
	IStructuredSelection currentSelection = (IStructuredSelection) selection;
	if (currentSelection.size() > 0) {			
		MessageDialog dialog = new MessageDialog(null,
				"Delete Term",
				null,
				"Are you sure you want to delete terms: " + 
						currentSelection.toList()
							.stream()
							.filter(s -> s instanceof Term)
							.map(s -> ((Term) s).getName())
							.collect(Collectors.joining(", ")),
				MessageDialog.QUESTION,
				new String[]{"Yes", "Cancel"},
				0);
		dialog.setBlockOnOpen(true);
		if (dialog.open() == MessageDialog.OK && dialog.getReturnCode() == MessageDialog.OK) {
			List<Term> termsToDelete = new ArrayList<>(currentSelection.size());
			currentSelection.toList().stream()
					.filter(s -> s instanceof Term)
					.forEach(s -> termsToDelete.add((Term) s));;
			TermDeleter.delete(termsToDelete);
		}
	}
	
	return null;
}
 
Example #26
Source File: PrintTakingsListHandler.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private List<IPrescription> getPrescriptions(IPatient patient, String medicationType,
	ExecutionEvent event){
	if ("selection".equals(medicationType)) {
		ISelection selection =
			HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
		if (selection != null && !selection.isEmpty()) {
			List<IPrescription> ret = new ArrayList<IPrescription>();
			IStructuredSelection strucSelection = (IStructuredSelection) selection;
			if (strucSelection.getFirstElement() instanceof MedicationTableViewerItem) {
				List<MedicationTableViewerItem> mtvItems =
					(List<MedicationTableViewerItem>) strucSelection.toList();
				for (MedicationTableViewerItem mtvItem : mtvItems) {
					IPrescription p = mtvItem.getPrescription();
					if (p != null) {
						ret.add(p);
					}
				}
			} else if (strucSelection.getFirstElement() instanceof IPrescription) {
				ret.addAll(strucSelection.toList());
			}
			return ret;
		}
	} else if ("all".equals(medicationType)) {
		return patient.getMedication(Arrays.asList(EntryType.FIXED_MEDICATION,
			EntryType.RESERVE_MEDICATION, EntryType.SYMPTOMATIC_MEDICATION));
	} else if ("fix".equals(medicationType)) {
		return patient.getMedication(Arrays.asList(EntryType.FIXED_MEDICATION));
	} else if ("reserve".equals(medicationType)) {
		return patient.getMedication(Arrays.asList(EntryType.RESERVE_MEDICATION));
	}
	return Collections.emptyList();
}
 
Example #27
Source File: NewImpexWizardHandler.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public Object execute( ExecutionEvent event ) throws ExecutionException
{
	Shell activeShell = HandlerUtil.getActiveShell(event);
	NewImpexWizard newWizard = new NewImpexWizard();
	newWizard.setCurrentSelection(HandlerUtil.getCurrentSelection(event));
	
	IWizard wizard = (IWizard) newWizard;
	WizardDialog dialog = new WizardDialog(activeShell, wizard);
	dialog.open();
	return null;
}
 
Example #28
Source File: NewSpecHandler.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
public Object execute(ExecutionEvent event) throws ExecutionException
{
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);

    // Create the wizard
    NewSpecWizard wizard = new NewSpecWizard(event.getParameter(PARAM_PATH));
    // we pass null for structured selection, cause we just not using it
    wizard.init(window.getWorkbench(), null);
    Shell parentShell = window.getShell();
    // Create the wizard dialog
    WizardDialog dialog = new WizardDialog(parentShell, wizard);
    dialog.setHelpAvailable(true);
    
    // Open the wizard dialog
    if (Window.OK == dialog.open() && wizard.getRootFilename() != null)
    {
    	// read UI values from the wizard page
    	final boolean importExisting = wizard.isImportExisting();
    	final String specName = wizard.getSpecName();
    	final String rootFilename = wizard.getRootFilename();
        
        // the moment the user clicks finish on the wizard page does
        // not correspond with the availability of the spec object
        // it first has to be created/parsed fully before it can be shown in
        // the editor. Thus, delay opening the editor until parsing is done.        	
        createModuleAndSpecInNonUIThread(rootFilename, importExisting, specName);
    }

    return null;
}
 
Example #29
Source File: ConvertJavaCodeHandler.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
	ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
	if (currentSelection instanceof IStructuredSelection) {
		IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
		final Set<ICompilationUnit> compilationUnits = getCompilationUnits(structuredSelection);
		if (compilationUnits.size() > 0) {
			Shell activeShell = HandlerUtil.getActiveShell(event);
			javaConverterProvider.get().runJavaConverter(compilationUnits, activeShell);
		}
	}
	return null;
}
 
Example #30
Source File: QuickFindPreviousOccurrenceHandler.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * {@inheritDoc}
   */
  @Override // IHandler
  public Object execute(ExecutionEvent event) throws ExecutionException {
      IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
      IEditorPart part = window.getActivePage().getActiveEditor();
if (part != null && !XFindPanelManager.isXFindPanelOpened(part)) {
          QuickXFind.findPrevious(part);
      }
      return null;
  }