Skip to content

Commit f07a7a2

Browse files
author
Smiechowski Nathanael
authored
1.5.1
* ImplementedWarningDialogWhenMultipleProjectOpen ;fixes #73
1 parent e4255e3 commit f07a7a2

15 files changed

Lines changed: 565 additions & 12 deletions

DEHCapellaAdapter/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: DEH-CapellaAdapter
44
Bundle-SymbolicName: com.rheagroup.dehcapellaadapter;singleton:=true
5-
Bundle-Version: 1.5.0
5+
Bundle-Version: 1.5.1
66
Bundle-Vendor: RHEAGROUP
77
Require-Bundle: org.eclipse.ui,
88
org.polarsys.capella.core.model.handler;bundle-version="5.1.0";visibility:=reexport,
@@ -32,6 +32,7 @@ Export-Package: App,
3232
Services.CapellaSelection,
3333
Services.CapellaSession,
3434
Services.CapellaTransaction,
35+
Services.CapellaUserPreference,
3536
Services.HistoryService,
3637
Services.Mapping,
3738
Services.MappingConfiguration,

DEHCapellaAdapter/src/App/App.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
import Services.CapellaSession.SiriusSessionManagerWrapper;
5757
import Services.CapellaTransaction.CapellaTransactionService;
5858
import Services.CapellaTransaction.ICapellaTransactionService;
59+
import Services.CapellaUserPreference.CapellaUserPreferenceService;
60+
import Services.CapellaUserPreference.ICapellaUserPreferenceService;
5961
import Services.HistoryService.CapellaLocalExchangeHistoryService;
6062
import Services.HistoryService.ICapellaLocalExchangeHistoryService;
6163
import Services.Mapping.IMapCommandService;
@@ -77,8 +79,10 @@
7779
import ViewModels.CapellaObjectBrowser.CapellaObjectBrowserViewModel;
7880
import ViewModels.CapellaObjectBrowser.Interfaces.ICapellaObjectBrowserViewModel;
7981
import ViewModels.ContextMenu.HubBrowserContextMenuViewModel;
82+
import ViewModels.Dialogs.AlertMoreThanOneCapellaModelOpenDialogViewModel;
8083
import ViewModels.Dialogs.DstToHubMappingConfigurationDialogViewModel;
8184
import ViewModels.Dialogs.HubToDstMappingConfigurationDialogViewModel;
85+
import ViewModels.Dialogs.Interfaces.IAlertMoreThanOneCapellaModelOpenDialogViewModel;
8286
import ViewModels.Dialogs.Interfaces.IDstToHubMappingConfigurationDialogViewModel;
8387
import ViewModels.Dialogs.Interfaces.IHubToDstMappingConfigurationDialogViewModel;
8488
import ViewModels.Interfaces.ICapellaHubBrowserPanelViewModel;
@@ -173,6 +177,7 @@ public void RegisterDependencies()
173177
AppContainer.Container.as(CACHE).addComponent(ICapellaTransactionService.class, CapellaTransactionService.class);
174178
AppContainer.Container.addComponent(IAdapterInfoService.class, CapellaAdapterInfoService.class);
175179
AppContainer.Container.as(CACHE).addComponent(ICapellaLocalExchangeHistoryService.class, CapellaLocalExchangeHistoryService.class);
180+
AppContainer.Container.addComponent(ICapellaUserPreferenceService.class, CapellaUserPreferenceService.class);
176181

