org.eclipse.ui.services.IEvaluationService Java Examples

The following examples show how to use org.eclipse.ui.services.IEvaluationService. 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: AbstractViewInstance.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
private void attachVisibleExpression ( final ViewInstanceDescriptor descriptor, final IEvaluationService evaluationService )
{
    if ( descriptor.getVisibleExpression () != null )
    {
        this.visibileRef = evaluationService.addEvaluationListener ( descriptor.getVisibleExpression (), new IPropertyChangeListener () {

            @Override
            public void propertyChange ( final PropertyChangeEvent event )
            {
                if ( PROP_VISIBLE.equals ( event.getProperty () ) && event.getNewValue () instanceof Boolean )
                {
                    setVisibleState ( (Boolean)event.getNewValue () );
                }
            }
        }, PROP_VISIBLE );
    }
    else
    {
        setVisibleState ( true );
    }
}
 
Example #2
Source File: AbstractViewInstance.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
private void attachLazyExpression ( final ViewInstanceDescriptor descriptor, final IEvaluationService evaluationService )
{
    if ( descriptor.getLazyExpression () != null )
    {
        this.lazyRef = evaluationService.addEvaluationListener ( descriptor.getLazyExpression (), new IPropertyChangeListener () {

            @Override
            public void propertyChange ( final PropertyChangeEvent event )
            {
                if ( PROP_LAZY.equals ( event.getProperty () ) && event.getNewValue () instanceof Boolean )
                {
                    setLazy ( (Boolean)event.getNewValue () );
                }
            }
        }, PROP_LAZY );
    }
    else
    {
        setLazy ( false );
    }
}
 
Example #3
Source File: AbstractViewInstance.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
private void attachDefaultInstanceExpression ( final ViewInstanceDescriptor descriptor, final IEvaluationService evaluationService )
{
    if ( descriptor.getDefaultInstanceExpression () != null )
    {
        this.defaultInstanceRef = evaluationService.addEvaluationListener ( descriptor.getDefaultInstanceExpression (), new IPropertyChangeListener () {

            @Override
            public void propertyChange ( final PropertyChangeEvent event )
            {
                if ( PROP_DEFAULT_INSTANCE.equals ( event.getProperty () ) && event.getNewValue () instanceof Boolean )
                {
                    setDefaultInstance ( (Boolean)event.getNewValue () );
                }
            }
        }, PROP_DEFAULT_INSTANCE );
    }
    else
    {
        setDefaultInstance ( descriptor.isDefaultInstance () );
    }
}
 
Example #4
Source File: EngineAddDialog.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object[] getElements(Object inputElement) {
	if(platforms == null ){
		List<PlatformSupport> allPlatforms = HybridCore.getPlatformSupports();
		ArrayList<PlatformSupport> elements = new ArrayList<PlatformSupport>();
		IEvaluationService service = (IEvaluationService)PlatformUI.getWorkbench().getService(IEvaluationService.class);
		for (PlatformSupport generator : allPlatforms) {
			try {
				if(generator.isEnabled(service.getCurrentState())){
					elements.add(generator);
				}
				
			} catch (CoreException e) {
				HybridUI.log(IStatus.ERROR, "Error filtering objects", e);
			}
		}
		platforms = elements.toArray(new PlatformSupport[elements.size()]);
	}
	return platforms;
}
 
Example #5
Source File: AvailableCordovaEnginesSection.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object[] getElements(Object inputElement) {
	if (platforms == null) {
		List<PlatformSupport> allPlatforms = HybridCore.getPlatformSupports();
		ArrayList<PlatformSupport> elements = new ArrayList<PlatformSupport>();
		IEvaluationService service = (IEvaluationService) PlatformUI.getWorkbench()
				.getService(IEvaluationService.class);
		for (PlatformSupport generator : allPlatforms) {
			try {
				if (generator.isEnabled(service.getCurrentState())) {
					elements.add(generator);
				}

			} catch (CoreException e) {
				HybridUI.log(IStatus.ERROR, "Error filtering objects", e);
			}
		}
		platforms = elements.toArray(new PlatformSupport[elements.size()]);
	}
	return platforms;
}
 
Example #6
Source File: ProjectGeneratorContentProvider.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object[] getElements(Object inputElement) {
	if(platforms == null ){
		platforms = HybridCore.getPlatformSupports();
	}
	ArrayList<PlatformSupport> elements = new ArrayList<PlatformSupport>();
	IEvaluationService service = (IEvaluationService)PlatformUI.getWorkbench().getService(IEvaluationService.class);
	for (PlatformSupport generator : platforms) {
		try {
			if(generator.isEnabled(service.getCurrentState())){
				elements.add(generator);
			}
			
		} catch (CoreException e) {
			HybridUI.log(IStatus.ERROR, "Error filtering objects", e);
		}
	}
	return elements.toArray();
}
 
