Ver Fonte

show mssage when enabling volume streaming fails

Alexander Rose há 5 anos atrás
pai
commit
f4a423ebe5

+ 1 - 1
src/mol-plugin-ui/state/apply-action.tsx

@@ -20,7 +20,7 @@ namespace ApplyActionControl {
         hideHeader?: boolean,
         initiallyCollapsed?: boolean
     }
-    
+
     export interface ComponentState {
         plugin: PluginContext,
         ref: StateTransform.Ref,

+ 2 - 2
src/mol-plugin-ui/state/common.tsx

@@ -101,7 +101,7 @@ namespace TransformControlBase {
     }
 
     export interface CommonProps {
-        simpleApply?: { header: string, icon: IconName },
+        simpleApply?: { header: string, icon: IconName, title?: string },
         noMargin?: boolean,
         applyLabel?: string,
         onApply?: () => void,
@@ -253,7 +253,7 @@ abstract class TransformControlBase<P, S extends TransformControlBase.ComponentS
         const info = this.getInfo();
         const canApply = this.canApply();
         const apply = <div className='msp-flex-row'>
-            <Button icon={this.props.simpleApply?.icon} disabled={this.state.busy || !canApply} onClick={this.apply}>
+            <Button icon={this.props.simpleApply?.icon} title={this.props.simpleApply?.title} disabled={this.state.busy || !canApply} onClick={this.apply}>
                 {this.props.simpleApply?.header}
             </Button>
             {!info.isEmpty && <ToggleButton icon='cog' label='' title='Options' toggle={this.toggleExpanded} isSelected={!this.state.isCollapsed} disabled={this.state.busy} style={{ flex: '0 0 40px', padding: 0 }} />}

+ 15 - 7
src/mol-plugin-ui/structure/volume.tsx

@@ -2,10 +2,11 @@
  * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author David Sehnal <david.sehnal@gmail.com>
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
 import * as React from 'react';
-import { InitVolumeStreaming } from '../../mol-plugin/behavior/dynamic/volume-streaming/transformers';
+import { InitVolumeStreaming, CreateVolumeStreamingInfo } from '../../mol-plugin/behavior/dynamic/volume-streaming/transformers';
 import { CollapsableControls, CollapsableState } from '../base';
 import { ApplyActionControl } from '../state/apply-action';
 import { UpdateTransformControl } from '../state/update-transform';
@@ -13,6 +14,7 @@ import { BindingsHelp } from '../viewport/help';
 import { ExpandGroup } from '../controls/common';
 import { StructureHierarchyManager } from '../../mol-plugin-state/manager/structure/hierarchy';
 import { FocusLoci } from '../../mol-plugin/behavior/dynamic/representation';
+import { StateSelection } from '../../mol-state';
 
 interface VolumeStreamingControlState extends CollapsableState {
     isBusy: boolean
@@ -31,14 +33,15 @@ export class VolumeStreamingControls extends CollapsableControls<{}, VolumeStrea
 
     componentDidMount() {
         // TODO: do not hide this but instead show some help text??
-        this.subscribe(this.plugin.managers.structure.hierarchy.behaviors.selection, () => this.setState({ isHidden: !this.canEnable() }));
+        this.subscribe(this.plugin.managers.structure.hierarchy.behaviors.selection, () => {
+            this.setState({
+                isHidden: !this.canEnable(),
+                description: StructureHierarchyManager.getSelectedStructuresDescription(this.plugin)
+            })
+        });
         this.subscribe(this.plugin.behaviors.state.isBusy, v => {
             this.setState({ isBusy: v })
         });
-
-        this.subscribe(this.plugin.managers.structure.hierarchy.behaviors.selection, c => this.setState({
-            description: StructureHierarchyManager.getSelectedStructuresDescription(this.plugin)
-        }));
     }
 
     get pivot() {
@@ -55,7 +58,12 @@ export class VolumeStreamingControls extends CollapsableControls<{}, VolumeStrea
 
     renderEnable() {
         const pivot = this.pivot;
-        return <ApplyActionControl state={pivot.cell.parent} action={InitVolumeStreaming} initiallyCollapsed={true} nodeRef={pivot.cell.transform.ref} simpleApply={{ header: 'Enable', icon: 'check' }} />;
+        const errored = this.plugin.state.data.select(StateSelection.Generators.ofTransformerWithError(CreateVolumeStreamingInfo, pivot.cell.transform.ref))[0];
+        const simpleApply = errored
+            ? { header: 'Error enabling', icon: 'alert' as const, title: errored.errorText }
+            : { header: 'Enable', icon: 'check' as const, title: 'Enable' }
+
+        return <ApplyActionControl state={pivot.cell.parent} action={InitVolumeStreaming} initiallyCollapsed={true} nodeRef={pivot.cell.transform.ref} simpleApply={simpleApply} />;
     }
 
     renderParams() {

+ 17 - 1
src/mol-state/state/selection.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author David Sehnal <david.sehnal@gmail.com>
  */
@@ -116,6 +116,14 @@ namespace StateSelection {
             });
         }
 
+        export function ofTransformerWithError<T extends StateTransformer<any, A, any>, A extends StateObject>(t: T, root: StateTransform.Ref = StateTransform.RootRef) {
+            return build(() => state => {
+                const ctx = { ret: [] as StateObjectCell<A, StateTransform<T>>[], cells: state.cells, t };
+                StateTree.doPreOrder(state.tree, state.tree.transforms.get(root), ctx, _findOfTransformerWithError);
+                return ctx.ret;
+            });
+        }
+
         function _findRootsOfType(n: StateTransform, _: any, s: { type: StateObject.Type, roots: StateObjectCell[], cells: State.Cells }) {
             const cell = s.cells.get(n.ref);
             if (cell && cell.obj && cell.obj.type === s.type) {
@@ -140,6 +148,14 @@ namespace StateSelection {
             }
             return true;
         }
+
+        function _findOfTransformerWithError(n: StateTransform, _: any, s: { t: StateTransformer, ret: StateObjectCell[], cells: State.Cells }) {
+            const cell = s.cells.get(n.ref);
+            if (cell && cell.status === 'error' && cell.transform.transformer === s.t) {
+                s.ret.push(cell);
+            }
+            return true;
+        }
     }
 
     registerModifier('flatMap', flatMap);