Search in sources :

Example 11 with DataSet

use of eu.esdihumboldt.hale.common.instance.model.DataSet in project hale by halestudio.

the class StyledMapView method createPartControl.

/**
 * @see MapView#createPartControl(Composite)
 */
@Override
public void createPartControl(Composite parent) {
    HaleUI.registerWorkbenchUndoRedo(getViewSite());
    super.createPartControl(parent);
    Control mainControl = null;
    // try to get the Swing embedding composite
    Control[] children = parent.getChildren();
    if (children != null && children.length > 0) {
        for (Control child : children) {
            // find based on class name (class from CityServer3D)
            if (child.getClass().getSimpleName().equals("SwingComposite")) {
                mainControl = child;
                break;
            }
        }
        if (mainControl == null) {
            if (children.length >= 2) {
                // Eclipse 4 - the first composite is the toolbar
                mainControl = children[0];
            } else {
                mainControl = children[0];
            }
        }
    } else {
        mainControl = parent;
    }
    new ViewContextMenu(getSite(), getSite().getSelectionProvider(), mainControl) {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            ISelection sel = getSite().getSelectionProvider().getSelection();
            // show summary about selected instances
            if (sel != null && !sel.isEmpty() && sel instanceof InstanceSelection) {
                List<Object> source = new ArrayList<Object>();
                List<Object> transformed = new ArrayList<Object>();
                for (Object object : ((InstanceSelection) sel).toArray()) {
                    DataSet ds = null;
                    if (object instanceof Instance) {
                        ds = ((Instance) object).getDataSet();
                    }
                    if (object instanceof InstanceReference) {
                        ds = ((InstanceReference) object).getDataSet();
                    }
                    if (ds != null) {
                        switch(ds) {
                            case SOURCE:
                                source.add(object);
                                break;
                            case TRANSFORMED:
                                transformed.add(object);
                                break;
                        }
                    }
                }
                if (!source.isEmpty() || !transformed.isEmpty()) {
                    Action noAction = new Action("Selection:") {
                    };
                    noAction.setEnabled(false);
                    manager.add(noAction);
                }
                if (!source.isEmpty()) {
                    Action selectAction = new SelectInstancesAction(source, DataSet.SOURCE);
                    selectAction.setEnabled(!transformed.isEmpty());
                    manager.add(selectAction);
                }
                if (!transformed.isEmpty()) {
                    Action selectAction = new SelectInstancesAction(transformed, DataSet.TRANSFORMED);
                    selectAction.setEnabled(!source.isEmpty());
                    manager.add(selectAction);
                }
            }
            super.menuAboutToShow(manager);
        }
    };
    final Menu swtMenu = mainControl.getMenu();
    getMapKit().getMainMap().addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            mouseReleased(e);
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
            if (e.isPopupTrigger()) {
                PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (Platform.WS_GTK.equals(Platform.getWS())) {
                            /*
								 * Work-around (or rather hack) for Eclipse Bug
								 * 233450
								 */
                            GTKAWTBridgePopupFix.showMenu(swtMenu);
                        } else {
                            swtMenu.setLocation(e.getXOnScreen(), e.getYOnScreen());
                            swtMenu.setVisible(true);
                        }
                    }
                });
            }
        }
    });
}
Also used : Action(org.eclipse.jface.action.Action) MouseEvent(java.awt.event.MouseEvent) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) ArrayList(java.util.ArrayList) MouseAdapter(java.awt.event.MouseAdapter) InstanceSelection(eu.esdihumboldt.hale.ui.selection.InstanceSelection) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection) Control(org.eclipse.swt.widgets.Control) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) ISelection(org.eclipse.jface.viewers.ISelection) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) ViewContextMenu(eu.esdihumboldt.hale.ui.util.ViewContextMenu) ViewContextMenu(eu.esdihumboldt.hale.ui.util.ViewContextMenu)

