Search in sources :

Example 1 with SaveCancelListener

use of de.catma.ui.dialog.SaveCancelListener in project catma by forTEXT.

the class ProjectView method handleImportTagsetsRequest.

private void handleImportTagsetsRequest() {
    GenericUploadDialog uploadDialog = new GenericUploadDialog("Upload a Tag Library with one or more Tagsets:", new SaveCancelListener<byte[]>() {

        public void savePressed(byte[] result) {
            InputStream is = new ByteArrayInputStream(result);
            try {
                if (BOMFilterInputStream.hasBOM(result)) {
                    is = new BOMFilterInputStream(is, // $NON-NLS-1$
                    Charset.forName("UTF-8"));
                }
                List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList = project.loadTagLibrary(is);
                TagsetImportDialog tagsetImportDialog = new TagsetImportDialog(tagsetDefinitionImportStatusList, new SaveCancelListener<List<TagsetDefinitionImportStatus>>() {

                    @Override
                    public void savePressed(List<TagsetDefinitionImportStatus> result) {
                        try {
                            project.importTagsets(result);
                        } catch (IOException e) {
                            ((CatmaApplication) UI.getCurrent()).showAndLogError("Error importing Tagsets", e);
                        }
                    }
                });
                tagsetImportDialog.show();
            } catch (IOException e) {
                ((CatmaApplication) UI.getCurrent()).showAndLogError("Error loading external Tagsets", e);
            } finally {
                CloseSafe.close(is);
            }
        }
    });
    uploadDialog.show();
}
Also used : CatmaApplication(de.catma.ui.CatmaApplication) GenericUploadDialog(de.catma.ui.dialog.GenericUploadDialog) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BOMFilterInputStream(de.catma.document.source.contenthandler.BOMFilterInputStream) InputStream(java.io.InputStream) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus) BOMFilterInputStream(de.catma.document.source.contenthandler.BOMFilterInputStream)

Example 2 with SaveCancelListener

use of de.catma.ui.dialog.SaveCancelListener in project catma by forTEXT.

the class TagSelectionPanel method handleAddSubtagRequest.

private void handleAddSubtagRequest() {
    final List<TagDefinition> parentTags = tagsetGrid.getSelectedItems().stream().filter(tagsetTreeItem -> tagsetTreeItem instanceof TagDataItem).map(tagsetTreeItem -> ((TagDataItem) tagsetTreeItem).getTag()).collect(Collectors.toList());
    for (TagDefinition parentTag : parentTags) {
        if (!project.hasPermission(project.getRoleForTagset(parentTag.getTagsetDefinitionUuid()), RBACPermission.TAGSET_WRITE)) {
            Notification.show("Info", String.format("You do not have the permission to make changes to the Tagset of Tag %1$s, " + "Please contact the Project maintainer!", parentTag.getName()), Type.HUMANIZED_MESSAGE);
            return;
        }
    }
    if (!parentTags.isEmpty()) {
        AddSubtagDialog addTagDialog = new AddSubtagDialog(new SaveCancelListener<TagDefinition>() {

            public void savePressed(TagDefinition result) {
                for (TagDefinition parent : parentTags) {
                    TagsetDefinition tagset = project.getTagManager().getTagLibrary().getTagsetDefinition(parent);
                    TagDefinition tag = new TagDefinition(result);
                    tag.setUuid(idGenerator.generate());
                    tag.setParentUuid(parent.getUuid());
                    tag.setTagsetDefinitionUuid(tagset.getUuid());
                    project.getTagManager().addTagDefinition(tagset, tag);
                }
            }
        });
        addTagDialog.show();
    } else {
        Notification.show("Info", "Please select at least one parent Tag!", Type.HUMANIZED_MESSAGE);
    }
}
Also used : SelectionListener(com.vaadin.event.selection.SelectionListener) VerticalLayout(com.vaadin.ui.VerticalLayout) SelectionEvent(com.vaadin.event.selection.SelectionEvent) UI(com.vaadin.ui.UI) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) MaterialTheme(com.github.appreciated.material.MaterialTheme) Notification(com.vaadin.ui.Notification) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) Pair(de.catma.util.Pair) Version(de.catma.tag.Version) TreeGridFactory(de.catma.ui.component.TreeGridFactory) IDGenerator(de.catma.util.IDGenerator) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) TreeData(com.vaadin.data.TreeData) Project(de.catma.project.Project) Collection(java.util.Collection) TreeGrid(com.vaadin.ui.TreeGrid) Collectors(java.util.stream.Collectors) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) ContextMenu(com.vaadin.contextmenu.ContextMenu) List(java.util.List) Type(com.vaadin.ui.Notification.Type) PropertyChangeListener(java.beans.PropertyChangeListener) TagDefinition(de.catma.tag.TagDefinition) SerializablePredicate(com.vaadin.server.SerializablePredicate) Optional(java.util.Optional) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) SelectionMode(com.vaadin.ui.Grid.SelectionMode) RBACPermission(de.catma.rbac.RBACPermission) TagDefinition(de.catma.tag.TagDefinition) TagsetDefinition(de.catma.tag.TagsetDefinition)

