Skip to content

Commit

Permalink
1.5.1
Browse files Browse the repository at this point in the history
* ImplementedWarningDialogWhenMultipleProjectOpen ;fixes #73
  • Loading branch information
Smiechowski Nathanael authored Jul 11, 2022
1 parent e4255e3 commit f07a7a2
Show file tree
Hide file tree
Showing 15 changed files with 565 additions and 12 deletions.
3 changes: 2 additions & 1 deletion DEHCapellaAdapter/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: DEH-CapellaAdapter
Bundle-SymbolicName: com.rheagroup.dehcapellaadapter;singleton:=true
Bundle-Version: 1.5.0
Bundle-Version: 1.5.1
Bundle-Vendor: RHEAGROUP
Require-Bundle: org.eclipse.ui,
org.polarsys.capella.core.model.handler;bundle-version="5.1.0";visibility:=reexport,
Expand Down Expand Up @@ -32,6 +32,7 @@ Export-Package: App,
Services.CapellaSelection,
Services.CapellaSession,
Services.CapellaTransaction,
Services.CapellaUserPreference,
Services.HistoryService,
Services.Mapping,
Services.MappingConfiguration,
Expand Down
6 changes: 6 additions & 0 deletions DEHCapellaAdapter/src/App/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import Services.CapellaSession.SiriusSessionManagerWrapper;
import Services.CapellaTransaction.CapellaTransactionService;
import Services.CapellaTransaction.ICapellaTransactionService;
import Services.CapellaUserPreference.CapellaUserPreferenceService;
import Services.CapellaUserPreference.ICapellaUserPreferenceService;
import Services.HistoryService.CapellaLocalExchangeHistoryService;
import Services.HistoryService.ICapellaLocalExchangeHistoryService;
import Services.Mapping.IMapCommandService;
Expand All @@ -77,8 +79,10 @@
import ViewModels.CapellaObjectBrowser.CapellaObjectBrowserViewModel;
import ViewModels.CapellaObjectBrowser.Interfaces.ICapellaObjectBrowserViewModel;
import ViewModels.ContextMenu.HubBrowserContextMenuViewModel;
import ViewModels.Dialogs.AlertMoreThanOneCapellaModelOpenDialogViewModel;
import ViewModels.Dialogs.DstToHubMappingConfigurationDialogViewModel;
import ViewModels.Dialogs.HubToDstMappingConfigurationDialogViewModel;
import ViewModels.Dialogs.Interfaces.IAlertMoreThanOneCapellaModelOpenDialogViewModel;
import ViewModels.Dialogs.Interfaces.IDstToHubMappingConfigurationDialogViewModel;
import ViewModels.Dialogs.Interfaces.IHubToDstMappingConfigurationDialogViewModel;
import ViewModels.Interfaces.ICapellaHubBrowserPanelViewModel;
Expand Down Expand Up @@ -173,6 +177,7 @@ public void RegisterDependencies()
AppContainer.Container.as(CACHE).addComponent(ICapellaTransactionService.class, CapellaTransactionService.class);
AppContainer.Container.addComponent(IAdapterInfoService.class, CapellaAdapterInfoService.class);
AppContainer.Container.as(CACHE).addComponent(ICapellaLocalExchangeHistoryService.class, CapellaLocalExchangeHistoryService.class);
AppContainer.Container.addComponent(ICapellaUserPreferenceService.class, CapellaUserPreferenceService.class);

