public code v1
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>flintstones.group</groupId>
|
||||
<artifactId>flintstones.bundles</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>flintstones.model.application.provider</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] Service</name>
|
||||
</project>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.model.application.provider</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ds.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1779484362720</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
@@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -0,0 +1,32 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %Bundle-Name
|
||||
Bundle-SymbolicName: flintstones.model.application.provider;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Automatic-Module-Name: flintstones.application.service
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
Service-Component: plugin.xml,
|
||||
OSGI-INF/flintstones.application.model.service.ApplicationServiceProvider.xml
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Require-Bundle: flintstones.model.application.service,
|
||||
flintstones.helper.data.io,
|
||||
org.eclipse.e4.core.services,
|
||||
org.eclipse.e4.core.contexts,
|
||||
org.eclipse.e4.core.di,
|
||||
org.eclipse.e4.ui.di,
|
||||
org.eclipse.e4.ui.model.workbench,
|
||||
org.eclipse.e4.ui.workbench,
|
||||
javax.inject,
|
||||
org.eclipse.jface,
|
||||
flintstones.application.constants,
|
||||
flintstones.helper.extensionpoint,
|
||||
flintstones.helper.git,
|
||||
javax.annotation,
|
||||
org.eclipse.nebula.widgets.opal.notifier,
|
||||
flintstones.helper.locale,
|
||||
flintstones.application.debug
|
||||
Export-Package: flintstones.application.model.service,
|
||||
flintstones.application.model.service.handler
|
||||
Import-Package: org.eclipse.core.runtime,
|
||||
org.osgi.framework;version="1.9.0",
|
||||
org.osgi.service.component.annotations;version="1.2.0"
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="flintstones.application.model.service.ApplicationServiceProvider">
|
||||
<service>
|
||||
<provide interface="flintstones.application.model.IApplicationService"/>
|
||||
</service>
|
||||
<implementation class="flintstones.application.model.service.ApplicationServiceProvider"/>
|
||||
</scr:component>
|
||||
@@ -0,0 +1,6 @@
|
||||
#Properties file for flintstones.model.application.provider
|
||||
Bundle-Name = Service
|
||||
extension-point.name = Language
|
||||
language.chinese = Chinese
|
||||
language.spanish = Spanish
|
||||
language.english = English
|
||||
@@ -0,0 +1,6 @@
|
||||
#Properties file for flintstones.model.application.provider
|
||||
Bundle-Name = Service
|
||||
extension-point.name = Language
|
||||
language.chinese = Chino
|
||||
language.spanish = Español
|
||||
language.english = Inglés
|
||||
@@ -0,0 +1,7 @@
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
OSGI-INF/,\
|
||||
plugin.xml,\
|
||||
OSGI-INF/l10n/bundle.properties
|
||||
source.. = src/
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension-point id="flintsonte.service.language" name="%extension-point.name" schema="schema/flintsonte.service.language.exsd"/>
|
||||
<extension
|
||||
point="flintsonte.service.language">
|
||||
<language
|
||||
icon_uri="platform:/plugin/flintstones.model.ui.service/icons/flag_uk_16.png"
|
||||
uid="flintstones.application.service.language.en"
|
||||
label="%language.english"
|
||||
slug="en">
|
||||
</language>
|
||||
<language
|
||||
icon_uri="platform:/plugin/flintstones.model.ui.service/icons/flag_spain_16.png"
|
||||
uid="flintstones.application.service.language.es"
|
||||
label="%language.spanish"
|
||||
slug="es">
|
||||
</language>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Schema file written by PDE -->
|
||||
<schema targetNamespace="flintstones.application.model.service" xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.schema plugin="flintstones.application.model.service" id="flintsonte.service.language" name="Language"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter description of this extension point.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<element name="extension">
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.element />
|
||||
</appinfo>
|
||||
</annotation>
|
||||
<complexType>
|
||||
<choice minOccurs="1" maxOccurs="unbounded">
|
||||
<element ref="language"/>
|
||||
</choice>
|
||||
<attribute name="point" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="xid" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="name" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute translatable="true"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="language">
|
||||
<complexType>
|
||||
<attribute name="uid" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute kind="identifier"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="label" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="slug" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="icon_uri" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.section type="since"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter the first release in which this extension point appears.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.section type="examples"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter extension point usage example here.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.section type="apiinfo"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter API information here.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.section type="implementation"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter information about supplied implementation of this extension point.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
|
||||
</schema>
|
||||
+523
@@ -0,0 +1,523 @@
|
||||
package flintstones.application.model.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.core.di.annotations.Optional;
|
||||
import org.eclipse.e4.core.services.events.IEventBroker;
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
import org.eclipse.e4.ui.di.UIEventTopic;
|
||||
import org.eclipse.e4.ui.model.application.MApplication;
|
||||
import org.eclipse.e4.ui.model.application.commands.MCommand;
|
||||
import org.eclipse.e4.ui.model.application.commands.MParameter;
|
||||
import org.eclipse.e4.ui.model.application.ui.MUIElement;
|
||||
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
|
||||
import org.eclipse.e4.ui.model.application.ui.menu.ItemType;
|
||||
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
||||
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
|
||||
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
|
||||
import org.eclipse.e4.ui.workbench.UIEvents;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
||||
import org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.nebula.widgets.opal.notifier.INotificationClickedListener;
|
||||
import org.eclipse.nebula.widgets.opal.notifier.NotifierColorsFactory.NotifierTheme;
|
||||
import org.eclipse.nebula.widgets.opal.notifier.WNotifier;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
|
||||
import flintstones.application.constants.ApplicationContants;
|
||||
import flintstones.application.debug.handler.OpenSaveFileDebugHandler;
|
||||
import flintstones.application.model.IApplicationService;
|
||||
import flintstones.application.model.ProblemType;
|
||||
import flintstones.application.model.service.handler.WindowCloseHandler;
|
||||
import flintstones.application.model.service.messages.Messages;
|
||||
import flintstones.helper.data.io.ClearData;
|
||||
import flintstones.helper.data.io.FlintstonesIO;
|
||||
import flintstones.helper.extensionpoint.BaseRegistry;
|
||||
import flintstones.helper.extensionpoint.ExtensionRegistry;
|
||||
import flintstones.helper.git.GitInformation;
|
||||
import flintstones.helper.locale.LocaleHelper;
|
||||
|
||||
/**
|
||||
* The Class ApplicationServiceProvider. Controls the status of the application
|
||||
* using the concept of project stored on disk, unsaved changes and build id.
|
||||
*/
|
||||
@Component
|
||||
public class ApplicationServiceProvider implements IApplicationService {
|
||||
|
||||
/** The messages. */
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/** The context. */
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
/** The application. */
|
||||
@Inject
|
||||
MApplication application;
|
||||
|
||||
/** The model service. */
|
||||
@Inject
|
||||
EModelService modelService;
|
||||
|
||||
@Inject
|
||||
MApplication app;
|
||||
|
||||
@Inject
|
||||
EPartService partService;
|
||||
|
||||
@Inject
|
||||
IEventBroker broker;
|
||||
|
||||
/** The proyect path. */
|
||||
private String proyectPath;
|
||||
|
||||
/** The saved. */
|
||||
boolean saved = true;
|
||||
|
||||
/** The last save. */
|
||||
Date lastSave;
|
||||
|
||||
/** The build hash. */
|
||||
String buildHash;
|
||||
|
||||
/** The io version. */
|
||||
String ioVersion;
|
||||
|
||||
// Problem type
|
||||
ProblemType problemType = ProblemType.Ranking;
|
||||
|
||||
/**
|
||||
* Instantiates a new application service provider.
|
||||
*/
|
||||
public ApplicationServiceProvider() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Inits the.
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
LocaleHelper.setLocale("en"); //$NON-NLS-1$
|
||||
this.buildHash = ContextInjectionFactory.make(GitInformation.class, this.context).getAppHash();
|
||||
this.newProblem();
|
||||
|
||||
loadLanguagesExtentionPoint();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.application.model.IApplicationService#isSaved()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSaved() {
|
||||
return this.saved;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.application.model.IApplicationService#getLastSave()
|
||||
*/
|
||||
@Override
|
||||
public Date getLastSave() {
|
||||
return this.lastSave;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.application.model.IApplicationService#getBuildHash()
|
||||
*/
|
||||
@Override
|
||||
public String getBuildHash() {
|
||||
return this.buildHash;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.application.model.IApplicationService#getIOVersion()
|
||||
*/
|
||||
@Override
|
||||
public String getIOVersion() {
|
||||
// TODO Auto-generated method stub x
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.application.model.IApplicationService#newProblem()
|
||||
*/
|
||||
@Override
|
||||
public void newProblem() {
|
||||
|
||||
String filename = this.getNewFilename(true);
|
||||
String path = this.getPath(filename);
|
||||
|
||||
boolean reset = true;
|
||||
if (!this.saved)
|
||||
reset = this.getUnsavedConfirmation();
|
||||
|
||||
if (reset) {
|
||||
System.out.println("!INFOFS Creando proyecto en " + path); //$NON-NLS-1$
|
||||
this.clearData();
|
||||
this.saveProblemAs(path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearData() {
|
||||
ContextInjectionFactory.make(ClearData.class, this.context).execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the savefile path .
|
||||
*
|
||||
* @param filename the filename
|
||||
* @return the path
|
||||
*/
|
||||
private String getPath(String filename) {
|
||||
// String folder = System.getProperty("user.home") + File.separator + "Desktop"
|
||||
// + File.separator + "save"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
String folder = getFS4FolderPath() + File.separator + "save"; //$NON-NLS-1$
|
||||
String fullPath = folder + File.separator + filename;
|
||||
|
||||
if (!new File(folder).exists())
|
||||
new File(folder).mkdirs();
|
||||
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFS4FolderPath() {
|
||||
String folder = System.getProperty("user.home") + File.separator + "flintstones"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return folder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the new filename using the current date.
|
||||
*
|
||||
* @param auto the auto
|
||||
* @return the new filename
|
||||
*/
|
||||
private String getNewFilename(boolean auto) {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); //$NON-NLS-1$
|
||||
String dateS = dateFormat.format(date);
|
||||
|
||||
String template = "proyect-{0}{1}.flintstones"; //$NON-NLS-1$
|
||||
String file = MessageFormat.format(template, dateS, auto ? ".auto" : ""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.application.model.IApplicationService#loadProblem(java.lang.
|
||||
* String)
|
||||
*/
|
||||
@Override
|
||||
public void loadProblem(String filename) {
|
||||
|
||||
this.clearData();
|
||||
|
||||
FlintstonesIO fio = ContextInjectionFactory.make(FlintstonesIO.class, this.context);
|
||||
fio.load(filename);
|
||||
this.setPath(filename);
|
||||
|
||||
String pers = "flintstones.application.perspective.framework"; //$NON-NLS-1$
|
||||
|
||||
broker.send("TOPIC_WINDOW_TRIMBAR",pers); //$NON-NLS-1$
|
||||
this.changePerspective(pers);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.application.model.IApplicationService#saveProblemAs(java.lang.
|
||||
* String)
|
||||
*/
|
||||
@Override
|
||||
public void saveProblemAs(String file) {
|
||||
|
||||
this.setPath(file);
|
||||
this.saveProblem();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.application.model.IApplicationService#saveProblem()
|
||||
*/
|
||||
@Override
|
||||
public void saveProblem() {
|
||||
FlintstonesIO fio = ContextInjectionFactory.make(FlintstonesIO.class, this.context);
|
||||
try {
|
||||
fio.writeFile(this.proyectPath);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.lastSave = new Date();
|
||||
this.saved = true;
|
||||
|
||||
new WNotifier(messages.saved, messages.saved_successfully, NotifierTheme.BLUE_THEME).onClick(new INotificationClickedListener() { //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
@Override
|
||||
public void onNotificationClick() {
|
||||
ContextInjectionFactory.make(OpenSaveFileDebugHandler.class, context).execute();
|
||||
}
|
||||
}, true)
|
||||
.send();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the savefile path.
|
||||
*
|
||||
* @param newPath the new path
|
||||
*/
|
||||
private void setPath(String newPath) {
|
||||
this.proyectPath = newPath;
|
||||
this.refreshTitle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the window itle.
|
||||
*/
|
||||
private void refreshTitle() {
|
||||
String titleTemplate = this.messages.title_template;
|
||||
String title = MessageFormat.format(titleTemplate, this.proyectPath,
|
||||
!this.saved ? this.messages.unsaved_changes : "", //$NON-NLS-1$
|
||||
this.buildHash != null ? this.buildHash : "" //$NON-NLS-1$
|
||||
);
|
||||
MWindow window = (MWindow) this.modelService.find("flintstones.application.trimmedwindow.flintstones", //$NON-NLS-1$
|
||||
this.application);
|
||||
window.setLabel(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register close event.
|
||||
*
|
||||
* @param application the application
|
||||
* @param modelService the model service
|
||||
*/
|
||||
@Inject
|
||||
@Optional
|
||||
public void registerCloseEvent(@UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) MApplication application,
|
||||
EModelService modelService) {
|
||||
MWindow window = (MWindow) modelService.find("flintstones.application.trimmedwindow.flintstones", application); //$NON-NLS-1$
|
||||
WindowCloseHandler handler = ContextInjectionFactory.make(WindowCloseHandler.class, this.context);
|
||||
window.getContext().set(IWindowCloseHandler.class, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unsaved confirmation if necesary.
|
||||
*
|
||||
* @return the unsaved confirmation
|
||||
*/
|
||||
private boolean getUnsavedConfirmation() {
|
||||
if (this.devMode())
|
||||
return true;
|
||||
|
||||
return MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), this.messages.button_confirm,
|
||||
this.messages.unsaved_changes_full);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.application.model.IApplicationService#close()
|
||||
*/
|
||||
@Override
|
||||
public boolean close() {
|
||||
if (!this.saved)
|
||||
return this.getUnsavedConfirmation();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecado para que se dibuje en rojo. No hay problema en usarlo.
|
||||
*
|
||||
* @deprecated Deprecado para que se dibuje en rojo. No hay problema en usarlo.
|
||||
*/
|
||||
@Override
|
||||
public boolean devMode() {
|
||||
String[] args = Platform.getCommandLineArgs();
|
||||
boolean status = Arrays.asList(args).stream().anyMatch(flag -> flag.equals("-development")); //$NON-NLS-1$
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("proyectPath ==> " + this.proyectPath + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
sb.append("saved ==> " + this.saved + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
sb.append("lastSave ==> " + this.lastSave.toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
sb.append("buildHash ==> " + this.buildHash + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// sb.append("ioVersion ==> " + this.ioVersion + "\n");
|
||||
sb.append("currentLocale ==> " + LocaleHelper.getLocale() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changePerspective(String perspectiveId) {
|
||||
List<MPerspective> perspectives = modelService.findElements(app, perspectiveId, MPerspective.class, null);
|
||||
|
||||
// switch to perspective with the ID if found
|
||||
if (!perspectives.isEmpty())
|
||||
partService.switchPerspective(perspectives.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFlagEnabled(String key) {
|
||||
String[] args = Platform.getCommandLineArgs();
|
||||
boolean status = Arrays.asList(args).stream().anyMatch(flag -> flag.equals("-" + key)); //$NON-NLS-1$
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSavePath() {
|
||||
return proyectPath;
|
||||
}
|
||||
|
||||
private void loadLanguagesExtentionPoint() {
|
||||
BaseRegistry reg = new BaseRegistry("flintsonte.service.language"); //$NON-NLS-1$
|
||||
|
||||
MWindow window = (MWindow) this.modelService.find(ApplicationContants.MWindow_Main, this.application);
|
||||
|
||||
int indiceMenu = -1;
|
||||
String slug = "", label = "", icon_uri = "", fullId; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
MMenu mainMenu = window.getMainMenu();
|
||||
List<MMenuElement> elements = mainMenu.getChildren();
|
||||
|
||||
// Buscamos el menu de idiomas en la aplicacion.
|
||||
for (int i = 0; i < elements.size(); i++) {
|
||||
if (elements.get(i).getElementId().equals("flintstones.application.menu.locale")) { //$NON-NLS-1$
|
||||
indiceMenu = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MMenu menu = (MMenu) elements.get(indiceMenu);
|
||||
|
||||
// Obtenemos los puntos de extesion.
|
||||
ExtensionRegistry[] br = reg.getAllRegistries();
|
||||
|
||||
for (int i = 0; i < br.length; i++) {
|
||||
|
||||
slug = br[i].getAttribute("slug"); //$NON-NLS-1$
|
||||
label = br[i].getAttribute("label"); //$NON-NLS-1$
|
||||
icon_uri = br[i].getAttribute("icon_uri"); //$NON-NLS-1$
|
||||
fullId = "flintstones.application.menu." + slug; //$NON-NLS-1$
|
||||
|
||||
String commandId = ApplicationContants.MCommand_Global_Selectlocale;
|
||||
|
||||
// MCommand command = createCommand(slug);
|
||||
MCommand command = modelService.findElements(app, commandId, MCommand.class, null).get(0);
|
||||
MHandledMenuItem dynamicMenuItem = createMenu(label, icon_uri, fullId, command);
|
||||
|
||||
// addition
|
||||
menu.getChildren().add(dynamicMenuItem);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// https://wiki.eclipse.org/Eclipse4/RCP/FAQ
|
||||
// Why is my parameterized handler not triggered?
|
||||
|
||||
private MHandledMenuItem createMenu(String label, String icon_uri, String fullId, MCommand command) {
|
||||
MHandledMenuItem dynamicMenuItem = modelService.createModelElement(MHandledMenuItem.class);
|
||||
dynamicMenuItem.setLabel(label);
|
||||
dynamicMenuItem.setType(ItemType.PUSH);
|
||||
dynamicMenuItem.setIconURI(icon_uri);
|
||||
|
||||
dynamicMenuItem.setCommand(command);
|
||||
|
||||
MParameter parameter = modelService.createModelElement(MParameter.class);
|
||||
parameter.setName(ApplicationContants.MParameter_Global_Selectlocale);
|
||||
parameter.setValue(fullId);
|
||||
dynamicMenuItem.getParameters().add(parameter);
|
||||
|
||||
return dynamicMenuItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentLocale() {
|
||||
return LocaleHelper.getLocale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentLocale(String slug) {
|
||||
LocaleHelper.setLocale(slug);
|
||||
}
|
||||
|
||||
private void setVisible(String elementId, boolean status) {
|
||||
MUIElement uiElement = (MUIElement) modelService.find(elementId, this.application); // $NON-NLS-1$
|
||||
uiElement.setVisible(status);
|
||||
}
|
||||
|
||||
String MPartStack_Domain = "flintstones.framework.ui.partstack.domains"; //$NON-NLS-1$
|
||||
String MPartStack_DomainViewer = "flintstones.framework.ui.partstack.domain"; //$NON-NLS-1$
|
||||
String MPartStack_AHPClasses = "flintstones.framework.ui.partstack.ahpclasses"; //$NON-NLS-1$
|
||||
String MPartStack_AHPPRofiles = "flintstones.framework.ui.partstack.ahpprofiles"; //$NON-NLS-1$
|
||||
String MPartStack_AHPViewer = "flintstones.framework.ui.partstack.ahpviewer"; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public void launchProblem(ProblemType type) {
|
||||
|
||||
problemType = type;
|
||||
|
||||
boolean isRanking = type.equals(ProblemType.Ranking);
|
||||
boolean isSorting = type.equals(ProblemType.Sorting);
|
||||
|
||||
setVisible(ApplicationContants.MPartStack_Domain, true);
|
||||
|
||||
if (isRanking) {
|
||||
setVisible(ApplicationContants.MPartStack_DomainViewer, false);
|
||||
setVisible(ApplicationContants.MPartStack_AHPClasses, !isRanking);
|
||||
setVisible(ApplicationContants.MPartStack_AHPPRofiles, !isRanking);
|
||||
setVisible(ApplicationContants.MPartStack_AHPViewer, !isRanking);
|
||||
}
|
||||
|
||||
if(isSorting) {
|
||||
setVisible(ApplicationContants.MPartStack_DomainViewer, !isSorting);
|
||||
setVisible(ApplicationContants.MPartStack_AHPClasses, isSorting);
|
||||
setVisible(ApplicationContants.MPartStack_AHPPRofiles, isSorting);
|
||||
setVisible(ApplicationContants.MPartStack_AHPViewer, isSorting);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProblemType getProblemType() {
|
||||
return problemType;
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package flintstones.application.model.service.handler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
|
||||
import org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler;
|
||||
|
||||
import flintstones.application.model.IApplicationService;
|
||||
|
||||
/**
|
||||
* The Class WindowCloseHandler.
|
||||
*/
|
||||
public class WindowCloseHandler implements IWindowCloseHandler {
|
||||
|
||||
/** The app service. */
|
||||
@Inject
|
||||
IApplicationService appService;
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler#close(org.eclipse.e4
|
||||
* .ui.model.application.ui.basic.MWindow) */
|
||||
@Override
|
||||
public boolean close(MWindow window) {
|
||||
return this.appService.close();
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package flintstones.application.model.service.messages;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Message;
|
||||
|
||||
@Message
|
||||
@SuppressWarnings("javadoc")
|
||||
public class Messages {
|
||||
|
||||
public String title_template;
|
||||
public String unsaved_changes;
|
||||
public String button_confirm;
|
||||
public String unsaved_changes_full;
|
||||
public String saved;
|
||||
public String saved_successfully;
|
||||
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
saved=Saved
|
||||
saved_successfully=Saved successfully
|
||||
X=1.1.1.1
|
||||
title_template=Flintstones - {0}{1} - {2}
|
||||
unsaved_changes= (There are unsaved changes)
|
||||
button_confirm=Confirm
|
||||
unsaved_changes_full=There are unsaved changes. Changes will be lost.
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
saved=Guardado
|
||||
saved_successfully=Guardado con éxito
|
||||
X=1.1.1.2
|
||||
title_template=Flintstones - {0}{1} - {2}
|
||||
unsaved_changes= (Hay cambios sin guardar)
|
||||
button_confirm=Confirmar
|
||||
unsaved_changes_full=Hay información sin guardar. Si continua la perderá
|
||||
Reference in New Issue
Block a user