Search in sources :

Example 36 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class OrientInstanceService method performTransformation.

/**
 * Perform the transformation
 *
 * @return if the transformation was successful
 */
protected boolean performTransformation() {
    final TransformationService ts = getTransformationService();
    if (ts == null) {
        log.userError("No transformation service available");
        return false;
    }
    final AtomicBoolean transformationFinished = new AtomicBoolean(false);
    final AtomicBoolean transformationCanceled = new AtomicBoolean(false);
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                Alignment alignment = getAlignmentService().getAlignment();
                if (alignment.getActiveTypeCells().isEmpty()) {
                    // early exit if there are no type relations
                    return;
                }
                // determine if there are any active type cells w/o source
                boolean transformEmpty = false;
                for (Cell cell : alignment.getActiveTypeCells()) {
                    if (cell.getSource() == null || cell.getSource().isEmpty()) {
                        transformEmpty = true;
                        break;
                    }
                }
                InstanceCollection sources = getInstances(DataSet.SOURCE);
                if (!transformEmpty && sources.isEmpty()) {
                    return;
                }
                HaleOrientInstanceSink sink = new HaleOrientInstanceSink(transformed, true);
                TransformationReport report;
                ATransaction trans = log.begin("Instance transformation");
                try {
                    report = ts.transform(alignment, sources, sink, HaleUI.getServiceProvider(), new ProgressMonitorIndicator(monitor));
                    // publish report
                    ReportService rs = PlatformUI.getWorkbench().getService(ReportService.class);
                    rs.addReport(report);
                } finally {
                    try {
                        sink.close();
                    } catch (IOException e) {
                    // ignore
                    }
                    trans.end();
                }
            } finally {
                // remember if canceled
                if (monitor.isCanceled()) {
                    transformationCanceled.set(true);
                }
                // transformation finished
                transformationFinished.set(true);
            }
        }
    };
    try {
        ThreadProgressMonitor.runWithProgressDialog(op, ts.isCancelable());
    } catch (Throwable e) {
        log.error("Error starting transformation process", e);
    }
    // wait for transformation to complete
    HaleUI.waitFor(transformationFinished);
    return !transformationCanceled.get();
}
Also used : TransformationReport(eu.esdihumboldt.hale.common.align.transformation.report.TransformationReport) ProgressMonitorIndicator(eu.esdihumboldt.hale.common.core.io.ProgressMonitorIndicator) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) BrowseOrientInstanceCollection(eu.esdihumboldt.hale.common.instance.orient.storage.BrowseOrientInstanceCollection) FilteredInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.FilteredInstanceCollection) IOException(java.io.IOException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) ReportService(eu.esdihumboldt.hale.ui.service.report.ReportService) ATransaction(de.fhg.igd.slf4jplus.ATransaction) TransformationService(eu.esdihumboldt.hale.common.align.transformation.service.TransformationService) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 37 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class GenericParameterPage method onShowPage.

/**
 * @see HaleWizardPage#onShowPage(boolean)
 */
@Override
protected void onShowPage(boolean firstShow) {
    Cell cell = getWizard().getUnfinishedCell();
    // update variables as they could have changed
    if (!AlignmentUtil.isTypeCell(cell)) {
        Set<PropertyEntityDefinition> variables = new HashSet<PropertyEntityDefinition>();
        for (Entity e : cell.getSource().values()) {
            // Cell is no type cell, so entities are Properties.
            variables.add(((Property) e).getDefinition());
        }
        for (Pair<AttributeEditor<?>, Button> pair : inputFields.values()) pair.getFirst().setVariables(variables);
    }
    updateState();
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) Button(org.eclipse.swt.widgets.Button) AttributeEditor(eu.esdihumboldt.hale.ui.common.AttributeEditor) Cell(eu.esdihumboldt.hale.common.align.model.Cell) HashSet(java.util.HashSet)

Example 38 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class EditRelationHandler method execute.

