Pregunta

Tengo un botón que crea partes.Necesito obtener la parte activa que actualmente es visible en la pila de piezas y lo estoy almacenando como una clave para algún valor.¿Cómo debo obtener la parte activa? He usado el siguiente código, pero está recibiendo todas las partes en la Pietstack.

            MPart graphpart = partService
                    .createPart("com.abc.xyz.project.partDescriptor.1");
            MPartStack stack = (MPartStack) modelService.find(
                    "com.abc.xyz.project.partstack.2", application);

            for (int i = 0; i < stack.getChildren().size(); i++) {
                if (stack.getChildren().get(i).isVisible()) {
                    System.out.println("values"
                            + ((MPart) stack.getChildren().get(i)).getLabel());
                    application.getTransientData().put(
                            ((MPart) stack.getChildren().get(i)).getLabel(),
                            selectedFiles);
                }
            }

¿Fue útil?

Solución

de un MPart Puede obtener su contenedor directamente con:

final MElementContainer<MUIElement> container = part.getParent();

(este será el MPartStack)

Puede obtener las pilas actualmente seleccionadas para niños con:

MUIElement selected = container.getSelectedElement();

Otros consejos

Usando el padre de la parte y su elemento seleccionado también funcionó para mí.Partservice.getActivePART () no funcionó porque en nuestra aplicación tenemos varias pilas de piezas y necesitaba una parte de una pila de piezas que no estaba enfocada en ese momento. También tuve que lanzar el muielismo a MPART porque necesitaba devolver un MPART, que no era un problema, ya que MPART se extiende desde MUIELEMENT. Aquí está mi código: ingrese la descripción de la imagen aquí

He encontrado la respuesta.Su trabajo ahora.

for (int i = 0; i < stack.getChildren().size(); i++) {
                        if (partService.isPartVisible((MPart) stack.getChildren().get(i))) {

                System.out.println("Storage of values"
                        + ((MPart) stack.getChildren().get(i)).getLabel());
                application.getTransientData().put(
                        ((MPart) stack.getChildren().get(i)).getLabel(),
                        selectedFiles);
            }
        }

Deberíamos hacer uso del servicio de servicio para verificar la pila en particular es visible o no.

Esto es bastante simple con Eclipse E4:

  1. inyectar el EPARTSERVICE

  2. Luego, obtenga de la parte activa de GetService.

  3. Hier es una muestra de mi refrigeramiento.

    public class RefreshHandler {
    
        @Inject
        EModelService modelService;
        @Inject
        MWindow window;
        @Inject
        IEventBroker broker;
        @Inject
        EPartService partService;
    
    
        @Execute
        public void execute() {
            System.out.println(this.getClass().getSimpleName() + " called");
            MPart activePart = partService.getActivePart();
    
            if(activePart != null) {
                System.out.println("--->" + activePart.getElementId());
            }
        }
    
        @CanExecute
        public boolean canExecute() {
            MPerspective activePerspective = modelService.getActivePerspective(window);
            if (activePerspective != null && activePerspective.getElementId()
                    .equals(IApplicationUIElementID.PERSPECTIVE_WORKINGSTORE_ID)) {
                return true;
            }
            return false;
        }
    
    }
    

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top