Example #7
Source File: NativeProjectBuilderContentProvider.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object[] getElements(Object inputElement) {
	if(builders == null ){
		builders = HybridCore.getNativeProjectBuilders();
	}
	ArrayList<NativeProjectBuilder> elements = new ArrayList<NativeProjectBuilder>();
	IEvaluationService service = (IEvaluationService)PlatformUI.getWorkbench().getService(IEvaluationService.class);
	for (NativeProjectBuilder builder : builders) {
		try {
			if(builder.isEnabled(service.getCurrentState())){
				elements.add(builder);
			}
			
		} catch (CoreException e) {
			HybridUI.log(IStatus.ERROR, "Error filtering objects", e);
		}
	}

	
	return elements.toArray();
}
 
Example #8
Source File: CloseJUnitStatusActionTest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() {
  evaluationService = mock( IEvaluationService.class );
  workbench = mock( IWorkbench.class );
  when( workbench.getService( IEvaluationService.class ) ).thenReturn( evaluationService );
  preferences = new WorkspaceScopePreferences( new PreferenceStore() );
  action = new CloseJUnitStatusAction( workbench, preferences );
}
 
Example #9
Source File: DefaultPrintTakingsListHandler.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 PrintTakingsListHandler().execute(
		new ExecutionEvent(null, parameterMap, null, evaluationService.getCurrentState()));
	return null;
}
 
Example #10
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 #11
Source File: NattableUtil.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 刷新 Command 的可用状态
 * @param nameSpace
 * @param properties
 *            ;
 */
public static void refreshCommand(String nameSpace, String properties) {
	if (nameSpace != null && properties != null) {
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		IEvaluationService evaluationService = (IEvaluationService) window.getService(IEvaluationService.class);
		if (evaluationService != null) {
			evaluationService.requestEvaluation(nameSpace + "." + properties);
		}
	}
}
 
Example #12
Source File: NattableUtil.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 刷新 Command 的可用状态
 * @param nameSpace
 * @param properties
 *            ;
 */
public static void refreshCommand(String nameSpace, String properties) {
	if (nameSpace != null && properties != null) {
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		IEvaluationService evaluationService = (IEvaluationService) window.getService(IEvaluationService.class);
		if (evaluationService != null) {
			evaluationService.requestEvaluation(nameSpace + "." + properties);
		}
	}
}
 
Example #13
Source File: UIUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public static IResource getSelectedResource()
{
	IEvaluationService evaluationService = (IEvaluationService) PlatformUI.getWorkbench().getService(
			IEvaluationService.class);
	if (evaluationService != null)
	{
		return getSelectedResource(evaluationService.getCurrentState());
	}
	return null;
}
 
Example #14
Source File: VisualInterfaceFactory.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public ViewInstance createViewInstance ( final ViewManager viewManager, final ViewManagerContext viewManagerContext, final ViewInstanceDescriptor descriptor, final Composite viewHolder, final ResourceManager manager, final IWorkbenchPartSite site )
{
    final VisualInterfaceViewInstance instance = new VisualInterfaceViewInstance ( viewManager, viewManagerContext, viewHolder, descriptor, site.getService ( IEvaluationService.class ) );
    instance.init ();
    return instance;
}
 
Example #15
Source File: ExpressionEvaluatorTest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testEvaluate() {
  IEvaluationService evaluationService = mock( IEvaluationService.class );
  when( workbench.getService( IEvaluationService.class ) ).thenReturn( evaluationService );

  new ExpressionEvaluator( workbench ).evaluate();

  verify( evaluationService ).requestEvaluation( PreferencePropertyTester.PROP_IS_TRUE );
}
 
Example #16
Source File: OpenParseErrorViewHandler.java    From tlaplus with MIT License 5 votes vote down vote up
public boolean eventOccured(SpecEvent event) {
	if (event.getType() == SpecEvent.TYPE_PARSE) {
		final IEvaluationService evalService = (IEvaluationService) PlatformUI.getWorkbench().getService(
				IEvaluationService.class);
		evalService.requestEvaluation(ParseErrorTester.PROPERTY_ID);
	}
	return false;
}
 
