summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/lifecycle/chooser/ActivityChooser.java
blob: d5f62a0ac64a64f8c54c9c4cfcac15ac1a0f8c68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 * Created on 1 sept. 2003
 *
 * To change the template for this generated file go to Window>Preferences>Java>Code Generation>Code and Comments
 */
package com.c2kernel.lifecycle.chooser;

import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.c2kernel.utils.Language;
import com.c2kernel.utils.Logger;
import com.c2kernel.utils.Resource;

/**
 * @author Developpement
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class ActivityChooser extends JFrame
{
    private LDAPFileChooser mLDAPFileChooserActivity = null;

    private JButton mButtonOK = null;

    private JButton mButtonCancel = null;

    private JPanel mJPanelVertical = null;

    private JPanel mJPanelHorizontal = null;

    private String mMessage = "Choose or modify";

    private WorkflowDialogue mParent = null;

    private JLabel label = null;

    HashMap<?, ?> mhashmap = null;

    public ActivityChooser(String message, String title, Image img, WorkflowDialogue parent, HashMap<?, ?> hashmap)
    {
        super(title);
        mMessage = message;
        img = Resource.findImage("graph/newvertex_large.png").getImage();
        setIconImage(img);
        mParent = parent;
        mhashmap = hashmap;
        initialize();
    }

    private JButton getJButtonOK()
    {
        if (mButtonOK == null)
            mButtonOK = new JButton(Language.translate("OK"));
        return mButtonOK;
    }

    private JButton getJButtonCancel()
    {
        if (mButtonCancel == null)
            mButtonCancel = new JButton(Language.translate("Cancel"));
        return mButtonCancel;
    }

    private LDAPFileChooser getLDAPFileChooserActivity()
    {
        if (mLDAPFileChooserActivity == null)
        {
            try
            {
                mLDAPFileChooserActivity = new LDAPFileChooser(LDAPFileChooser.ACTIVITY_CHOOSER);
                mLDAPFileChooserActivity.setName("LDAPFileChooserRouting");
                mLDAPFileChooserActivity.setEditable(false);
                //mLDAPFileChooserActivity.setBounds(125, 13, 400, 19);
            } catch (Exception mExc)
            {
                Logger.error(mExc);
            }
        }
        return mLDAPFileChooserActivity;
    }

    private void initialize()
    {
        getJButtonOK().addActionListener(new ActionListener()
        {
            @Override
			public void actionPerformed(ActionEvent e)
            {
                Logger.debug(5, "mLDAPFileChooserActivity.getEntryName()" + mLDAPFileChooserActivity.getEntryName());
                setCursor(new Cursor(Cursor.WAIT_CURSOR));
                mParent.loadThisWorkflow(mLDAPFileChooserActivity.getEntryName(), mhashmap);
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                close();
            }
        });
        getJButtonCancel().addActionListener(new ActionListener()
        {
            @Override
			public void actionPerformed(ActionEvent e)
            {
                close();
            }
        });
        //getContentPane().add(getJPanelVertical());
        Container contentPane = getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        contentPane.add(getJPanelVertical());
        contentPane.add(getJPanelHorizontal());
        contentPane.add(Box.createGlue());
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((d.width - getWidth()) / 2, (d.height - getHeight()) / 2);
        setResizable(true);
        pack();
        setSize(new Dimension(getWidth(), getJButtonCancel().getHeight() + getLDAPFileChooserActivity().getHeight() + label.getHeight() + 100));
        setVisible(true);
        setVisible(true);
    }

    private void close()
    {
        mParent = null;
        this.setEnabled(false);
        this.setVisible(false);
    }

    private JPanel getJPanelVertical()
    {
        if (mJPanelVertical == null)
        {
            try
            {
                Logger.debug(8, "Panel button");
                mJPanelVertical = new JPanel();
                mJPanelVertical.setName("JPanelV");
                mJPanelVertical.setLayout(new BoxLayout(mJPanelVertical, BoxLayout.Y_AXIS));
                label = new JLabel(mMessage);
                JPanel labelP = new JPanel();
                labelP.setLayout(new BoxLayout(labelP, BoxLayout.X_AXIS));
                labelP.add(label);
                labelP.add(Box.createGlue());
                mJPanelVertical.add(labelP);
                mJPanelVertical.add(Box.createRigidArea(new Dimension(0, 5)));
                mJPanelVertical.add(getLDAPFileChooserActivity(), getLDAPFileChooserActivity().getName());
                //mJPanelVertical.add(Box.createRigidArea(new Dimension(0,
                // 10)));
                mJPanelVertical.add(Box.createGlue());
                mJPanelVertical.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
                mJPanelVertical.setVisible(true);
            } catch (java.lang.Throwable mExc)
            {
                //handleException(mExc);
            }
        }
        return mJPanelVertical;
    }

    private JPanel getJPanelHorizontal()
    {
        if (mJPanelHorizontal == null)
        {
            try
            {
                Logger.debug(8, "Panel button");
                mJPanelHorizontal = new JPanel();
                mJPanelHorizontal.setName("JPanelH");
                mJPanelHorizontal.setLayout(new BoxLayout(mJPanelHorizontal, BoxLayout.X_AXIS));
                mJPanelHorizontal.add(getJButtonOK(), getJButtonOK().getName());
                mJPanelHorizontal.add(Box.createRigidArea(new Dimension(10, 0)));
                mJPanelHorizontal.add(getJButtonCancel(), getJButtonCancel().getName());
                mJPanelHorizontal.setVisible(true);
            } catch (java.lang.Throwable mExc)
            {
                //handleException(mExc);
            }
        }
        return mJPanelHorizontal;
    }
}