1818import org .eclipse .e4 .core .di .annotations .Optional ;
1919import org .eclipse .e4 .ui .di .UIEventTopic ;
2020import org .eclipse .jface .dialogs .MessageDialog ;
21+ import org .eclipse .jface .viewers .ArrayContentProvider ;
22+ import org .eclipse .jface .viewers .LabelProvider ;
23+ import org .eclipse .jface .viewers .StructuredSelection ;
2124import org .eclipse .swt .SWT ;
2225import org .eclipse .swt .events .ModifyEvent ;
2326import org .eclipse .swt .events .ModifyListener ;
2730import org .eclipse .swt .layout .FillLayout ;
2831import org .eclipse .swt .layout .GridLayout ;
2932import org .eclipse .swt .widgets .Button ;
33+ import org .eclipse .swt .widgets .Combo ;
3034import org .eclipse .swt .widgets .Composite ;
3135import org .eclipse .swt .widgets .Control ;
3236import org .eclipse .swt .widgets .Event ;
6165import ch .elexis .core .services .holder .ContextServiceHolder ;
6266import ch .elexis .core .services .holder .StoreToStringServiceHolder ;
6367import ch .elexis .core .ui .UiDesk ;
68+ import ch .elexis .core .ui .contacts .views .util .FilterFieldInputRestrictions ;
6469import ch .elexis .core .ui .dialogs .AnschriftEingabeDialog ;
6570import ch .elexis .core .ui .dialogs .KontaktExtDialog ;
6671import ch .elexis .core .ui .e4 .util .CoreUiUtil ;
7075import ch .elexis .core .ui .util .LabeledInputField .AutoForm ;
7176import ch .elexis .core .ui .util .LabeledInputField .InputData ;
7277import ch .elexis .core .ui .util .LabeledInputField .InputData .Typ ;
78+ import ch .elexis .core .ui .util .LabeledInputField .IStructuredSelectionResolver ;
7379import ch .elexis .core .ui .util .SWTHelper ;
7480import ch .elexis .core .ui .views .IRefreshable ;
7581import ch .elexis .data .Kontakt ;
8591public class KontaktBlatt extends Composite implements IRefreshable , IUnlockable {
8692
8793 private static final String IS_USER = "istAnwender" ; //$NON-NLS-1$
94+ private static final String IS_PATIENT = "istPatient" ; //$NON-NLS-1$
8895
8996 private static final String MOBIL = Messages .Core_Mobilephone ; // $NON-NLS-1$
9097 private static final String VORNAME = Messages .Core_Firstname ; // $NON-NLS-1$
@@ -93,8 +100,8 @@ public class KontaktBlatt extends Composite implements IRefreshable, IUnlockable
93100 private static final String ANSPRECHPERSON = Messages .ContactPerson ; // $NON-NLS-1$
94101 private static final String ZUSATZ = Messages .Core_Additional ; // $NON-NLS-1$
95102 private static final String BEZEICHNUNG = Messages .Core_Description ; // $NON-NLS-1$
96- static final String [] types = { "istOrganisation" , "istLabor" , "istPerson" , "istPatient" , IS_USER , "istMandant" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5 $
97- }; // $NON-NLS-6 $
103+ static final String [] types = { "istOrganisation" , "istLabor" , "istPerson" , IS_PATIENT , IS_USER , "istMandant" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
104+ }; // $NON-NLS-5 $
98105 static final String [] typLabels = { Messages .Core_Organisation , Messages .Core_Laboratory , Messages .Core_Person ,
99106 Messages .Core_Patient , Messages .Core_User , Messages .Core_Mandator };
100107 private final Button [] bTypes = new Button [types .length ];
@@ -103,6 +110,7 @@ public class KontaktBlatt extends Composite implements IRefreshable, IUnlockable
103110 private final ScrolledForm form ;
104111 private final FormToolkit tk ;
105112 AutoForm afDetails ;
113+ private InputData genderCombo ;
106114 Listener mandantListener , checkIfContactExistsListener , changeEmailListener ;
107115
108116 @ Inject
@@ -112,7 +120,23 @@ public class KontaktBlatt extends Composite implements IRefreshable, IUnlockable
112120 new InputData (Messages .Core_Name , Kontakt .FLD_NAME1 , Typ .STRING , null ),
113121 new InputData (Messages .Core_Firstname , Kontakt .FLD_NAME2 , Typ .STRING , null ),
114122 new InputData (Messages .KontaktBlatt_Bez3 , Kontakt .FLD_NAME3 , Typ .STRING , null ),
115- new InputData (Messages .Sex , Person .SEX , Typ .STRING , null ),
123+ new InputData (Messages .Sex , Person .SEX , null , Typ .COMBO_VIEWER , ArrayContentProvider .getInstance (),
124+ new LabelProvider () {
125+ @ Override
126+ public String getText (Object element ) {
127+ return element == null ? StringUtils .EMPTY : element .toString ();
128+ }
129+ }, new IStructuredSelectionResolver () {
130+ @ Override
131+ public StructuredSelection resolveStructuredSelection (String value ) {
132+ if (Person .FEMALE .equalsIgnoreCase (value )) {
133+ return new StructuredSelection (Person .FEMALE );
134+ } else if (Person .MALE .equalsIgnoreCase (value )) {
135+ return new StructuredSelection (Person .MALE );
136+ }
137+ return new StructuredSelection (StringUtils .EMPTY );
138+ }
139+ }, new String [] { StringUtils .EMPTY , Person .MALE , Person .FEMALE }),
116140 new InputData (Messages .KontaktBlatt_LawCode , Person .FLD_TITLE_SUFFIX , Typ .STRING , null ),
117141 new InputData (Messages .Core_Street , Kontakt .FLD_STREET , Typ .STRING , null ),
118142 new InputData (Messages .Core_Postal_code , Kontakt .FLD_ZIP , Typ .STRING , null , 6 ),
@@ -236,6 +260,7 @@ public KontaktBlatt(Composite parent, int style, IViewSite vs) {
236260 bottom .setLayoutData (SWTHelper .getFillGridData (1 , true , 1 , true ));
237261 actKontakt = (Kontakt ) ElexisEventDispatcher .getSelected (Kontakt .class );
238262 afDetails = new AutoForm (bottom , def );
263+ restrictSexField ();
239264 ((ColumnLayout ) afDetails .getLayout ()).minNumColumns = 5 ;
240265 updateFieldsView ();
241266 setToolTipTextListeners ();
@@ -348,6 +373,16 @@ private void updateFieldsView() {
348373 }
349374 }
350375
376+ private void restrictSexField () {
377+ genderCombo = getInputFieldByLabel (Messages .Sex );
378+ if (genderCombo != null && genderCombo .getWidget () != null
379+ && genderCombo .getWidget ().getControl () instanceof Combo ) {
380+ Combo cbSex = (Combo ) genderCombo .getWidget ().getControl ();
381+ FilterFieldInputRestrictions .restrictToValuesIgnoreCase (cbSex , Person .MALE , Person .FEMALE );
382+ FilterFieldInputRestrictions .disableMouseWheel (cbSex );
383+ }
384+ }
385+
351386 /**
352387 * Adds listeners to the {@link LabeledInputField} components to update the
353388 * tooltip text when the content in the input field has been modified.
@@ -442,7 +477,7 @@ public void widgetSelected(SelectionEvent e) {
442477 setOrganisationFieldsVisible (false );
443478 if ("istPerson" .equals (type )) { //$NON-NLS-1$
444479 select ("0" , "0" , "1" , "x" , "x" , "x" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
445- } else if (type .equals ("istPatient" )) { //$NON-NLS-1$
480+ } else if (type .equals (IS_PATIENT )) {
446481 select ("0" , "0" , "1" , "1" , "x" , "x" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
447482 } else if (type .equals (IS_USER )) { // $NON-NLS-1$
448483 select ("0" , "0" , "1" , "x" , "1" , "x" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
@@ -453,6 +488,7 @@ public void widgetSelected(SelectionEvent e) {
453488 } else {
454489 actKontakt .set (type , "0" ); //$NON-NLS-1$
455490 }
491+ updateShortLabelEditable ();
456492 updateFieldsView ();
457493 }
458494
@@ -476,6 +512,33 @@ private void setOrganisationFieldsVisible(boolean visible) {
476512 def [9 ].getWidget ().setVisible (visible );
477513 }
478514
515+ private void updateShortLabelEditable () {
516+ InputData shortLabel = getInputFieldByLabel (Messages .KontaktBlatt_shortLabel );
517+ Button patientButton = getTypeButton (IS_PATIENT );
518+ if (shortLabel != null && shortLabel .getWidget () != null && patientButton != null ) {
519+ boolean isPatient = patientButton .getSelection ();
520+ shortLabel .getWidget ().setEnabled (!isPatient );
521+ }
522+ }
523+
524+ private InputData getInputFieldByLabel (String label ) {
525+ for (InputData d : def ) {
526+ if (label .equals (d .getLabel ())) {
527+ return d ;
528+ }
529+ }
530+ return null ;
531+ }
532+
533+ private Button getTypeButton (String type ) {
534+ for (Button b : bTypes ) {
535+ if (b != null && type .equals (b .getData ())) {
536+ return b ;
537+ }
538+ }
539+ return null ;
540+ }
541+
479542 public void activation (boolean mode ) {
480543 if (ElexisEventDispatcher .getSelected (Kontakt .class ) == null ) {
481544 setEnabled (false );
@@ -502,12 +565,6 @@ private void setKontakt(Kontakt kontakt) {
502565 bTypes [i ].setSelection ((ret [i ] == null ) ? false : StringConstants .ONE .equals (ret [i ]));
503566 bTypes [i ].setEnabled (updateRight );
504567 }
505- if (bTypes [3 ].getSelection () == true ) {
506- // isPatient
507- def [17 ].getWidget ().setEnabled (false );
508- } else {
509- def [17 ].getWidget ().setEnabled (true );
510- }
511568 if (bTypes [0 ].getSelection () == true ) {
512569 // isOrganisation
513570 def [0 ].setLabel (BEZEICHNUNG );
@@ -529,6 +586,9 @@ private void setKontakt(Kontakt kontakt) {
529586 updateFieldsView ();
530587 form .reflow (true );
531588 setUnlocked (LocalLockServiceHolder .get ().isLockedLocal (kontakt ));
589+ if (actKontakt != null ) {
590+ updateShortLabelEditable ();
591+ }
532592
533593 addListener (actKontakt );
534594 }
0 commit comments