177182
AppContainer.Container.addComponent(ComponentToElementMappingRule.class.getName(), ComponentToElementMappingRule.class);
178183
AppContainer.Container.addComponent(ElementToComponentMappingRule.class.getName(), ElementToComponentMappingRule.class);
@@ -194,6 +199,7 @@ public void RegisterDependencies()
194199
AppContainer.Container.addComponent(ICapellaHubBrowserPanelViewModel.class, CapellaHubBrowserPanelViewModel.class);
195200
AppContainer.Container.addComponent(ICapellaMappedElementListViewViewModel.class, CapellaMappedElementListViewViewModel.class);
196201
AppContainer.Container.addComponent(IMappingListViewViewModel.class, CapellaMappingListViewViewModel.class);
202+
AppContainer.Container.addComponent(IAlertMoreThanOneCapellaModelOpenDialogViewModel.class.getSimpleName(), AlertMoreThanOneCapellaModelOpenDialogViewModel.class);
197203
}
198204
catch (Exception exception)
199205
{

DEHCapellaAdapter/src/DstController/DstController.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import static Utils.Operators.Operators.AreTheseEquals;
2727

28+
import java.awt.EventQueue;
2829
import java.util.ArrayList;
2930
import java.util.Collection;
3031
import java.util.List;
@@ -62,10 +63,13 @@
6263
import Services.CapellaLog.ICapellaLogService;
6364
import Services.CapellaSession.ICapellaSessionService;
6465
import Services.CapellaTransaction.ICapellaTransactionService;
66+
import Services.CapellaUserPreference.ICapellaUserPreferenceService;
67+
import Services.CapellaUserPreference.UserPreferenceKey;
6568
import Services.HistoryService.ICapellaLocalExchangeHistoryService;
6669
import Services.MappingConfiguration.ICapellaMappingConfigurationService;import Services.MappingConfiguration.IMappingConfigurationService;
6770
import Services.MappingEngineService.IMappableThingCollection;
6871
import Services.MappingEngineService.IMappingEngineService;
72+
import Services.NavigationService.INavigationService;
6973
import Utils.Ref;
7074
import Utils.Stereotypes.CapellaComponentCollection;
7175
import Utils.Stereotypes.CapellaRequirementCollection;
@@ -79,6 +83,7 @@
7983
import ViewModels.Rows.MappedElementRowViewModel;
8084
import ViewModels.Rows.MappedHubRequirementRowViewModel;
8185
import ViewModels.Rows.MappedRequirementBaseRowViewModel;
86+
import Views.Dialogs.AlertMoreThanOneCapellaModelOpenDialog;
8287
import cdp4common.ChangeKind;
8388
import cdp4common.commondata.ClassKind;
8489
import cdp4common.commondata.DefinedThing;
@@ -103,6 +108,8 @@
103108
import cdp4dal.exceptions.TransactionException;
104109
import cdp4dal.operations.ThingTransaction;
105110
import io.reactivex.Observable;
111+
import io.reactivex.Scheduler;
112+
import io.reactivex.schedulers.Schedulers;
106113

107114
/**
108115
* The {@linkplain DstController} is a class that manage transfer and connection to attached running instance of Capella
@@ -154,6 +161,16 @@ public final class DstController implements IDstController
154161
*/
155162
private final ICapellaLocalExchangeHistoryService exchangeHistory;
156163

164+
/**
165+
* The {@linkplain INavigationService} instance
166+
*/
167+
private final INavigationService navigationService;
168+
169+
/**
170+
* The {@linkplain ICapellaUserPreferenceService} instance
171+
*/
172+
private final ICapellaUserPreferenceService userPreferenceService;
173+
157174
/**
158175
* A value indicating whether the {@linkplain DstController} should load mapping when the HUB session is refresh or reloaded
159176
*/
@@ -330,10 +347,13 @@ public boolean HasAnyOpenSession()
330347
* @param capellaSessionService the {@linkplain ICapellaSessionService} instance
331348
* @param transactionService the {@linkplain ICapellaTransactionService} instance
332349
* @param exchangeHistory the {@linkplain ICapellaLocalExchangeHistoryService} instance
350+
* @param userPreferenceService the {@linkplain CapellaUserPreferenceService} instance
351+
* @param navigationService the {@linkplain INavigationService} instance
333352
*/
334353
public DstController(IMappingEngineService mappingEngine, IHubController hubController, ICapellaLogService logService,
335354
ICapellaMappingConfigurationService mappingConfigurationService, ICapellaSessionService capellaSessionService,
336-
ICapellaTransactionService transactionService, ICapellaLocalExchangeHistoryService exchangeHistory)
355+
ICapellaTransactionService transactionService, ICapellaLocalExchangeHistoryService exchangeHistory,
356+
ICapellaUserPreferenceService userPreferenceService, INavigationService navigationService)
337357
{
338358
this.mappingEngine = mappingEngine;
339359
this.hubController = hubController;
@@ -342,6 +362,8 @@ public DstController(IMappingEngineService mappingEngine, IHubController hubCont
342362
this.capellaSessionService = capellaSessionService;
343363
this.transactionService = transactionService;
344364
this.exchangeHistory = exchangeHistory;
365+
this.userPreferenceService = userPreferenceService;
366+
this.navigationService = navigationService;
345367

346368
this.hubController.GetIsSessionOpenObservable().subscribe(isSessionOpen ->
347369
{
@@ -362,10 +384,36 @@ public DstController(IMappingEngineService mappingEngine, IHubController hubCont
362384
{
363385
if(!this.isHubSessionRefreshSilent)
364386
{
365-
this.LoadMapping();
387+
this.LoadMapping();
366388
}
367389
});
368390

391+
if(!this.userPreferenceService.Get(UserPreferenceKey.ShouldNeverRemindMeThatMoreThanOneCapellaModelIsOpen, Boolean.class, false))
392+
{
393+
Ref<Boolean> isDialogOpen = new Ref<>(Boolean.class, false);
394+
395+
Observable.combineLatest(this.capellaSessionService.HasAnyOpenSessionObservable().startWith(this.HasAnyOpenSession()),
396+
this.hubController.GetIsSessionOpenObservable(),
397+
(hasAnyCapellaModelOpen, isHubSessionOpen) ->
398+
hasAnyCapellaModelOpen && isHubSessionOpen
399+
&& this.capellaSessionService.GetOpenSessions().size() > 1
400+
&& !this.userPreferenceService.Get(UserPreferenceKey.ShouldNeverRemindMeThatMoreThanOneCapellaModelIsOpen, Boolean.class, false))
401+
.filter(x -> x)
402+
.subscribe(x ->
403+
{
404+
if(!isDialogOpen.Get())
405+
{
406+
isDialogOpen.Set(true);
407+
408+
EventQueue.invokeLater(() ->
409+
{
410+
this.navigationService.ShowDialog(new AlertMoreThanOneCapellaModelOpenDialog());
411+
isDialogOpen.Set(false);
412+
});
413+
}
414+
});
415+
}
416+
369417
this.GetDstMapResult().ItemsAdded().subscribe(x -> this.MapTraces(MappingDirection.FromDstToHub));
370418
this.GetHubMapResult().ItemsAdded().subscribe(x -> this.MapTraces(MappingDirection.FromHubToDst));
371419
}

DEHCapellaAdapter/src/Services/CapellaSession/CapellaSessionService.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package Services.CapellaSession;
2525

2626
import java.util.ArrayList;
27+
import java.util.Collection;
2728
import java.util.HashMap;
2829
import java.util.List;
2930
import java.util.function.BiConsumer;
@@ -45,6 +46,7 @@
4546

4647
import Enumerations.CapellaArchitecture;
4748
import Reactive.ObservableValue;
49+
import Services.NavigationService.INavigationService;
4850
import ViewModels.CapellaObjectBrowser.Rows.RootRowViewModel;
4951
import io.reactivex.Observable;
5052

@@ -116,7 +118,7 @@ public Session GetCurrentSession()
116118
{
117119
if(currentSession == null)
118120
{
119-
this.currentSession = this.GetOpenSessions().get(0);
121+
this.currentSession = new ArrayList<>(this.GetOpenSessions()).get(0);
120122
}
121123
else if(!this.GetOpenSessions().contains(this.currentSession))
122124
{
@@ -199,12 +201,12 @@ public boolean HasAnyOpenSession()
199201
/**
200202
* Gets the open {@linkplain Session}s
201203
*
202-
* @return a {@linkplain List} of {@linkplain Session}
204+
* @return a {@linkplain Collection} of {@linkplain Session}
203205
*/
204206
@Override
205-
public List<Session> GetOpenSessions()
207+
public Collection<Session> GetOpenSessions()
206208
{
207-
return this.sessionManager.GetSessions().stream().collect(Collectors.toList());
209+
return this.sessionManager.GetSessions();
208210
}
209211

210212
/**

DEHCapellaAdapter/src/Services/CapellaSession/ICapellaSessionService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package Services.CapellaSession;
2525

26+
import java.util.Collection;
2627
import java.util.HashMap;
2728
import java.util.List;
2829

@@ -133,9 +134,9 @@ public interface ICapellaSessionService
133134
/**
134135
* Gets the open {@linkplain Session}s
135136
*
136-
* @return a {@linkplain List} of {@linkplain Session}
137+
* @return a {@linkplain Collection} of {@linkplain Session}
137138
*/
138-
List<Session> GetOpenSessions();
139+
Collection<Session> GetOpenSessions();
139140

140141
/**
141142
* Gets the {@linkplain Project} element from the provided {@linkplain Session}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* CapellaUserPreference.java
3+
*
4+
* Copyright (c) 2020-2022 RHEA System S.A.
5+
*
6+
* Author: Sam Gerené, Alex Vorobiev, Nathanael Smiechowski
7+
*
8+
* This file is part of DEH-Capella
9+
*
10+
* The DEH-Capella is free software; you can redistribute it and/or
11+
* modify it under the terms of the GNU Lesser General Public
12+
* License as published by the Free Software Foundation; either
13+
* version 3 of the License, or (at your option) any later version.
14+
*
15+
* The DEH-Capella is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18+
* Lesser General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Lesser General Public License
21+
* along with this program; if not, write to the Free Software Foundation,
22+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23+
*/
24+
package Services.CapellaUserPreference;
25+
26+
import java.util.HashMap;
27+
28+
/**
29+
* The {@linkplain CapellaUserPreference} holds different preferences for the user saved as Json and handled by the {@linkplain CapellaUserPreferenceService}
30+
*/
31+
public class CapellaUserPreference
32+
{
33+
/**
34+
* Gets or sets the dictionary of preferences
35+
*/
36+
public HashMap<UserPreferenceKey, Object> preferences = new HashMap<>();
37+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* CapellaUserPreferenceService.java
3+
*
4+
* Copyright (c) 2020-2022 RHEA System S.A.
5+
*
6+
* Author: Sam Gerené, Alex Vorobiev, Nathanael Smiechowski
7+
*
8+
* This file is part of DEH-Capella
9+
*
10+
* The DEH-Capella is free software; you can redistribute it and/or
11+
* modify it under the terms of the GNU Lesser General Public
12+
* License as published by the Free Software Foundation; either
13+
* version 3 of the License, or (at your option) any later version.
14+
*
15+
* The DEH-Capella is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18+
* Lesser General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Lesser General Public License
21+
* along with this program; if not, write to the Free Software Foundation,
22+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23+
*/
24+
package Services.CapellaUserPreference;
25+
26+
import Services.UserPreferenceService.UserPreferenceBaseService;
27+
import Services.UserPreferenceService.UserPreferenceService;
28+
29+
/**
30+
* The {@linkplain CapellaUserPreferenceService} is dst adapter specific {@linkplain UserPreferenceService}
31+
*/
32+
public class CapellaUserPreferenceService extends UserPreferenceBaseService<CapellaUserPreference> implements ICapellaUserPreferenceService
33+
{
34+
/**
35+
* Gets the {@linkplain Class} of {@linkplain #TUserPreference}
36+
*/
37+
@Override
38+
protected Class<CapellaUserPreference> GetUserPreferenceType()
39+
{
40+
return CapellaUserPreference.class;
41+
}
42+
43+
/**
44+
* Gets the user preference file name
45+
*/
46+
@Override
47+
protected String GetFileName()
48+
{
49+
return "Capella";
50+
}
51+
52+
/**
53+
* Saves one key to the {@linkplain CapellaUserPreference} file
54+
*
55+
* @param userPreferenceKey the {@linkplain UserPreferenceKey}
56+
* @param value the {@linkplain Object} value
57+
*/
58+
@Override
59+
public void Save(UserPreferenceKey userPreferenceKey, Object value)
60+
{
61+
this.GetUserPreference().preferences.put(userPreferenceKey, value);
62+
this.Save();
63+
}
64+
65+
/**
66+
* Reads one value associated to the specified {@linkplain UserPreferenceKey} from the {@linkplain CapellaUserPreference} file
67+
*
68+
* @param <TValue> the type of value to return
69+
* @param userPreferenceKey the {@linkplain UserPreferenceKey}
70+
* @param valueType the {@linkplain Class} of TValue
71+
* @param defaultValue a default value in case the value is not found
72+
* @return a TValue
73+
*/
74+
@Override
75+
@SuppressWarnings("unchecked")
76+
public <TValue> TValue Get(UserPreferenceKey userPreferenceKey, Class<TValue> valueType, TValue defaultValue)
77+
{
78+
this.Read();
79+
var value = this.GetUserPreference().preferences.get(userPreferenceKey);
80+
81+
if(valueType.isInstance(value))
82+
{
83+
return (TValue)value;
84+
}
85+
86+
return defaultValue;
87+
}
88+
}

0 commit comments

Comments
 (0)