Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Import-Package: ch.qos.logback.classic;version="1.0.7",
org.eclipse.set.core.services.name,
org.eclipse.set.core.services.part,
org.eclipse.set.core.services.pdf,
org.eclipse.set.core.services.planningaccess,
org.eclipse.set.core.services.rename,
org.eclipse.set.core.services.session,
org.eclipse.set.core.services.siteplan,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/**
* Copyright (c) 2016 DB Netz AG and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*/
package org.eclipse.set.application.subwork;

import static org.eclipse.set.ppmodel.extensions.EObjectExtensions.getNullableObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.contexts.RunAndTrack;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.core.services.nls.Translation;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.set.application.Messages;
import org.eclipse.set.application.toolcontrol.ServiceProvider;
import org.eclipse.set.basis.IModelSession;
import org.eclipse.set.basis.constants.Events;
import org.eclipse.set.core.services.part.ToolboxPartService;
import org.eclipse.set.core.services.planningaccess.PlanningAccessService;
import org.eclipse.set.model.planpro.PlanPro.ENUMUntergewerkArt;
import org.eclipse.swt.widgets.Composite;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Selects the subwork type for title box generation.
*
* @author Brombacher
*/
public class SubworkSelectionControl {

static final Logger LOGGER = LoggerFactory
.getLogger(SubworkSelectionControl.class);

private final MApplication application;

@Translation
private final Messages messages;

private IModelSession oldSession;

ToolboxPartService partService;

private ComboViewer comboViewer;

PlanningAccessService planningAccessService;

private final IEventBroker broker;

/**
* @param parent
* the parent
* @param serviceProvider
* the {@link ServiceProvider}
*/
public SubworkSelectionControl(final Composite parent,
final ServiceProvider serviceProvider) {
application = serviceProvider.application;
broker = serviceProvider.broker;
messages = serviceProvider.messages;
partService = serviceProvider.partService;
planningAccessService = serviceProvider.planningAccessService;
createTableCombo(parent);
}

private void createTableCombo(final Composite parent) {
comboViewer = new ComboViewer(parent);
comboViewer.setContentProvider(ArrayContentProvider.getInstance());
initCombo();
comboViewer.addSelectionChangedListener(event -> {
if (event
.getSelection() instanceof final IStructuredSelection selection) {
final Object first = selection.getFirstElement();
if (first instanceof final String selectedString) {
final ENUMUntergewerkArt selectedEnum = ENUMUntergewerkArt
.get(selectedString);
planningAccessService
.setCurrentUntergewerkArt(selectedEnum);
broker.send(Events.SUBWORK_CHANGED, null);
}
}
});

setCombo(getSession());

// register for session changes
application.getContext().runAndTrack(new RunAndTrack() {
@Override
public boolean changed(final IEclipseContext context) {
setCombo(context.get(IModelSession.class));
return true;
}
});

}

private IModelSession getSession() {
return application.getContext().get(IModelSession.class);
}

// correct size for combo
private void initCombo() {
clearCombo();
comboViewer.add(messages.TableTypeSelectionControl_noSession);
comboViewer.getCombo().select(0);
comboViewer.getCombo().setEnabled(false);
}

private static List<String> getSubworkTypes(final IModelSession session) {

final var projectListOpt = getNullableObject(session,
s -> s.getPlanProSchnittstelle()
.getLSTPlanung()
.getObjektmanagement()
.getLSTPlanungProjekt());

if (projectListOpt.isEmpty()) {
return List.of();
}

final var projects = projectListOpt.get();
final Set<String> subworkTypes = new HashSet<>();

for (final var project : projects) {

final var projectGroupsOpt = getNullableObject(project,
p -> p.getLSTPlanungGruppe()).orElse(new BasicEList<>());

for (final var group : projectGroupsOpt) {

final var subworkTypeOpt = getNullableObject(group,
g -> g.getPlanungGAllg().getUntergewerkArt().getWert())
.orElse(null);

if (subworkTypeOpt != null) {
subworkTypes.add(subworkTypeOpt.getLiteral());
}
}
}

return new ArrayList<>(subworkTypes);
}

private void setCombo(final IModelSession session) {
if (session == oldSession) {
return;
}
oldSession = session;
if (session == null) {
initCombo();
} else {
clearCombo();
final List<String> subworkTypes = getSubworkTypes(session);
final List<String> sortedSubworkTypes = sortSubworkTypes(
subworkTypes);
comboViewer.setInput(sortedSubworkTypes.toArray());
comboViewer.getCombo().select(0);
comboViewer.getCombo().setEnabled(true);
planningAccessService.setCurrentUntergewerkArt(
ENUMUntergewerkArt.get(sortedSubworkTypes.getFirst()));
}
}

private static final List<String> SUBWORK_TYPE_ORDER = Arrays.asList(
ENUMUntergewerkArt.ENUM_UNTERGEWERK_ART_ATO.getLiteral(),
ENUMUntergewerkArt.ENUM_UNTERGEWERK_ART_ETCS.getLiteral(),
ENUMUntergewerkArt.ENUM_UNTERGEWERK_ART_ESTW.getLiteral(),
ENUMUntergewerkArt.ENUM_UNTERGEWERK_ART_GEO.getLiteral());

private static List<String> sortSubworkTypes(
final List<String> subworkTypes) {
final List<String> sortedSubworkTypes = new ArrayList<>(subworkTypes);
sortedSubworkTypes.sort((a, b) -> {
final int indexOfA = SUBWORK_TYPE_ORDER.indexOf(a);
final int indexOfB = SUBWORK_TYPE_ORDER.indexOf(b);
if (indexOfA == -1 && indexOfB == -1) {
return a.compareTo(b);
}
if (indexOfA == -1) {
return 1;
}
if (indexOfB == -1) {
return -1;
}

final int indexCompare = Integer.compare(indexOfA, indexOfB);
if (indexCompare != 0) {
return indexCompare;
}
return a.compareTo(b);
});

return sortedSubworkTypes.isEmpty() ? List.of(
ENUMUntergewerkArt.ENUM_UNTERGEWERK_ART_SONSTIGE.getLiteral())
: sortedSubworkTypes;
}

private void clearCombo() {
comboViewer.getCombo().removeAll();
comboViewer.getCombo().clearSelection();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.set.core.services.dialog.DialogService;
import org.eclipse.set.core.services.enumtranslation.EnumTranslationService;
import org.eclipse.set.core.services.part.ToolboxPartService;
import org.eclipse.set.core.services.planningaccess.PlanningAccessService;

import jakarta.inject.Inject;

Expand Down Expand Up @@ -44,4 +45,7 @@ public class ServiceProvider {

@Inject
public DialogService dialogService;

@Inject
public PlanningAccessService planningAccessService;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.set.application.controlarea.ControlAreaSelectionControl;
import org.eclipse.set.application.subwork.SubworkSelectionControl;
import org.eclipse.set.application.tabletype.TableTypeSelectionControl;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
Expand All @@ -38,7 +39,7 @@ private void postConstruct(final Composite parent,
serviceProvider = ContextInjectionFactory.make(ServiceProvider.class,
context);
composite = new Composite(parent, SWT.NONE);
final GridLayout gridLayout = new GridLayout(3, false);
final GridLayout gridLayout = new GridLayout(4, false);
composite.setLayout(gridLayout);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
initControl(shell);
Expand All @@ -48,6 +49,8 @@ private void postConstruct(final Composite parent,
private void initControl(final Shell shell) {
final LoadedFileStatusControl validIconControl = new LoadedFileStatusControl(
composite, serviceProvider, shell);
final SubworkSelectionControl subworkSelectionControl = new SubworkSelectionControl(
composite, serviceProvider);
final TableTypeSelectionControl tableTypeSelectionControl = new TableTypeSelectionControl(
composite, serviceProvider);
final ControlAreaSelectionControl controlAreaSelectionControlcontrolArea = new ControlAreaSelectionControl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,9 @@ public interface Events {
* The find GEO_Kante geometry process is done
*/
String FIND_GEOMETRY_PROCESS_DONE = "geometryService/done";

/**
* When a subwork is selected
*/
String SUBWORK_CHANGED = "subwork/change";
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
*/
public interface PlanningAccessService {

/**
* @return the selected Subwork type
*/
public ENUMUntergewerkArt getCurrentUntergewerkArt();

/**
* @param untergewerkArt
* the selected Subwork type
*/
public void setCurrentUntergewerkArt(ENUMUntergewerkArt untergewerkArt);

/**
* @param planProIterface
* the PlanPro Schnittstelle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

package org.eclipse.set.core.modelservice;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -33,14 +32,8 @@
*/
@Component
public class PlanningAccessServiceImpl implements PlanningAccessService {
private static LinkedList<ENUMUntergewerkArt> subworkByPriority = new LinkedList<>() {
{
add(ENUMUntergewerkArt.ENUM_UNTERGEWERK_ART_ATO);
add(ENUMUntergewerkArt.ENUM_UNTERGEWERK_ART_ETCS);
add(ENUMUntergewerkArt.ENUM_UNTERGEWERK_ART_ESTW);
add(ENUMUntergewerkArt.ENUM_UNTERGEWERK_ART_GEO);
}
};

private ENUMUntergewerkArt currentUntergewerkArt = null;

private static void createPrerequisiteElements(
final PlanPro_Schnittstelle planProIterface) {
Expand Down Expand Up @@ -119,21 +112,34 @@ public Planung_Projekt getLSTPlanungProjekt(
@Override
public Planung_Gruppe getLeadingPlanungGruppe(
final Planung_Projekt project) {

final List<Planung_Gruppe> planingGroups = project
.getLSTPlanungGruppe();

if (planingGroups.isEmpty()) {
return null;
}
final Map<ENUMUntergewerkArt, List<Planung_Gruppe>> groupsBySubWork = planingGroups
.stream()
.filter(group -> getUntergewerkArt(group) != null)
.filter(group -> {
final var groupArt = getUntergewerkArt(group);
final var currentArt = getCurrentUntergewerkArt();
if (groupArt == null && currentArt == null) {
return true;
}

if (groupArt == null || currentArt == null) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@linusbbb u can check outside this stream, that getCurrentUntergewerkArtr() == null or not, when null is, then should return the first value of planingGroups, else this stream.filter


return groupArt.equals(currentArt);
})
.collect(Collectors
.groupingBy(group -> getUntergewerkArt(group)));
for (final ENUMUntergewerkArt subWork : subworkByPriority) {
if (groupsBySubWork.containsKey(subWork)) {
return groupsBySubWork.get(subWork).getFirst();
}
if (groupsBySubWork.containsKey(getCurrentUntergewerkArt())) {
return groupsBySubWork.get(getCurrentUntergewerkArt()).getFirst();
}

return planingGroups.getFirst();
}

Expand Down Expand Up @@ -185,4 +191,15 @@ public void setPlanungGruppe(final Planung_Projekt project,
}
}
}

@Override
public ENUMUntergewerkArt getCurrentUntergewerkArt() {
return currentUntergewerkArt;
}

@Override
public void setCurrentUntergewerkArt(
final ENUMUntergewerkArt untergewerkArt) {
currentUntergewerkArt = untergewerkArt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-21
Import-Package: com.fasterxml.jackson.core,
com.fasterxml.jackson.databind,
com.fasterxml.jackson.databind.module,
jakarta.annotation;version="[2.1.0,3.0.0)",
jakarta.inject;version="1.0.0",
org.apache.commons.io;version="2.2.0",
org.apache.fop.apps,
Expand All @@ -37,6 +38,7 @@ Import-Package: com.fasterxml.jackson.core,
org.eclipse.e4.core.contexts;version="1.7.0",
org.eclipse.e4.core.di,
org.eclipse.e4.core.di.annotations;version="1.6.0",
org.eclipse.e4.core.services.events,
org.eclipse.e4.core.services.nls,
org.eclipse.e4.ui.di,
org.eclipse.e4.ui.model.application,
Expand Down Expand Up @@ -82,6 +84,7 @@ Import-Package: com.fasterxml.jackson.core,
org.eclipse.set.utils.table,
org.eclipse.set.utils.viewgroups,
org.osgi.service.component.annotations;version="1.2.0",
org.osgi.service.event;version="[1.4.0,2.0.0)",
org.slf4j;version="1.7.2"
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: hyph/,
Expand Down
Loading
Loading