AppContainer.Container.addComponent(ComponentToElementMappingRule.class.getName(), ComponentToElementMappingRule.class);
AppContainer.Container.addComponent(ElementToComponentMappingRule.class.getName(), ElementToComponentMappingRule.class);
Expand All @@ -194,6 +199,7 @@ public void RegisterDependencies()
AppContainer.Container.addComponent(ICapellaHubBrowserPanelViewModel.class, CapellaHubBrowserPanelViewModel.class);
AppContainer.Container.addComponent(ICapellaMappedElementListViewViewModel.class, CapellaMappedElementListViewViewModel.class);
AppContainer.Container.addComponent(IMappingListViewViewModel.class, CapellaMappingListViewViewModel.class);
AppContainer.Container.addComponent(IAlertMoreThanOneCapellaModelOpenDialogViewModel.class.getSimpleName(), AlertMoreThanOneCapellaModelOpenDialogViewModel.class);
}
catch (Exception exception)
{
Expand Down
52 changes: 50 additions & 2 deletions DEHCapellaAdapter/src/DstController/DstController.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import static Utils.Operators.Operators.AreTheseEquals;

import java.awt.EventQueue;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -62,10 +63,13 @@
import Services.CapellaLog.ICapellaLogService;
import Services.CapellaSession.ICapellaSessionService;
import Services.CapellaTransaction.ICapellaTransactionService;
import Services.CapellaUserPreference.ICapellaUserPreferenceService;
import Services.CapellaUserPreference.UserPreferenceKey;
import Services.HistoryService.ICapellaLocalExchangeHistoryService;
import Services.MappingConfiguration.ICapellaMappingConfigurationService;import Services.MappingConfiguration.IMappingConfigurationService;
import Services.MappingEngineService.IMappableThingCollection;
import Services.MappingEngineService.IMappingEngineService;
import Services.NavigationService.INavigationService;
import Utils.Ref;
import Utils.Stereotypes.CapellaComponentCollection;
import Utils.Stereotypes.CapellaRequirementCollection;
Expand All @@ -79,6 +83,7 @@
import ViewModels.Rows.MappedElementRowViewModel;
import ViewModels.Rows.MappedHubRequirementRowViewModel;
import ViewModels.Rows.MappedRequirementBaseRowViewModel;
import Views.Dialogs.AlertMoreThanOneCapellaModelOpenDialog;
import cdp4common.ChangeKind;
import cdp4common.commondata.ClassKind;
import cdp4common.commondata.DefinedThing;
Expand All @@ -103,6 +108,8 @@
import cdp4dal.exceptions.TransactionException;
import cdp4dal.operations.ThingTransaction;
import io.reactivex.Observable;
import io.reactivex.Scheduler;
import io.reactivex.schedulers.Schedulers;

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

/**
* The {@linkplain INavigationService} instance
*/
private final INavigationService navigationService;

/**
* The {@linkplain ICapellaUserPreferenceService} instance
*/
private final ICapellaUserPreferenceService userPreferenceService;

/**
* A value indicating whether the {@linkplain DstController} should load mapping when the HUB session is refresh or reloaded
*/
Expand Down Expand Up @@ -330,10 +347,13 @@ public boolean HasAnyOpenSession()
* @param capellaSessionService the {@linkplain ICapellaSessionService} instance
* @param transactionService the {@linkplain ICapellaTransactionService} instance
* @param exchangeHistory the {@linkplain ICapellaLocalExchangeHistoryService} instance
* @param userPreferenceService the {@linkplain CapellaUserPreferenceService} instance
* @param navigationService the {@linkplain INavigationService} instance
*/
public DstController(IMappingEngineService mappingEngine, IHubController hubController, ICapellaLogService logService,
ICapellaMappingConfigurationService mappingConfigurationService, ICapellaSessionService capellaSessionService,
ICapellaTransactionService transactionService, ICapellaLocalExchangeHistoryService exchangeHistory)
ICapellaTransactionService transactionService, ICapellaLocalExchangeHistoryService exchangeHistory,
ICapellaUserPreferenceService userPreferenceService, INavigationService navigationService)
{
this.mappingEngine = mappingEngine;
this.hubController = hubController;
Expand All @@ -342,6 +362,8 @@ public DstController(IMappingEngineService mappingEngine, IHubController hubCont
this.capellaSessionService = capellaSessionService;
this.transactionService = transactionService;
this.exchangeHistory = exchangeHistory;
this.userPreferenceService = userPreferenceService;
this.navigationService = navigationService;

this.hubController.GetIsSessionOpenObservable().subscribe(isSessionOpen ->
{
Expand All @@ -362,10 +384,36 @@ public DstController(IMappingEngineService mappingEngine, IHubController hubCont
{
if(!this.isHubSessionRefreshSilent)
{
this.LoadMapping();
this.LoadMapping();
}
});

if(!this.userPreferenceService.Get(UserPreferenceKey.ShouldNeverRemindMeThatMoreThanOneCapellaModelIsOpen, Boolean.class, false))
{
Ref<Boolean> isDialogOpen = new Ref<>(Boolean.class, false);

Observable.combineLatest(this.capellaSessionService.HasAnyOpenSessionObservable().startWith(this.HasAnyOpenSession()),
this.hubController.GetIsSessionOpenObservable(),
(hasAnyCapellaModelOpen, isHubSessionOpen) ->
hasAnyCapellaModelOpen && isHubSessionOpen
&& this.capellaSessionService.GetOpenSessions().size() > 1
&& !this.userPreferenceService.Get(UserPreferenceKey.ShouldNeverRemindMeThatMoreThanOneCapellaModelIsOpen, Boolean.class, false))
.filter(x -> x)
.subscribe(x ->
{
if(!isDialogOpen.Get())
{
isDialogOpen.Set(true);

EventQueue.invokeLater(() ->
{
this.navigationService.ShowDialog(new AlertMoreThanOneCapellaModelOpenDialog());
isDialogOpen.Set(false);
});
}
});
}

this.GetDstMapResult().ItemsAdded().subscribe(x -> this.MapTraces(MappingDirection.FromDstToHub));
this.GetHubMapResult().ItemsAdded().subscribe(x -> this.MapTraces(MappingDirection.FromHubToDst));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package Services.CapellaSession;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.function.BiConsumer;
Expand All @@ -45,6 +46,7 @@

import Enumerations.CapellaArchitecture;
import Reactive.ObservableValue;
import Services.NavigationService.INavigationService;
import ViewModels.CapellaObjectBrowser.Rows.RootRowViewModel;
import io.reactivex.Observable;

Expand Down Expand Up @@ -116,7 +118,7 @@ public Session GetCurrentSession()
{
if(currentSession == null)
{
this.currentSession = this.GetOpenSessions().get(0);
this.currentSession = new ArrayList<>(this.GetOpenSessions()).get(0);
}
else if(!this.GetOpenSessions().contains(this.currentSession))
{
Expand Down Expand Up @@ -199,12 +201,12 @@ public boolean HasAnyOpenSession()
/**
* Gets the open {@linkplain Session}s
*
* @return a {@linkplain List} of {@linkplain Session}
* @return a {@linkplain Collection} of {@linkplain Session}
*/
@Override
public List<Session> GetOpenSessions()
public Collection<Session> GetOpenSessions()
{
return this.sessionManager.GetSessions().stream().collect(Collectors.toList());
return this.sessionManager.GetSessions();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package Services.CapellaSession;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -133,9 +134,9 @@ public interface ICapellaSessionService
/**
* Gets the open {@linkplain Session}s
*
* @return a {@linkplain List} of {@linkplain Session}
* @return a {@linkplain Collection} of {@linkplain Session}
*/
List<Session> GetOpenSessions();
Collection<Session> GetOpenSessions();

/**
* Gets the {@linkplain Project} element from the provided {@linkplain Session}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* CapellaUserPreference.java
*
* Copyright (c) 2020-2022 RHEA System S.A.
*
* Author: Sam Gerené, Alex Vorobiev, Nathanael Smiechowski
*
* This file is part of DEH-Capella
*
* The DEH-Capella is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* The DEH-Capella is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package Services.CapellaUserPreference;

import java.util.HashMap;

/**
* The {@linkplain CapellaUserPreference} holds different preferences for the user saved as Json and handled by the {@linkplain CapellaUserPreferenceService}
*/
public class CapellaUserPreference
{
/**
* Gets or sets the dictionary of preferences
*/
public HashMap<UserPreferenceKey, Object> preferences = new HashMap<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* CapellaUserPreferenceService.java
*
* Copyright (c) 2020-2022 RHEA System S.A.
*
* Author: Sam Gerené, Alex Vorobiev, Nathanael Smiechowski
*
* This file is part of DEH-Capella
*
* The DEH-Capella is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* The DEH-Capella is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package Services.CapellaUserPreference;

import Services.UserPreferenceService.UserPreferenceBaseService;
import Services.UserPreferenceService.UserPreferenceService;

/**
* The {@linkplain CapellaUserPreferenceService} is dst adapter specific {@linkplain UserPreferenceService}
*/
public class CapellaUserPreferenceService extends UserPreferenceBaseService<CapellaUserPreference> implements ICapellaUserPreferenceService
{
/**
* Gets the {@linkplain Class} of {@linkplain #TUserPreference}
*/
@Override
protected Class<CapellaUserPreference> GetUserPreferenceType()
{
return CapellaUserPreference.class;
}

/**
* Gets the user preference file name
*/
@Override
protected String GetFileName()
{
return "Capella";
}

/**
* Saves one key to the {@linkplain CapellaUserPreference} file
*
* @param userPreferenceKey the {@linkplain UserPreferenceKey}
* @param value the {@linkplain Object} value
*/
@Override
public void Save(UserPreferenceKey userPreferenceKey, Object value)
{
this.GetUserPreference().preferences.put(userPreferenceKey, value);
this.Save();
}

/**
* Reads one value associated to the specified {@linkplain UserPreferenceKey} from the {@linkplain CapellaUserPreference} file
*
* @param <TValue> the type of value to return
* @param userPreferenceKey the {@linkplain UserPreferenceKey}
* @param valueType the {@linkplain Class} of TValue
* @param defaultValue a default value in case the value is not found
* @return a TValue
*/
@Override
@SuppressWarnings("unchecked")
public <TValue> TValue Get(UserPreferenceKey userPreferenceKey, Class<TValue> valueType, TValue defaultValue)
{
this.Read();
var value = this.GetUserPreference().preferences.get(userPreferenceKey);

if(valueType.isInstance(value))
{
return (TValue)value;
}

return defaultValue;
}
}
Loading

0 comments on commit f07a7a2

Please sign in to comment.