Search in sources :

Example 16 with Presentation

use of org.eclipse.che.ide.api.action.Presentation in project che by eclipse.

the class FindActionPresenter method nameChanged.

@Override
public void nameChanged(String name, boolean checkBoxState) {
    if (name.isEmpty()) {
        view.hideActions();
        return;
    }
    String pattern = convertPattern(name.trim());
    RegExp regExp = RegExp.compile(pattern);
    Map<Action, String> actions = new TreeMap<>(actionComparator);
    if (checkBoxState) {
        Set<String> ids = ((ActionManagerImpl) actionManager).getActionIds();
        for (Action action : actionsMap.keySet()) {
            ids.remove(actionManager.getId(action));
        }
        for (String id : ids) {
            Action action = actionManager.getAction(id);
            Presentation presentation = action.getTemplatePresentation();
            String text = presentation.getText();
            if (text != null && regExp.test(text)) {
                actions.put(action, null);
            }
        }
    }
    List<String> excludedActionIds = getExcludedActionIds(actionManager);
    for (Entry<Action, String> entry : actionsMap.entrySet()) {
        final Action action = entry.getKey();
        final String groupName = entry.getValue();
        if (excludedActionIds.contains(actionManager.getId(action))) {
            continue;
        }
        Presentation presentation = action.getTemplatePresentation();
        String text = presentation.getText();
        if (text != null && regExp.test(text)) {
            actions.put(action, groupName);
        }
    }
    if (!actions.isEmpty()) {
        view.showActions(actions);
    } else {
        view.hideActions();
    }
}
Also used : Action(org.eclipse.che.ide.api.action.Action) RegExp(com.google.gwt.regexp.shared.RegExp) ActionManagerImpl(org.eclipse.che.ide.actions.ActionManagerImpl) TreeMap(java.util.TreeMap) Presentation(org.eclipse.che.ide.api.action.Presentation)

Example 17 with Presentation

use of org.eclipse.che.ide.api.action.Presentation in project che by eclipse.

the class FullTextSearchActionTest method actionShouldBeDisabled.

@Test
public void actionShouldBeDisabled() {
    Presentation presentation = Mockito.mock(Presentation.class);
    when(actionEvent.getPresentation()).thenReturn(presentation);
    when(appContext.getRootProject()).thenReturn(null);
    fullTextSearchAction.updateInPerspective(actionEvent);
    verify(presentation).setVisible(true);
    verify(presentation).setEnabled(false);
}
Also used : Presentation(org.eclipse.che.ide.api.action.Presentation) Test(org.junit.Test)

Aggregations

Presentation (org.eclipse.che.ide.api.action.Presentation)17 Action (org.eclipse.che.ide.api.action.Action)10 ActionEvent (org.eclipse.che.ide.api.action.ActionEvent)9 ActionGroup (org.eclipse.che.ide.api.action.ActionGroup)7 CustomComponentAction (org.eclipse.che.ide.api.action.CustomComponentAction)4 Separator (org.eclipse.che.ide.api.action.Separator)4 Test (org.junit.Test)3 Widget (com.google.gwt.user.client.ui.Widget)2 DefaultActionGroup (org.eclipse.che.ide.api.action.DefaultActionGroup)2 DivElement (com.google.gwt.dom.client.DivElement)1 Element (com.google.gwt.dom.client.Element)1 RegExp (com.google.gwt.regexp.shared.RegExp)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 Image (com.google.gwt.user.client.ui.Image)1 Label (com.google.gwt.user.client.ui.Label)1 Element (elemental.dom.Element)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 LIElement (elemental.html.LIElement)1 SpanElement (elemental.html.SpanElement)1