Example #17
Source File: ChartViewFactory.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public ViewInstance createViewInstance ( final ViewManager viewManager, final ViewManagerContext viewManagerContext, final ViewInstanceDescriptor descriptor, final Composite viewHolder, final ResourceManager manager, final IWorkbenchPartSite site )
{
    final ChartView view = new ChartView ( viewManagerContext, manager, descriptor, viewHolder, (IEvaluationService)site.getService ( IEvaluationService.class ), true );
    view.init ();
    return view;
}
 
Example #18
Source File: ChartView.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public ChartView ( final ViewManagerContext viewManagerContext, final ResourceManager manager, final ViewInstanceDescriptor descriptor, final Composite viewHolder, final IEvaluationService evaluationService, final boolean showSelector )
{
    super ( viewManagerContext, descriptor, evaluationService );
    this.showSelector = showSelector;
    this.viewHolder = viewHolder;
    this.viewManagerContext = viewManagerContext;
}
 
Example #19
Source File: VisualInterfaceViewInstance.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public VisualInterfaceViewInstance ( final ViewManager viewManager, final ViewManagerContext viewManagerContext, final Composite parent, final ViewInstanceDescriptor descriptor, final IEvaluationService evaluationService )
{
    super ( viewManagerContext, descriptor, evaluationService );
    this.parent = parent;

    // create the visual interface view

    this.scriptObjects = new HashMap<String, Object> ();
    this.scriptObjects.put ( "viewManager", viewManager ); //$NON-NLS-1$
}
 
Example #20
Source File: KeybindingsManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private boolean processKeyStroke(Event event, KeyStroke keyStroke)
{
	IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
	KeySequence sequenceBeforeKeyStroke = state.getCurrentSequence();
	KeySequence sequenceAfterKeyStroke = KeySequence.getInstance(sequenceBeforeKeyStroke, keyStroke);

	if (uniqueKeySequences.contains(sequenceAfterKeyStroke))
	{
		IEvaluationService evaluationService = (IEvaluationService) workbench.getService(IEvaluationService.class);
		IEvaluationContext evaluationContext = evaluationService.getCurrentState();
		IWorkbenchPart workbenchPart = (IWorkbenchPart) evaluationContext.getVariable(ISources.ACTIVE_PART_NAME);
		ICommandElementsProvider commandElementsProvider = (ICommandElementsProvider) workbenchPart
				.getAdapter(ICommandElementsProvider.class);
		if (commandElementsProvider != null)
		{
			// Is there a Eclipse binding that matches the key sequence?
			Binding binding = null;
			if (bindingService.isPerfectMatch(sequenceAfterKeyStroke))
			{
				// Record it
				binding = bindingService.getPerfectMatch(sequenceAfterKeyStroke);
			}

			List<CommandElement> commandElements = commandElementsProvider
					.getCommandElements(sequenceAfterKeyStroke);
			if (commandElements.size() == 0)
			{
				if (binding == null)
				{
					// Remember the prefix
					incrementState(sequenceAfterKeyStroke);
				}
				else
				{
					// Reset our state
					resetState();
				}

				// Do not consume the event. Let Eclipse handle it.
				return false;
			}
			else
			{
				if (binding == null && commandElements.size() == 1)
				{
					// We have a unique scripting command to execute
					executeCommandElement(commandElementsProvider, commandElements.get(0));

					// Reset our state
					resetState();

					// The event should be consumed
					return true;
				}
				else
				{
					// We need to show commands menu to the user
					IContextService contextService = (IContextService) workbench.getService(IContextService.class);
					popup(workbenchPart.getSite().getShell(), bindingService, contextService,
							commandElementsProvider, commandElements, event, binding,
							getInitialLocation(commandElementsProvider));

					// Reset our state
					resetState();

					// The event should be consumed
					return true;
				}
			}
		}
	}
	else if (uniqueKeySequencesPrefixes.contains(sequenceAfterKeyStroke))
	{
		// Prefix match

		// Is there a Eclipse command with a perfect match
		if (bindingService.isPerfectMatch(sequenceAfterKeyStroke))
		{
			// Reset our state
			resetState();
		}
		else
		{
			// Remember the prefix
			incrementState(sequenceAfterKeyStroke);
		}
	}
	else
	{
		// Reset our state
		resetState();
	}

	// We did not handle the event. Do not consume the event. Let Eclipse handle it.
	return false;
}
 
Example #21
Source File: ExpressionEvaluatorTest.java    From eclipse-extras with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testEvaluateWithoutEvaluationService() {
  new ExpressionEvaluator( workbench ).evaluate();

  verify( workbench ).getService( IEvaluationService.class );
}
 