/**
 * @see IHandler#execute(ExecutionEvent)
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        Object selected = ((IStructuredSelection) selection).getFirstElement();
        if (selected instanceof Cell) {
            final Cell originalCell = (Cell) selected;
            FunctionWizard wizard = null;
            List<FunctionWizardDescriptor<?>> factories = FunctionWizardExtension.getInstance().getFactories(new FactoryFilter<FunctionWizardFactory, FunctionWizardDescriptor<?>>() {

                @Override
                public boolean acceptFactory(FunctionWizardDescriptor<?> factory) {
                    return factory.getFunctionId().equals(originalCell.getTransformationIdentifier());
                }

                @Override
                public boolean acceptCollection(ExtensionObjectFactoryCollection<FunctionWizardFactory, FunctionWizardDescriptor<?>> collection) {
                    return true;
                }
            });
            if (!factories.isEmpty()) {
                // create registered wizard
                FunctionWizardDescriptor<?> fwd = factories.get(0);
                wizard = fwd.createEditWizard(originalCell);
            }
            if (wizard == null) {
                FunctionDefinition<?> function = FunctionUtil.getFunction(originalCell.getTransformationIdentifier(), HaleUI.getServiceProvider());
                if (function == null) {
                    log.userError(MessageFormat.format("Function with identifier ''{0}'' is unknown.", originalCell.getTransformationIdentifier()));
                    return null;
                }
                // create generic wizard
                if (function instanceof TypeFunction) {
                    wizard = new GenericTypeFunctionWizard(originalCell);
                } else {
                    wizard = new GenericPropertyFunctionWizard(originalCell);
                }
            }
            // initialize wizard
            wizard.init();
            HaleWizardDialog dialog = new HaleWizardDialog(HandlerUtil.getActiveShell(event), wizard);
            if (dialog.open() == WizardDialog.OK) {
                MutableCell cell = wizard.getResult();
                AlignmentService alignmentService = PlatformUI.getWorkbench().getService(AlignmentService.class);
                // remove the original cell
                // and add the new cell
                alignmentService.replaceCell(originalCell, cell);
            }
        }
    }
    return null;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) FunctionWizardDescriptor(eu.esdihumboldt.hale.ui.function.extension.FunctionWizardDescriptor) FunctionWizardFactory(eu.esdihumboldt.hale.ui.function.extension.FunctionWizardFactory) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GenericTypeFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericTypeFunctionWizard) GenericPropertyFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericPropertyFunctionWizard) FunctionWizard(eu.esdihumboldt.hale.ui.function.FunctionWizard) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ISelection(org.eclipse.jface.viewers.ISelection) GenericTypeFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericTypeFunctionWizard) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) GenericPropertyFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericPropertyFunctionWizard) TypeFunction(eu.esdihumboldt.hale.common.align.extension.function.TypeFunction) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Example 39 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class CellFigureTaskLabelContribution method contribute.

// private TaskServiceListener taskServiceListener;
@Override
public void contribute(CellFigure figure, Cell cell) {
    TaskService taskService = HaleUI.getServiceProvider().getService(TaskService.class);
    Collection<ResolvedTask<Cell>> tasks = taskService.getTasks(cell).stream().map(t -> taskService.resolveTask(t)).collect(Collectors.toList());
    tasks = tasks.stream().filter(t -> t.isOpen()).collect(Collectors.toList());
    if (tasks.isEmpty()) {
        return;
    }
    Label tasksLabel = new Label();
    Image tasksImage = null;
    tasksImage = CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_TASKS);
    tasksLabel.setIcon(tasksImage);
    tasksLabel.addMouseListener(new MouseListener() {

        @Override
        public void mouseReleased(MouseEvent me) {
            try {
                IViewPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(TaskTreeView.ID);
                // the alignment/mapping view
                if (part instanceof TaskTreeView) {
                    ((TaskTreeView) part).update(new StructuredSelection(cell));
                }
                me.consume();
            } catch (PartInitException e) {
                log.error("Error creating task view", e);
            }
        }

        @Override
        public void mousePressed(MouseEvent me) {
        // ignore
        }

        @Override
        public void mouseDoubleClicked(MouseEvent me) {
        // ignore
        }
    });
    if (tasksImage != null) {
        Label priorityTip = new Label(MessageFormat.format("There {0} {1} open tasks for this cell. Please refer to the Tasks view for details.", (tasks.size() == 1) ? "is" : "are", tasks.size()));
        tasksLabel.setToolTip(priorityTip);
    }
    GridData tasksLabelGD = new GridData(GridData.CENTER, GridData.FILL, false, true);
    figure.add(tasksLabel, tasksLabelGD);
}
Also used : Cell(eu.esdihumboldt.hale.common.align.model.Cell) PlatformUI(org.eclipse.ui.PlatformUI) ALogger(de.fhg.igd.slf4jplus.ALogger) Collection(java.util.Collection) HaleUI(eu.esdihumboldt.hale.ui.HaleUI) Image(org.eclipse.swt.graphics.Image) CellFigure(eu.esdihumboldt.hale.ui.common.graph.figures.CellFigure) MouseEvent(org.eclipse.draw2d.MouseEvent) ALoggerFactory(de.fhg.igd.slf4jplus.ALoggerFactory) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) MouseListener(org.eclipse.draw2d.MouseListener) CommonSharedImages(eu.esdihumboldt.hale.ui.common.CommonSharedImages) CellFigureContribution(eu.esdihumboldt.hale.ui.common.graph.figures.CellFigureContribution) Collectors(java.util.stream.Collectors) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) MessageFormat(java.text.MessageFormat) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) GridData(org.eclipse.draw2d.GridData) PartInitException(org.eclipse.ui.PartInitException) Label(org.eclipse.draw2d.Label) IViewPart(org.eclipse.ui.IViewPart) IViewPart(org.eclipse.ui.IViewPart) MouseEvent(org.eclipse.draw2d.MouseEvent) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) Label(org.eclipse.draw2d.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Image(org.eclipse.swt.graphics.Image) MouseListener(org.eclipse.draw2d.MouseListener) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) GridData(org.eclipse.draw2d.GridData) PartInitException(org.eclipse.ui.PartInitException)

Example 40 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class TaskTreeView method createInput.

/**
 * Update the view
 */