Example 12 with DataSet

use of eu.esdihumboldt.hale.common.instance.model.DataSet in project hale by halestudio.

the class OccurringValuesServiceImpl method updateOccuringValues.

/**
 * Update the occurring values for the given property entity.
 *
 * @param property the property entity definition
 * @param values the map containing the current occurring values
 * @return <code>true</code> if the task to update the information has been
 *         started, <code>false</code> if the information was up-to-date
 */
private boolean updateOccuringValues(PropertyEntityDefinition property, Map<PropertyEntityDefinition, OccurringValuesImpl> values) {
    synchronized (values) {
        OccurringValues ov = values.get(property);
        if (ov != null && ov.isUpToDate()) {
            return false;
        }
    }
    // determine occurring values
    // determine data set
    DataSet dataSet;
    switch(property.getSchemaSpace()) {
        case TARGET:
            dataSet = DataSet.TRANSFORMED;
            break;
        default:
            dataSet = DataSet.SOURCE;
    }
    // determine if external data should be used
    boolean useExternalData = false;
    if (dataSet.equals(DataSet.SOURCE)) {
        ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
        useExternalData = InstanceViewPreferences.occurringValuesUseExternalData(ps.getConfigurationService());
    }
    InstanceCollection collection;
    if (!useExternalData) {
        collection = instances.getInstances(dataSet);
    } else {
        // use complete project data sources
        final AtomicReference<InstanceCollection> source = new AtomicReference<>();
        IRunnableWithProgress op = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
                List<InstanceCollection> sources = new ArrayList<>();
                for (Resource resource : ps.getResources()) {
                    if (InstanceIO.ACTION_LOAD_SOURCE_DATA.equals(resource.getActionId())) {
                        // resource is source data
                        IOConfiguration conf = resource.copyConfiguration(true);
                        TransformDataImportAdvisor advisor = new TransformDataImportAdvisor();
                        ProjectResourcesUtil.executeConfiguration(conf, advisor, false, null);
                        if (advisor.getInstances() != null) {
                            sources.add(advisor.getInstances());
                        }
                    }
                }
                source.set(new MultiInstanceCollection(sources));
            }
        };
        try {
            ThreadProgressMonitor.runWithProgressDialog(op, false);
            collection = source.get();
        } catch (Exception e) {
            log.error("Error initializing data sources", e);
            return true;
        }
    }
    // go through instances to determine occurring values
    Job job = new OccurringValuesJob(property, values, collection);
    job.schedule();
    return true;
}
Also used : DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) MultiInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.MultiInstanceCollection) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) ArrayList(java.util.ArrayList) Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) AtomicReference(java.util.concurrent.atomic.AtomicReference) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) MultiInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.MultiInstanceCollection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TransformDataImportAdvisor(eu.esdihumboldt.hale.ui.transformation.TransformDataImportAdvisor) OccurringValues(eu.esdihumboldt.hale.ui.service.values.OccurringValues) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

DataSet (eu.esdihumboldt.hale.common.instance.model.DataSet)12 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)8 Style (org.geotools.styling.Style)4 InstanceService (eu.esdihumboldt.hale.ui.service.instance.InstanceService)3 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)2 InstanceReference (eu.esdihumboldt.hale.common.instance.model.InstanceReference)2 StyleService (eu.esdihumboldt.hale.ui.common.service.style.StyleService)2 GeometrySchemaService (eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService)2 InstanceServiceAdapter (eu.esdihumboldt.hale.ui.service.instance.InstanceServiceAdapter)2 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)2 SchemaService (eu.esdihumboldt.hale.ui.service.schema.SchemaService)2 ArrayList (java.util.ArrayList)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Image (org.eclipse.swt.graphics.Image)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)1 Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)1 InstanceValidationReport (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport)1 MultiInstanceCollection (eu.esdihumboldt.hale.common.instance.model.impl.MultiInstanceCollection)1