Пример #1
0
 @Override
 public void empty() {
   Elements.setVisible(empty.asElement(), true);
   for (Element element : elements) {
     Elements.setVisible(element, false);
   }
 }
Пример #2
0
 @Override
 public void setMacros(Iterable<Macro> macros) {
   Elements.setVisible(empty.asElement(), false);
   for (Element element : elements) {
     Elements.setVisible(element, true);
   }
   macroList.setItems(macros);
 }
Пример #3
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));
  }