Search in sources :

Example 11 with Constraints

use of org.eclipse.che.ide.api.constraints.Constraints in project che by eclipse.

the class DefaultActionGroupTest method addOneAfter.

@Test
public void addOneAfter() {
    // given
    mockRegisterActions();
    defaultActionGroup.add(firstAction);
    defaultActionGroup.add(secondAction);
    defaultActionGroup.add(thirdAction);
    defaultActionGroup.add(fourthAction, new Constraints(AFTER, "firstAction"));
    defaultActionGroup.add(fifthAction);
    defaultActionGroup.add(sixthAction);
    // when
    Action[] result = defaultActionGroup.getChildren(mock(ActionEvent.class));
    //then
    assertThat(Arrays.asList(result)).hasSize(6).containsExactly(firstAction, fourthAction, secondAction, thirdAction, fifthAction, sixthAction);
}
Also used : Constraints(org.eclipse.che.ide.api.constraints.Constraints) Test(org.junit.Test)

Example 12 with Constraints

use of org.eclipse.che.ide.api.constraints.Constraints in project che by eclipse.

the class DefaultActionGroupTest method addOneBeforeNotAdded.

@Test
public void addOneBeforeNotAdded() {
    // given
    mockRegisterActions();
    defaultActionGroup.add(firstAction);
    defaultActionGroup.add(secondAction);
    defaultActionGroup.add(thirdAction, new Constraints(BEFORE, "fifthAction"));
    defaultActionGroup.add(fourthAction);
    defaultActionGroup.add(fifthAction);
    defaultActionGroup.add(sixthAction);
    // when
    Action[] result = defaultActionGroup.getChildren(mock(ActionEvent.class));
    // then
    assertThat(Arrays.asList(result)).hasSize(6).containsExactly(firstAction, secondAction, fourthAction, thirdAction, fifthAction, sixthAction);
}
Also used : Constraints(org.eclipse.che.ide.api.constraints.Constraints) Test(org.junit.Test)

Example 13 with Constraints

use of org.eclipse.che.ide.api.constraints.Constraints in project che by eclipse.

the class DefaultActionGroup method checkUnsorted.

/**
     * This method checks unsorted map for actions, that depend
     * on action, received in parameter. If found ones, adds it
     *
     * @param unsortedMap
     *         - map with unsorted actions
     * @param action
     *         - action, that is a condition for actions in unsorted list
     * @param result
     *         - result list
     */
private void checkUnsorted(Map<Action, Constraints> unsortedMap, Action action, List<Action> result) {
    Iterator<Map.Entry<Action, Constraints>> itr = unsortedMap.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry<Action, Constraints> entry = itr.next();
        String actionId = actionManager.getId(action);
        Action relatedAction = entry.getKey();
        Constraints relatedConstraints = entry.getValue();
        // add it to result and remove from unsorted list
        if (relatedConstraints.relativeId.equals(actionId)) {
            if (relatedConstraints.myAnchor.equals(Anchor.BEFORE)) {
                result.add(result.indexOf(action), relatedAction);
            } else if (relatedConstraints.myAnchor.equals(Anchor.AFTER)) {
                result.add(result.indexOf(action) + 1, relatedAction);
            }
            itr.remove();
            // recursive call of this method, but now passing the 'relatedAction'
            // to find another actions, that related to 'relatedAction
            checkUnsorted(unsortedMap, relatedAction, result);
        }
    }
}
Also used : Constraints(org.eclipse.che.ide.api.constraints.Constraints) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 14 with Constraints

use of org.eclipse.che.ide.api.constraints.Constraints in project che by eclipse.

the class LanguageServerExtension method registerAction.