Example 3 with SaveCancelListener

use of de.catma.ui.dialog.SaveCancelListener in project catma by forTEXT.

the class TagsView method handleAddSubtagRequest.

private void handleAddSubtagRequest() {
    final List<TagDefinition> parentTags = tagsetGrid.getSelectedItems().stream().filter(tagsetTreeItem -> tagsetTreeItem instanceof TagDataItem).map(tagsetTreeItem -> ((TagDataItem) tagsetTreeItem).getTag()).collect(Collectors.toList());
    for (TagDefinition parentTag : parentTags) {
        if (!project.hasPermission(project.getRoleForTagset(parentTag.getTagsetDefinitionUuid()), RBACPermission.TAGSET_WRITE)) {
            Notification.show("Info", String.format("You do not have the permission to make changes to the Tagset of Tag %1$s, " + "Please contact the Project maintainer!", parentTag.getName()), Type.HUMANIZED_MESSAGE);
            return;
        }
    }
    if (!parentTags.isEmpty()) {
        AddSubtagDialog addTagDialog = new AddSubtagDialog(new SaveCancelListener<TagDefinition>() {

            public void savePressed(TagDefinition result) {
                for (TagDefinition parent : parentTags) {
                    TagsetDefinition tagset = project.getTagManager().getTagLibrary().getTagsetDefinition(parent);
                    TagDefinition tag = new TagDefinition(result);
                    tag.setUuid(idGenerator.generate());
                    tag.setParentUuid(parent.getUuid());
                    tag.setTagsetDefinitionUuid(tagset.getUuid());
                    project.getTagManager().addTagDefinition(tagset, tag);
                }
            }
        });
        addTagDialog.show();
    } else {
        Notification.show("Info", "Please select at least one parent Tag!", Type.HUMANIZED_MESSAGE);
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) PropertyDefinition(de.catma.tag.PropertyDefinition) UI(com.vaadin.ui.UI) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog) Multimap(com.google.common.collect.Multimap) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) ArrayList(java.util.ArrayList) EventBus(com.google.common.eventbus.EventBus) MaterialTheme(com.github.appreciated.material.MaterialTheme) Notification(com.vaadin.ui.Notification) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) SliderPanel(org.vaadin.sliderpanel.SliderPanel) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) Pair(de.catma.util.Pair) Version(de.catma.tag.Version) TreeGridFactory(de.catma.ui.component.TreeGridFactory) IDGenerator(de.catma.util.IDGenerator) ButtonRenderer(com.vaadin.ui.renderers.ButtonRenderer) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) TreeData(com.vaadin.data.TreeData) Project(de.catma.project.Project) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) TreeGrid(com.vaadin.ui.TreeGrid) Collectors(java.util.stream.Collectors) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) ContextMenu(com.vaadin.contextmenu.ContextMenu) List(java.util.List) Type(com.vaadin.ui.Notification.Type) RendererClickEvent(com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent) PropertyChangeListener(java.beans.PropertyChangeListener) HorizontalLayout(com.vaadin.ui.HorizontalLayout) TagDefinition(de.catma.tag.TagDefinition) SerializablePredicate(com.vaadin.server.SerializablePredicate) Optional(java.util.Optional) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) SliderPanelBuilder(org.vaadin.sliderpanel.SliderPanelBuilder) SelectionMode(com.vaadin.ui.Grid.SelectionMode) StyleGenerator(com.vaadin.ui.StyleGenerator) RBACPermission(de.catma.rbac.RBACPermission) SliderMode(org.vaadin.sliderpanel.client.SliderMode) HugeCard(de.catma.ui.component.hugecard.HugeCard) TagDefinition(de.catma.tag.TagDefinition) TagsetDefinition(de.catma.tag.TagsetDefinition)

Example 4 with SaveCancelListener

use of de.catma.ui.dialog.SaveCancelListener in project catma by forTEXT.

the class TagsView method handleAddPropertyRequest.

