Révision 3078 tmp/org.txm.analec.rcp/src/visuAnalec/PanneauChamps.java

PanneauChamps.java (revision 3078)
22 22
 * @author Bernard, cplancq
23 23
 */
24 24
public class PanneauChamps extends JPanel {
25
  ArrayList<GChamp> champs = new ArrayList<GChamp>();
26
  private Vue vue;
27
  private Element element = null;
28
  private Class<? extends Element> classe = null;
29
  private String type = null;
30
  private JPanel cadre;
31
  public PanneauChamps(PanneauEditeur pEdit, Vue vue) {
32
    super(new BorderLayout());
33
    setBorder(new TitledBorder("Champs"));
34
    cadre = new JPanel(new GridLayout(0, 1));
35
    JScrollPane scroll = new JScrollPane(cadre);
36
    add(scroll, BorderLayout.CENTER);
37
    this.vue = vue;
38
  }
39
  void reafficher() {
40
    if (element == null) return;
41
    type = null;
42
    afficher(element);
43
  }
44
  void afficher(Element elt) {
45
    this.element = elt;
46
    if (elt.getClass() != classe || !elt.getType().equals(type)) {
47
      type = elt.getType();
48
      classe = elt.getClass();
49
      afficherTouslesChamps();
50
    }
51
    ((TitledBorder) getBorder()).setTitle("Champs " + GVisu.getNomDeLaClasse(elt) + " :  \"" +
52
            vue.getIdElement(elt) + "\"");
53
    for (GChamp gc : champs) {
54
      gc.afficher(elt);
55
    }
56
    revalidate();
57
    repaint();
58
  }
59
  void effacer() {
60
    cadre.removeAll();
61
    type = null;
62
    element = null;
63
    ((TitledBorder) getBorder()).setTitle("Champs");
64
    revalidate();
65
    repaint();
66
  }
67
  private void afficherTouslesChamps() {
68
    cadre.removeAll();
69
    champs.clear();
70

  
71
    int niveau = 0;
72
    for (String[] champsniveau : vue.getChamps(classe, type)) {
73
      JPanel panneauniveau = new JPanel();
74
 //     panneauniveau.setBorder(new TitledBorder("Niveau " + ++niveau));
75
      for (String champ : champsniveau) {
76
        GChamp gc = new GChamp(vue, classe, type, champ);
77
        champs.add(gc);
78
        panneauniveau.add(gc);
79
      }
80
      cadre.add(panneauniveau);
81
    }
82
  }
83

  
84
  private static class GChamp extends JPanel implements ActionListener {
85
    JComboBox afficheValeurChamp;
86
    Vue vue;
87
    Class<? extends Element> classe;
88
    String type;
89
    String champ;
90
    Element element = null;
91
    GChamp(Vue vue, Class<? extends Element> classe, String type, String champ) {
92
      super();
93
      this.vue = vue;
94
      this.classe = classe;
95
      this.type = type;
96
      this.champ = champ;
97
      Box groupe = Box.createVerticalBox();
98
      Box titre = Box.createHorizontalBox();
99
      titre.add(Box.createHorizontalGlue());
100
      JLabel label = new JLabel(champ, JLabel.CENTER);
101
 //     label.setPreferredSize(new Dimension(50, 10));
102
      titre.add(label);
103
      titre.add(Box.createHorizontalGlue());
104
      groupe.add(titre);
105
      groupe.add(Box.createVerticalStrut(2));
106
      afficheValeurChamp = new JComboBox(vue.getValeursChamp(classe, type, champ));
107
      /*
108
      * CP: JComboBox avec autocompletion. Dépend de la lib glazedlists
109
      * (http://www.glazedlists.com/), (https://github.com/glazedlists/glazedlists)
110
      */
111
      AutoCompleteSupport support = AutoCompleteSupport.install(afficheValeurChamp, GlazedLists.eventListOf(vue.getValeursChamp(classe, type, champ)));
112
      support.setCorrectsCase(false);
113
      afficheValeurChamp.setEditable(vue.isChampModifiable(classe, type, champ));
114
      afficheValeurChamp.addActionListener(this);
115
      groupe.add(afficheValeurChamp);
116
      add(groupe);
117
    }
118
    void afficher(Element elt) {
119
      this.element = elt;
120
      afficheValeurChamp.removeActionListener(this);
121
      String val = vue.getValeurChamp(elt, champ);
122
      if (val.isEmpty()) afficheValeurChamp.setSelectedIndex(-1);
123
      else afficheValeurChamp.setSelectedItem(val);
124
      afficheValeurChamp.addActionListener(this);
125
    }
126
    public void actionPerformed(ActionEvent evt) {
127
      try {
128
        if (!afficheValeurChamp.isEditable()) {
129
          JOptionPane.showMessageDialog(getTopLevelAncestor(), "Champ non modifiable pour ce type d'éléments",
130
                  "Modification impossible", JOptionPane.ERROR_MESSAGE);
131
          afficher(element);
132
          return;
133
        }
134
        String newval = ((String) afficheValeurChamp.getSelectedItem());
135
        if (newval == null) newval = "";
136
        else newval = newval.trim();
137
        
138
        if (!vue.setValeurChamp(element, champ, newval)) {
139
          JOptionPane.showMessageDialog(getTopLevelAncestor(), "Champ non défini pour cet élément",
140
                  "Saisie de valeur de champ impossible", JOptionPane.ERROR_MESSAGE);
141
          afficher(element);
142
        }
143
      } catch (Throwable ex) {
144
        GMessages.erreurFatale(ex);
145
      }
146
    }
147
  }
25
	
26
	ArrayList<GChamp> champs = new ArrayList<>();
27
	
28
	private Vue vue;
29
	
30
	private Element element = null;
31
	
32
	private Class<? extends Element> classe = null;
33
	
34
	private String type = null;
35
	
36
	private JPanel cadre;
37
	
38
	public PanneauChamps(PanneauEditeur pEdit, Vue vue) {
39
		super(new BorderLayout());
40
		setBorder(new TitledBorder("Champs"));
41
		cadre = new JPanel(new GridLayout(0, 1));
42
		JScrollPane scroll = new JScrollPane(cadre);
43
		add(scroll, BorderLayout.CENTER);
44
		this.vue = vue;
45
	}
46
	
47
	void reafficher() {
48
		if (element == null) return;
49
		type = null;
50
		afficher(element);
51
	}
52
	
53
	void afficher(Element elt) {
54
		this.element = elt;
55
		if (elt.getClass() != classe || !elt.getType().equals(type)) {
56
			type = elt.getType();
57
			classe = elt.getClass();
58
			afficherTouslesChamps();
59
		}
60
		((TitledBorder) getBorder()).setTitle("Champs " + GVisu.getNomDeLaClasse(elt) + " :  \"" +
61
				vue.getIdElement(elt) + "\"");
62
		for (GChamp gc : champs) {
63
			gc.afficher(elt);
64
		}
65
		revalidate();
66
		repaint();
67
	}
68
	
69
	void effacer() {
70
		cadre.removeAll();
71
		type = null;
72
		element = null;
73
		((TitledBorder) getBorder()).setTitle("Champs");
74
		revalidate();
75
		repaint();
76
	}
77
	
78
	private void afficherTouslesChamps() {
79
		cadre.removeAll();
80
		champs.clear();
81
		
82
		int niveau = 0;
83
		for (String[] champsniveau : vue.getChamps(classe, type)) {
84
			JPanel panneauniveau = new JPanel();
85
			// panneauniveau.setBorder(new TitledBorder("Niveau " + ++niveau));
86
			for (String champ : champsniveau) {
87
				GChamp gc = new GChamp(vue, classe, type, champ);
88
				champs.add(gc);
89
				panneauniveau.add(gc);
90
			}
91
			cadre.add(panneauniveau);
92
		}
93
	}
94
	
95
	private static class GChamp extends JPanel implements ActionListener {
96
		
97
		JComboBox afficheValeurChamp;
98
		
99
		Vue vue;
100
		
101
		Class<? extends Element> classe;
102
		
103
		String type;
104
		
105
		String champ;
106
		
107
		Element element = null;
108
		
109
		GChamp(Vue vue, Class<? extends Element> classe, String type, String champ) {
110
			super();
111
			this.vue = vue;
112
			this.classe = classe;
113
			this.type = type;
114
			this.champ = champ;
115
			Box groupe = Box.createVerticalBox();
116
			Box titre = Box.createHorizontalBox();
117
			titre.add(Box.createHorizontalGlue());
118
			JLabel label = new JLabel(champ, JLabel.CENTER);
119
			// label.setPreferredSize(new Dimension(50, 10));
120
			titre.add(label);
121
			titre.add(Box.createHorizontalGlue());
122
			groupe.add(titre);
123
			groupe.add(Box.createVerticalStrut(2));
124
			afficheValeurChamp = new JComboBox(vue.getValeursChamp(classe, type, champ));
125
			/*
126
			 * CP: JComboBox avec autocompletion. Dépend de la lib glazedlists
127
			 * (http://www.glazedlists.com/), (https://github.com/glazedlists/glazedlists)
128
			 */
129
			AutoCompleteSupport<String> support = AutoCompleteSupport.install(afficheValeurChamp, GlazedLists.eventListOf(vue.getValeursChamp(classe, type, champ)));
130
			support.setCorrectsCase(false);
131
			afficheValeurChamp.setEditable(vue.isChampModifiable(classe, type, champ));
132
			afficheValeurChamp.addActionListener(this);
133
			groupe.add(afficheValeurChamp);
134
			add(groupe);
135
		}
136
		
137
		void afficher(Element elt) {
138
			this.element = elt;
139
			afficheValeurChamp.removeActionListener(this);
140
			String val = vue.getValeurChamp(elt, champ);
141
			if (val.isEmpty()) afficheValeurChamp.setSelectedIndex(-1);
142
			else afficheValeurChamp.setSelectedItem(val);
143
			afficheValeurChamp.addActionListener(this);
144
		}
145
		
146
		@Override
147
		public void actionPerformed(ActionEvent evt) {
148
			try {
149
				if (!afficheValeurChamp.isEditable()) {
150
					JOptionPane.showMessageDialog(getTopLevelAncestor(), "Champ non modifiable pour ce type d'éléments",
151
							"Modification impossible", JOptionPane.ERROR_MESSAGE);
152
					afficher(element);
153
					return;
154
				}
155
				String newval = ((String) afficheValeurChamp.getSelectedItem());
156
				if (newval == null) newval = "";
157
				else newval = newval.trim();
158
				
159
				if (!vue.setValeurChamp(element, champ, newval)) {
160
					JOptionPane.showMessageDialog(getTopLevelAncestor(), "Champ non défini pour cet élément",
161
							"Saisie de valeur de champ impossible", JOptionPane.ERROR_MESSAGE);
162
					afficher(element);
163
				}
164
			}
165
			catch (Throwable ex) {
166
				GMessages.erreurFatale(ex);
167
			}
168
		}
169
	}
148 170
}

Formats disponibles : Unified diff