@Inject
protected void registerAction(ActionManager actionManager, KeyBindingAgent keyBindingManager, GoToSymbolAction goToSymbolAction, FindSymbolAction findSymbolAction, FindDefinitionAction findDefinitionAction, FindReferencesAction findReferencesAction) {
    actionManager.registerAction("LSGoToSymbolAction", goToSymbolAction);
    actionManager.registerAction("LSFindSymbolAction", findSymbolAction);
    actionManager.registerAction("LSFindDefinitionAction", findDefinitionAction);
    actionManager.registerAction("LSFindReferencesAction", findReferencesAction);
    DefaultActionGroup assistantGroup = (DefaultActionGroup) actionManager.getAction(GROUP_ASSISTANT);
    assistantGroup.add(goToSymbolAction, new Constraints(Anchor.BEFORE, GROUP_ASSISTANT_REFACTORING));
    assistantGroup.add(findSymbolAction, new Constraints(Anchor.BEFORE, GROUP_ASSISTANT_REFACTORING));
    assistantGroup.add(findDefinitionAction, new Constraints(Anchor.BEFORE, GROUP_ASSISTANT_REFACTORING));
    assistantGroup.add(findReferencesAction, new Constraints(Anchor.BEFORE, GROUP_ASSISTANT_REFACTORING));
    if (UserAgent.isMac()) {
        keyBindingManager.getGlobal().addKey(new KeyBuilder().control().charCode(KeyCodeMap.F12).build(), "LSGoToSymbolAction");
    } else {
        keyBindingManager.getGlobal().addKey(new KeyBuilder().action().charCode(KeyCodeMap.F12).build(), "LSGoToSymbolAction");
    }
    keyBindingManager.getGlobal().addKey(new KeyBuilder().alt().charCode('n').build(), "LSFindSymbolAction");
    keyBindingManager.getGlobal().addKey(new KeyBuilder().alt().charCode(KeyCodeMap.F7).build(), "LSFindReferencesAction");
    keyBindingManager.getGlobal().addKey(new KeyBuilder().charCode(KeyCodeMap.F4).build(), "LSFindDefinitionAction");
}
Also used : KeyBuilder(org.eclipse.che.ide.api.keybinding.KeyBuilder) Constraints(org.eclipse.che.ide.api.constraints.Constraints) DefaultActionGroup(org.eclipse.che.ide.api.action.DefaultActionGroup) Inject(com.google.inject.Inject)

Example 15 with Constraints

use of org.eclipse.che.ide.api.constraints.Constraints in project che by eclipse.

the class PartsComparator method compare.

@Override
public int compare(PartPresenter part1, PartPresenter part2) {
    String title1 = part1.getTitle();
    String title2 = part2.getTitle();
    Constraints constr1 = constraints.get(part1);
    Constraints constr2 = constraints.get(part2);
    if (constr1 == null && constr2 == null) {
        return 0;
    }
    if ((constr1 != null && constr1.myAnchor == Anchor.FIRST) || (constr2 != null && constr2.myAnchor == Anchor.LAST)) {
        return -1;
    }
    if ((constr2 != null && constr2.myAnchor == Anchor.FIRST) || (constr1 != null && constr1.myAnchor == Anchor.LAST)) {
        return 1;
    }
    if (constr1 != null && constr1.relativeId != null) {
        Anchor anchor1 = constr1.myAnchor;
        String relative1 = constr1.relativeId;
        if (anchor1 == Anchor.BEFORE && relative1.equals(title2)) {
            return -1;
        }
        if (anchor1 == Anchor.AFTER && relative1.equals(title2)) {
            return 1;
        }
    }
    if (constr2 != null && constr2.relativeId != null) {
        Anchor anchor2 = constr2.myAnchor;
        String relative2 = constr2.relativeId;
        if (anchor2 == Anchor.BEFORE && relative2.equals(title1)) {
            return 1;
        }
        if (anchor2 == Anchor.AFTER && relative2.equals(title1)) {
            return -1;
        }
    }
    if (constr1 != null && constr2 == null) {
        return 1;
    }
    if (constr1 == null) {
        return -1;
    }
    return 0;
}
Also used : Anchor(org.eclipse.che.ide.api.constraints.Anchor) Constraints(org.eclipse.che.ide.api.constraints.Constraints)

Aggregations

Constraints (org.eclipse.che.ide.api.constraints.Constraints)21 Test (org.junit.Test)12 Inject (com.google.inject.Inject)3 DefaultActionGroup (org.eclipse.che.ide.api.action.DefaultActionGroup)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 KeyBuilder (org.eclipse.che.ide.api.keybinding.KeyBuilder)2 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 JsonObject (elemental.json.JsonObject)1 Map (java.util.Map)1 Promise (org.eclipse.che.api.promises.client.Promise)1 Anchor (org.eclipse.che.ide.api.constraints.Anchor)1 EditorPartStack (org.eclipse.che.ide.api.parts.EditorPartStack)1