private void handleAddPropertyRequest() {
    final List<TagDefinition> targetTags = new ArrayList<>();
    if (tagsetGrid.getSelectedItems().size() == 1) {
        TagsetTreeItem selectedItem = tagsetGrid.getSelectedItems().iterator().next();
        while (!(selectedItem instanceof TagDataItem) && (selectedItem != null)) {
            selectedItem = tagsetData.getParent(selectedItem);
        }
        if (selectedItem != null) {
            targetTags.add(((TagDataItem) selectedItem).getTag());
        }
    } else {
        targetTags.addAll(tagsetGrid.getSelectedItems().stream().filter(tagsetTreeItem -> tagsetTreeItem instanceof TagDataItem).map(tagsetTreeItem -> ((TagDataItem) tagsetTreeItem).getTag()).collect(Collectors.toList()));
    }
    if (targetTags.isEmpty()) {
        Notification.show("Info", "Please select one ore more Tags first!", Type.TRAY_NOTIFICATION);
    } else {
        for (TagDefinition targetTag : targetTags) {
            if (!project.hasPermission(project.getRoleForTagset(targetTag.getTagsetDefinitionUuid()), RBACPermission.TAGSET_WRITE)) {
                Notification.show("Info", String.format("You do not have the permission to make changes to the Tagset of Tag %1$s, " + "Please contact the Project maintainer!", targetTag.getName()), Type.HUMANIZED_MESSAGE);
                return;
            }
        }
        Multimap<String, PropertyDefinition> propertiesByName = ArrayListMultimap.create();
        for (TagDefinition tag : targetTags) {
            for (PropertyDefinition propertyDef : tag.getUserDefinedPropertyDefinitions()) {
                if (!propertiesByName.containsKey(propertyDef.getName()) || propertiesByName.get(propertyDef.getName()).iterator().next().getPossibleValueList().equals(propertyDef.getPossibleValueList())) {
                    propertiesByName.put(propertyDef.getName(), propertyDef);
                }
            }
        }
        List<PropertyDefinition> commonProperties = propertiesByName.asMap().entrySet().stream().filter(entry -> entry.getValue().size() == targetTags.size()).map(entry -> new PropertyDefinition(entry.getValue().iterator().next())).collect(Collectors.toList());
        // just a single tag's properties or is it a bulk(>1) edit?
        final boolean bulkEdit = targetTags.size() > 1;
        AddEditPropertyDialog addPropertyDialog = new AddEditPropertyDialog(bulkEdit, commonProperties, new SaveCancelListener<List<PropertyDefinition>>() {

            @Override
            public void savePressed(List<PropertyDefinition> result) {
                if (bulkEdit) {
                    handleBulkEditProperties(result, commonProperties, targetTags);
                } else {
                    handleSingleEditProperties(result, targetTags.iterator().next());
                }
            }
        });
        addPropertyDialog.show();
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) PropertyDefinition(de.catma.tag.PropertyDefinition) UI(com.vaadin.ui.UI) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog) Multimap(com.google.common.collect.Multimap) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) ArrayList(java.util.ArrayList) EventBus(com.google.common.eventbus.EventBus) MaterialTheme(com.github.appreciated.material.MaterialTheme) Notification(com.vaadin.ui.Notification) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) SliderPanel(org.vaadin.sliderpanel.SliderPanel) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) Pair(de.catma.util.Pair) Version(de.catma.tag.Version) TreeGridFactory(de.catma.ui.component.TreeGridFactory) IDGenerator(de.catma.util.IDGenerator) ButtonRenderer(com.vaadin.ui.renderers.ButtonRenderer) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) TreeData(com.vaadin.data.TreeData) Project(de.catma.project.Project) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) TreeGrid(com.vaadin.ui.TreeGrid) Collectors(java.util.stream.Collectors) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) ContextMenu(com.vaadin.contextmenu.ContextMenu) List(java.util.List) Type(com.vaadin.ui.Notification.Type) RendererClickEvent(com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent) PropertyChangeListener(java.beans.PropertyChangeListener) HorizontalLayout(com.vaadin.ui.HorizontalLayout) TagDefinition(de.catma.tag.TagDefinition) SerializablePredicate(com.vaadin.server.SerializablePredicate) Optional(java.util.Optional) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) SliderPanelBuilder(org.vaadin.sliderpanel.SliderPanelBuilder) SelectionMode(com.vaadin.ui.Grid.SelectionMode) StyleGenerator(com.vaadin.ui.StyleGenerator) RBACPermission(de.catma.rbac.RBACPermission) SliderMode(org.vaadin.sliderpanel.client.SliderMode) HugeCard(de.catma.ui.component.hugecard.HugeCard) TagDefinition(de.catma.tag.TagDefinition) ArrayList(java.util.ArrayList) PropertyDefinition(de.catma.tag.PropertyDefinition) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with SaveCancelListener