private void createInput() {
    TaskService taskService = HaleUI.getServiceProvider().getService(TaskService.class);
    final Collection<TreeNode> input = new ArrayList<TreeNode>();
    cellNode = new MapTreeNode<Cell, MapTreeNode<ResolvedTask<Cell>, TreeNode>>("Cell messages");
    input.add(cellNode);
    Collection<ResolvedTask<?>> tasks = taskService.getResolvedTasks();
    for (ResolvedTask<?> task : tasks) {
        addTask(task);
    }
    tree.setInput(input);
}
Also used : TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) DefaultTreeNode(eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode) MapTreeNode(eu.esdihumboldt.hale.ui.util.tree.MapTreeNode) TreeNode(org.eclipse.jface.viewers.TreeNode) SortedMapTreeNode(eu.esdihumboldt.hale.ui.util.tree.SortedMapTreeNode) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) ArrayList(java.util.ArrayList) MapTreeNode(eu.esdihumboldt.hale.ui.util.tree.MapTreeNode) SortedMapTreeNode(eu.esdihumboldt.hale.ui.util.tree.SortedMapTreeNode) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Aggregations

Cell (eu.esdihumboldt.hale.common.align.model.Cell)123 ArrayList (java.util.ArrayList)33 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)28 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)28 Test (org.junit.Test)27 Entity (eu.esdihumboldt.hale.common.align.model.Entity)24 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)24 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)18 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)16 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)16 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)15 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)13 HashSet (java.util.HashSet)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 Type (eu.esdihumboldt.hale.common.align.model.Type)11 List (java.util.List)11 ModifiableCell (eu.esdihumboldt.hale.common.align.model.ModifiableCell)9 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)9 Property (eu.esdihumboldt.hale.common.align.model.Property)8