/*
* Michel Héon PhD: Web sémantique et modélisation ontologique - Guide du développeur Java sous Eclipse
* This file is part of the book:
*
* Michel Héon
* Web sémantique et modélisation ontologique - Guide du développeur Java sous Eclipse
* 2014
* Editions ENI
* ISBN : 978-2-7460-8869-6
* EAN : 9782746088696
* France
*
* The contents of this file are subject to the LGPL License, Version 3.0.
*
* Copyright (C) 2014, Cotechnoe inc. http://www.cotechnoe.com, http://java-ws.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*
* Alternatively, the contents of this file may be used under the terms of the Apache License, Version 2.0
* in which case, the provisions of the Apache License Version 2.0 are applicable instead of those above.
*
* Copyright (C) 2014, Cotechnoe inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.java_ws.ontodetai.iu;
import java.io.IOException;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.PojoObservables;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
import com.java_ws.ontodetai.metier.CommandeFixerTauxImpostion;
import com.java_ws.ontodetai.metier.Contribuable;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.semanticweb.owlapi.model.OWLException;
/** Auteur: Michel Héon PhD
* Cotechnoe http://www.cotechnoe.com
* Date: 15-jan-2014
*/
@SuppressWarnings("unused")
/****************************************************************
****************************************************************
**
** Chapitre 10 OntoDeTai
**
****************************************************************
****************************************************************/
public class OntoDeTai extends Shell {
private DataBindingContext m_bindingContext;
private Contribuable contribuable = new Contribuable();
private Text nomText;
private Text statutText;
private Button avecPersonneChargeButton;
private Spinner salaireSpinner;
private Text categorieDeRevenuText;
private Text tauxImpositionText;
private Composite composite;
private Button marie;
private Button celibataire;
private Button btnFixer;
private CommandeFixerTauxImpostion commandeFixer;
/**
* Launch the application.
* @param args
*/
public static void main(String args[]) {
Display display = new Display();
Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
public void run() {
try {
Display display = Display.getDefault();
OntoDeTai shell = new OntoDeTai(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the shell.
* @param display
* @param style
*/
public OntoDeTai(Display display, int style) {
super(display, style);
createContents();
}
/**
* Create contents of the window.
*/
protected void createContents() {
commandeFixer = new CommandeFixerTauxImpostion();
setText("SWT Application");
setSize(450, 300);
setLayout(new GridLayout(2, false));
new Label(this, SWT.NONE).setText("Nom:");
nomText = new Text(this, SWT.BORDER | SWT.SINGLE);
nomText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
new Label(this, SWT.NONE).setText("Statut:");
composite = new Composite(this, SWT.NONE);
GridData gd_composite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_composite.heightHint = 53;
gd_composite.widthHint = 140;
composite.setLayoutData(gd_composite);
composite.setLayout(null);
marie = new Button(composite, SWT.RADIO);
marie.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
contribuable.setStatut(Contribuable.Statut.MARIE);
}
});
marie.setBounds(10, 10, 83, 16);
marie.setText("Mari\u00E9");
celibataire = new Button(composite, SWT.RADIO);
celibataire.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
contribuable.setStatut(Contribuable.Statut.CELIBATAIRE);
}
});
celibataire.setBounds(10, 32, 83, 16);
celibataire.setText("C\u00E9libataire");
// statutText = new Text(this, SWT.BORDER | SWT.SINGLE);
// statutText
// .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
new Label(this, SWT.NONE).setText("AvecPersonneCharge:");
avecPersonneChargeButton = new Button(this, SWT.CHECK);
avecPersonneChargeButton.setLayoutData(new GridData(SWT.FILL,
SWT.CENTER, true, false));
new Label(this, SWT.NONE).setText("Salaire:");
salaireSpinner = new Spinner(this, SWT.BORDER);
salaireSpinner.setIncrement(100);
salaireSpinner.setMaximum(Integer.MAX_VALUE);
salaireSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
false));
new Label(this, SWT.NONE).setText("CategorieDeRevenu:");
categorieDeRevenuText = new Text(this, SWT.BORDER | SWT.SINGLE);
categorieDeRevenuText.setEditable(false);
categorieDeRevenuText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
true, false));
new Label(this, SWT.NONE).setText("TauxImposition:");
tauxImpositionText = new Text(this, SWT.BORDER | SWT.SINGLE);
tauxImpositionText.setEditable(false);
tauxImpositionText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
true, false));
new Label(this, SWT.NONE);
new Label(this, SWT.NONE);
btnFixer = new Button(this, SWT.NONE);
btnFixer.addMouseListener(new MouseAdapter() {
public void mouseUp(MouseEvent e) {
try {
contribuable = commandeFixer.execute(contribuable);
tauxImpositionText.setText(contribuable.getTauxImposition());
categorieDeRevenuText.setText(contribuable.getCategorieDeRevenu());
} catch (UnsupportedOperationException e1) {
// TODO Bloc catch auto-généré
e1.printStackTrace();
} catch (OWLException e1) {
// TODO Bloc catch auto-généré
e1.printStackTrace();
} catch (IOException e1) {
// TODO Bloc catch auto-généré
e1.printStackTrace();
}
}
});
btnFixer.setText("Evaluer le taux");
new Label(this, SWT.NONE);
if (contribuable != null) {
m_bindingContext = initDataBindings();
}
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
private DataBindingContext initDataBindings() {
IObservableValue nomObserveWidget = SWTObservables.observeText(nomText,
SWT.Modify);
IObservableValue nomObserveValue = PojoObservables.observeValue(
contribuable, "nom");
// IObservableValue statutObserveWidget = SWTObservables.observeText(
// statutText, SWT.Modify);
IObservableValue statutObserveValue = PojoObservables.observeValue(
contribuable, "statut");
IObservableValue avecPersonneChargeObserveWidget = SWTObservables
.observeSelection(avecPersonneChargeButton);
IObservableValue avecPersonneChargeObserveValue = PojoObservables
.observeValue(contribuable, "avecPersonneCharge");
IObservableValue salaireObserveWidget = SWTObservables
.observeSelection(salaireSpinner);
IObservableValue salaireObserveValue = PojoObservables.observeValue(
contribuable, "salaire");
IObservableValue categorieDeRevenuObserveWidget = SWTObservables
.observeText(categorieDeRevenuText, SWT.Modify);
IObservableValue categorieDeRevenuObserveValue = PojoObservables
.observeValue(contribuable, "categorieDeRevenu");
IObservableValue tauxImpositionObserveWidget = SWTObservables
.observeText(tauxImpositionText, SWT.Modify);
IObservableValue tauxImpositionObserveValue = PojoObservables
.observeValue(contribuable, "tauxImposition");
//
DataBindingContext bindingContext = new DataBindingContext();
//
bindingContext.bindValue(nomObserveWidget, nomObserveValue, null, null);
// bindingContext.bindValue(statutObserveWidget, statutObserveValue, null,
// null);
bindingContext.bindValue(avecPersonneChargeObserveWidget,
avecPersonneChargeObserveValue, null, null);
bindingContext.bindValue(salaireObserveWidget, salaireObserveValue,
null, null);
bindingContext.bindValue(categorieDeRevenuObserveWidget,
categorieDeRevenuObserveValue, null, null);
bindingContext.bindValue(tauxImpositionObserveWidget,
tauxImpositionObserveValue, null, null);
//
return bindingContext;
}
public Contribuable getContribuable() {
return contribuable;
}
public void setContribuable(
Contribuable newContribuable) {
setContribuable(newContribuable, true);
}
public void setContribuable(
Contribuable newContribuable,
boolean update) {
contribuable = newContribuable;
if (update) {
if (m_bindingContext != null) {
m_bindingContext.dispose();
m_bindingContext = null;
}
if (contribuable != null) {
m_bindingContext = initDataBindings();
}
}
}
}