use of de.catma.ui.dialog.SaveCancelListener in project catma by forTEXT.

the class TagsView method handleEditTagsetRequest.

private void handleEditTagsetRequest() {
    if (project.isAuthorizedOnProject(RBACPermission.TAGSET_DELETE_OR_EDIT)) {
        Collection<TagsetDefinition> selectedTagsets = tagsetGrid.getSelectedItems().stream().filter(tagsetTreeItem -> tagsetTreeItem instanceof TagsetDataItem).map(tagsetDataItem -> ((TagsetDataItem) tagsetDataItem).getTagset()).collect(Collectors.toList());
        if (!selectedTagsets.isEmpty()) {
            final TagsetDefinition tagset = selectedTagsets.iterator().next();
            SingleTextInputDialog tagsetNameDlg = new SingleTextInputDialog("Edit Tagset", "Please enter the new Tagset name:", tagset.getName(), new SaveCancelListener<String>() {

                @Override
                public void savePressed(String result) {
                    project.getTagManager().setTagsetDefinitionName(tagset, result);
                }
            });
            tagsetNameDlg.show();
        } else {
            Notification.show("Info", "Please select a Tagset first!", Type.HUMANIZED_MESSAGE);
        }
    } else {
        Notification.show("Info", "You do not have the permission to edit Tagsets! " + "Please contact the Project maintainer for changes!", Type.HUMANIZED_MESSAGE);
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) PropertyDefinition(de.catma.tag.PropertyDefinition) UI(com.vaadin.ui.UI) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog) Multimap(com.google.common.collect.Multimap) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) ArrayList(java.util.ArrayList) EventBus(com.google.common.eventbus.EventBus) MaterialTheme(com.github.appreciated.material.MaterialTheme) Notification(com.vaadin.ui.Notification) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) SliderPanel(org.vaadin.sliderpanel.SliderPanel) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) Pair(de.catma.util.Pair) Version(de.catma.tag.Version) TreeGridFactory(de.catma.ui.component.TreeGridFactory) IDGenerator(de.catma.util.IDGenerator) ButtonRenderer(com.vaadin.ui.renderers.ButtonRenderer) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) TreeData(com.vaadin.data.TreeData) Project(de.catma.project.Project) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) TreeGrid(com.vaadin.ui.TreeGrid) Collectors(java.util.stream.Collectors) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) ContextMenu(com.vaadin.contextmenu.ContextMenu) List(java.util.List) Type(com.vaadin.ui.Notification.Type) RendererClickEvent(com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent) PropertyChangeListener(java.beans.PropertyChangeListener) HorizontalLayout(com.vaadin.ui.HorizontalLayout) TagDefinition(de.catma.tag.TagDefinition) SerializablePredicate(com.vaadin.server.SerializablePredicate) Optional(java.util.Optional) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) SliderPanelBuilder(org.vaadin.sliderpanel.SliderPanelBuilder) SelectionMode(com.vaadin.ui.Grid.SelectionMode) StyleGenerator(com.vaadin.ui.StyleGenerator) RBACPermission(de.catma.rbac.RBACPermission) SliderMode(org.vaadin.sliderpanel.client.SliderMode) HugeCard(de.catma.ui.component.hugecard.HugeCard) TagsetDefinition(de.catma.tag.TagsetDefinition) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog)

Aggregations

SaveCancelListener (de.catma.ui.dialog.SaveCancelListener)10 List (java.util.List)10 ArrayList (java.util.ArrayList)9 ContextMenu (com.vaadin.contextmenu.ContextMenu)8 SerializablePredicate (com.vaadin.server.SerializablePredicate)8 SelectionMode (com.vaadin.ui.Grid.SelectionMode)8 Label (com.vaadin.ui.Label)8 Notification (com.vaadin.ui.Notification)8 Type (com.vaadin.ui.Notification.Type)8 UI (com.vaadin.ui.UI)8 HtmlRenderer (com.vaadin.ui.renderers.HtmlRenderer)8 Project (de.catma.project.Project)8 RBACPermission (de.catma.rbac.RBACPermission)8 TagDefinition (de.catma.tag.TagDefinition)8 ActionGridComponent (de.catma.ui.component.actiongrid.ActionGridComponent)8 SearchFilterProvider (de.catma.ui.component.actiongrid.SearchFilterProvider)8 ErrorHandler (de.catma.ui.module.main.ErrorHandler)8 IDGenerator (de.catma.util.IDGenerator)8 Pair (de.catma.util.Pair)8 IOException (java.io.IOException)8