Example #22
Source File: ConcordanceSearchHandler.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	if (!isEnabled()) {
		return null;
	}
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (editor instanceof IXliffEditor) {
		IXliffEditor xliffEditor = (IXliffEditor) editor;
		String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";

		IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
				.getActiveEditor();
		if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
			// IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
			IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
			ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
			List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
			if (lstDatabase.size() == 0) {
				MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
						Messages.getString("handler.ConcordanceSearchHandler.msgTitle"),
						Messages.getString("handler.ConcordanceSearchHandler.msg"));
				return null;
			}

			String selectText = xliffEditor.getSelectPureText();
			if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
				selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
			} else if (selectText == null) {
				selectText = "";
			}
			String srcLang = xliffEditor.getSrcColumnName();
			String tgtLang = xliffEditor.getTgtColumnName();
			ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file,
					srcLang,tgtLang, selectText.trim());
			Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
			Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
			dialog.open();
			if (srcLangL.isBidi() || tgtLangL.isBidi()) {
				dialog.getShell().setOrientation(SWT.RIGHT_TO_LEFT);
			}
			if (selectText != null && !selectText.trim().equals("")) {
				dialog.initGroupIdAndSearch();
				IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
				ICommandService commandService = (ICommandService) site.getService(
						ICommandService.class);
				Command command = commandService
						.getCommand(ActionFactory.COPY.getCommandId());
				IEvaluationService evalService = (IEvaluationService) site.getService(
						IEvaluationService.class);
				IEvaluationContext currentState = evalService.getCurrentState();
				ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
				try {
					command.executeWithChecks(executionEvent);
				} catch (Exception e1) {}
			}
		}
	}
	return null;
}
 
Example #23
Source File: ExpressionEvaluator.java    From eclipse-extras with Eclipse Public License 1.0 4 votes vote down vote up
private IEvaluationService getEvaluationService() {
  return workbench == null ? null : ( IEvaluationService )workbench.getService( IEvaluationService.class );
}
 
Example #24
Source File: ExpressionEvaluator.java    From eclipse-extras with Eclipse Public License 1.0 4 votes vote down vote up
public void evaluate() {
  IEvaluationService evaluationService = getEvaluationService();
  if( evaluationService != null ) {
    evaluationService.requestEvaluation( PreferencePropertyTester.PROP_IS_TRUE );
  }
}
 
Example #25
Source File: ConcordanceSearchHandler.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	if (!isEnabled()) {
		return null;
	}
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (editor instanceof IXliffEditor) {
		String tshelp = System.getProperties().getProperty("TSHelp");
		String tsstate = System.getProperties().getProperty("TSState");
		if (tshelp == null || !"true".equals(tshelp) || tsstate == null || !"true".equals(tsstate)) {
			LoggerFactory.getLogger(ConcordanceSearchHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
			System.exit(0);
		}
		IXliffEditor xliffEditor = (IXliffEditor) editor;
		String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";

		IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
				.getActiveEditor();
		if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
			// IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
			IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
			ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
			List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
			if (lstDatabase.size() == 0) {
				MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
						Messages.getString("handler.ConcordanceSearchHandler.msgTitle"),
						Messages.getString("handler.ConcordanceSearchHandler.msg"));
				return null;
			}

			String selectText = xliffEditor.getSelectPureText();
			if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
				selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
			} else if (selectText == null) {
				selectText = "";
			}
			ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file,
					xliffEditor.getSrcColumnName(), xliffEditor.getTgtColumnName(), selectText.trim());
			dialog.open();
			if (selectText != null && !selectText.trim().equals("")) {
				dialog.initGroupIdAndSearch();
				IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
				ICommandService commandService = (ICommandService) site.getService(
						ICommandService.class);
				Command command = commandService
						.getCommand(ActionFactory.COPY.getCommandId());
				IEvaluationService evalService = (IEvaluationService) site.getService(
						IEvaluationService.class);
				IEvaluationContext currentState = evalService.getCurrentState();
				ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
				try {
					command.executeWithChecks(executionEvent);
				} catch (Exception e1) {}
			}
		}
	}
	return null;
}
 
Example #26
Source File: AbstractViewInstance.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public AbstractViewInstance ( final ViewManagerContext viewManagerContext, final ViewInstanceDescriptor descriptor, final IEvaluationService evaluationService )
{
    this.viewManagerContext = viewManagerContext;
    this.evaluationService = evaluationService;
    this.descriptor = descriptor;
}