Search in sources :

Example 1 with Global

use of org.drools.workbench.screens.globals.model.Global in project drools-wb by kiegroup.

the class GlobalsPersistenceTest method testMarshalling.

@Test
public void testMarshalling() {
    final GlobalsModel model = new GlobalsModel();
    final String expected = "global java.lang.String myString;\n";
    model.getGlobals().add(new Global("myString", "java.lang.String"));
    final String actual = GlobalsPersistence.getInstance().marshal(model);
    assertNotNull(actual);
    assertEquals(expected, actual);
}
Also used : GlobalsModel(org.drools.workbench.screens.globals.model.GlobalsModel) Global(org.drools.workbench.screens.globals.model.Global) Test(org.junit.Test)

Example 2 with Global

use of org.drools.workbench.screens.globals.model.Global in project drools-wb by kiegroup.

the class GlobalsEditorViewImpl method setup.

private void setup() {
    // Setup table
    table.setStriped(true);
    table.setCondensed(true);
    table.setBordered(true);
    table.setEmptyTableWidget(new Label(translationService.getTranslation(GlobalsEditorConstants.GlobalsEditorViewImplNoGlobalsDefined)));
    // Columns
    final TextColumn<Global> aliasColumn = new TextColumn<Global>() {

        @Override
        public String getValue(final Global global) {
            return global.getAlias();
        }
    };
    final TextColumn<Global> classNameColumn = new TextColumn<Global>() {

        @Override
        public String getValue(final Global global) {
            return global.getClassName();
        }
    };
    deleteGlobalButton = new ButtonCell(IconType.MINUS, ButtonType.DANGER, ButtonSize.SMALL);
    final Column<Global, String> deleteGlobalColumn = new Column<Global, String>(deleteGlobalButton) {

        @Override
        public String getValue(final Global global) {
            return translationService.getTranslation(GlobalsEditorConstants.GlobalsEditorViewImplRemove);
        }
    };
    deleteGlobalColumn.setFieldUpdater((index, global, value) -> {
        if (Window.confirm(translationService.format(GlobalsEditorConstants.GlobalsEditorViewImplPromptForRemovalOfGlobal, global.getAlias()))) {
            dataProvider.getList().remove(index);
        }
    });
    table.addColumn(aliasColumn, new TextHeader(translationService.getTranslation(GlobalsEditorConstants.GlobalsEditorViewImplAlias)));
    table.addColumn(classNameColumn, new TextHeader(translationService.getTranslation(GlobalsEditorConstants.GlobalsEditorViewImplClassName)));
    table.addColumn(deleteGlobalColumn, translationService.getTranslation(GlobalsEditorConstants.GlobalsEditorViewImplRemove));
    // Link data
    dataProvider.addDataDisplay(table);
    dataProvider.setList(globals);
    generatedLabel.setText(translationService.getTranslation(GlobalsEditorConstants.GlobalsEditorViewImplAutoGeneratedFile));
    addGlobalButton.setText(translationService.getTranslation(GlobalsEditorConstants.GlobalsEditorViewImplAdd));
    addGlobalButton.setIcon(IconType.PLUS);
}
Also used : TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) Label(org.gwtbootstrap3.client.ui.Label) TextHeader(com.google.gwt.user.cellview.client.TextHeader) ButtonCell(org.gwtbootstrap3.client.ui.gwt.ButtonCell) Global(org.drools.workbench.screens.globals.model.Global) TextColumn(com.google.gwt.user.cellview.client.TextColumn)

Example 3 with Global

use of org.drools.workbench.screens.globals.model.Global in project drools-wb by kiegroup.

the class GlobalsPersistence method unmarshal.

public GlobalsModel unmarshal(final String content) {
    // De-serialize model
    final List<Pair<String, String>> parsedGlobalsContent = GlobalsParser.parseGlobals(content);
    final List<Global> globals = makeGlobals(parsedGlobalsContent);
    final GlobalsModel model = new GlobalsModel();
    model.setGlobals(globals);
    // De-serialize Package name
    final String packageName = PackageNameParser.parsePackageName(content);
    model.setPackageName(packageName);
    return model;
}
Also used : GlobalsModel(org.drools.workbench.screens.globals.model.GlobalsModel) Global(org.drools.workbench.screens.globals.model.Global) Pair(org.uberfire.commons.data.Pair)

Example 4 with Global

use of org.drools.workbench.screens.globals.model.Global in project drools-wb by kiegroup.

the class GlobalsPersistence method marshal.

public String marshal(final GlobalsModel model) {
    final StringBuilder sb = new StringBuilder();
    PackageNameWriter.write(sb, model);
    for (Global global : model.getGlobals()) {
        sb.append("global ").append(global.getClassName()).append(" ").append(global.getAlias()).append(";\n");
    }
    return sb.toString();
}
Also used : Global(org.drools.workbench.screens.globals.model.Global)

Aggregations

Global (org.drools.workbench.screens.globals.model.Global)4 GlobalsModel (org.drools.workbench.screens.globals.model.GlobalsModel)2 Column (com.google.gwt.user.cellview.client.Column)1 TextColumn (com.google.gwt.user.cellview.client.TextColumn)1 TextHeader (com.google.gwt.user.cellview.client.TextHeader)1 Label (org.gwtbootstrap3.client.ui.Label)1 ButtonCell (org.gwtbootstrap3.client.ui.gwt.ButtonCell)1 Test (org.junit.Test)1 Pair (org.uberfire.commons.data.Pair)1