Esempio n. 1
0
  @Inject
  public MacroEditorView(Resources resources) {
    this.resources = resources;

    empty =
        new EmptyState.Builder(resources.constants().noMacros())
            .icon(CSS.fontAwesome("dot-circle-o"))
            .description(
                resources.messages().noMacrosDescription(resources.constants().startMacro()))
            .build();
    empty.asElement().getClassList().add(noMacros);

    macroList =
        new ListView<>(
            Ids.MACRO_LIST,
            macro ->
                new ItemDisplay<Macro>() {
                  @Override
                  public String getTitle() {
                    return macro.getName();
                  }

                  @Override
                  public String getDescription() {
                    return macro.getDescription();
                  }

                  @Override
                  public boolean stacked() {
                    return true;
                  }

                  @Override
                  public List<ItemAction<Macro>> actions() {
                    return Arrays.asList(
                        new ItemAction<Macro>(
                            PLAY_ACTION,
                            resources.constants().play(),
                            macro -> presenter.play(macro)),
                        new ItemAction<Macro>(
                            RENAME_ACTION,
                            resources.constants().rename(),
                            macro -> presenter.rename(macro)),
                        new ItemAction<Macro>(
                            REMOVE_ACTION,
                            resources.constants().remove(),
                            macro ->
                                DialogFactory.showConfirmation(
                                    resources
                                        .messages()
                                        .removeResourceConfirmationTitle(macro.getName()),
                                    resources
                                        .messages()
                                        .removeResourceConfirmationQuestion(macro.getName()),
                                    () -> presenter.remove(macro))));
                  }
                });
    macroList.onSelect(this::loadMacro);
    macroList.asElement().getClassList().add(CSS.macroList);

    Options editorOptions = new Options();
    editorOptions.readOnly = true;
    editorOptions.showGutter = true;
    editorOptions.showLineNumbers = true;
    editorOptions.showPrintMargin = false;
    editor = new AceEditor(Ids.MACRO_EDITOR, editorOptions);

    // @formatter:off
    Elements.Builder builder =
        new Elements.Builder()
            .div()
            .css(macroEditor)
            .button()
            .css(btn, btnDefault, copy)
            .data(UIConstants.TOGGLE, UIConstants.TOOLTIP)
            .data(UIConstants.PLACEMENT, "left") // NON-NLS
            .title(resources.constants().copyToClipboard())
            .rememberAs(COPY_TO_CLIPBOARD_ELEMENT)
            .span()
            .css(fontAwesome("clipboard"))
            .end()
            .end()
            .add(editor)
            .end();
    // @formatter:on

    Element editorContainer = builder.build();
    copyToClipboard = builder.referenceFor(COPY_TO_CLIPBOARD_ELEMENT);
    Clipboard clipboard = new Clipboard(copyToClipboard);
    clipboard.onCopy(event -> copyToClipboard(event.client));

    // @formatter:off
    elements =
        new LayoutBuilder()
            .row()
            .column(4)
            .add(macroList.asElement())
            .end()
            .column(8)
            .add(editorContainer)
            .end()
            .end()
            .elements();
    // @formatter:on

    registerAttachable(editor);
    initElements(Iterables.concat(singletonList(empty.asElement()), elements));
  }
Esempio n. 2
0
 private void adjustHeight() {
   int height = max(Skeleton.applicationHeight() - 2 * MARGIN_BIG - 1, MIN_HEIGHT);
   macroList.asElement().getStyle().setHeight(height, PX);
   editor.asElement().getStyle().setHeight(height, PX);
   editor.getEditor().resize();
 }