Search in sources :

Example 11 with HierarchyListener

use of java.awt.event.HierarchyListener in project CIM-Identities by epri-dev.

the class Splash method jButton1ActionPerformed.

// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    this.dispose();
    String URL = "jdbc:postgresql://localhost:5432/CIMIdentity";
    String LoginID = "postgres";
    JPasswordField pwd = new JPasswordField(10);
    pwd.addHierarchyListener(new HierarchyListener() {

        public void hierarchyChanged(HierarchyEvent e) {
            final Component c = e.getComponent();
            if (c.isShowing() && (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                Window toplevel = SwingUtilities.getWindowAncestor(c);
                toplevel.addWindowFocusListener(new WindowAdapter() {

                    public void windowGainedFocus(WindowEvent e) {
                        c.requestFocus();
                    }
                });
            }
        }
    });
    int action = JOptionPane.showConfirmDialog(null, pwd, "Enter Password", JOptionPane.OK_CANCEL_OPTION);
    if (action < 0)
        JOptionPane.showMessageDialog(null, "Cancel, X or escape key selected");
    String passw = new String(pwd.getPassword());
    Connection c = null;
    Statement stmt = null;
    Connection cc = null;
    try {
        c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/", LoginID, passw);
        /* Now that we are connected to PostgreSQL, let's create
            the database */
        stmt = c.createStatement();
        String sql = "CREATE DATABASE \"CIMIdentity\";";
        stmt.executeUpdate(sql);
        stmt.close();
        c.close();
        System.out.println("Opened database successfully");
        stmt = null;
        cc = DriverManager.getConnection(URL, LoginID, passw);
        stmt = cc.createStatement();
        String usql = "CREATE EXTENSION pgcrypto; " + "CREATE TABLE public.\"Identity\" " + "(id_pkey uuid NOT NULL DEFAULT gen_random_uuid(), " + " entry serial NOT NULL, " + "CONSTRAINT id_pkey PRIMARY KEY (id_pkey) )" + " WITH ( OIDS = FALSE); " + " ALTER TABLE public.\"Identity\"" + " OWNER to postgres;" + "CREATE TABLE public.\"IdentifiedObject\"" + "( io_pkey uuid NOT NULL, " + "CONSTRAINT io_pkey PRIMARY KEY (io_pkey), " + "CONSTRAINT io_idkey FOREIGN KEY (io_pkey) " + "REFERENCES public.\"Identity\" (id_pkey) MATCH SIMPLE " + "ON UPDATE CASCADE ON DELETE CASCADE )" + "WITH ( OIDS = FALSE);" + "ALTER TABLE public.\"IdentifiedObject\"" + "OWNER TO postgres;" + "CREATE TABLE public.\"Name\"" + "( n_pkey uuid NOT NULL, " + "n_name character varying NOT NULL, " + "CONSTRAINT n_pkey PRIMARY KEY (n_pkey), " + "CONSTRAINT n_idkey FOREIGN KEY (n_pkey)" + " REFERENCES public.\"Identity\" (id_pkey) MATCH SIMPLE" + " ON UPDATE CASCADE ON DELETE CASCADE" + ") WITH ( OIDS = FALSE );" + " ALTER TABLE public.\"Name\" OWNER TO postgres;" + " CREATE TABLE public.\"NameType\" " + " ( nt_pkey uuid NOT NULL, " + " nt_description character varying NOT NULL, " + " nt_name character varying NOT NULL, " + " CONSTRAINT nt_pkey PRIMARY KEY (nt_pkey), " + " CONSTRAINT nt_nkey FOREIGN KEY (nt_pkey) " + " REFERENCES public.\"Name\" (n_pkey) MATCH SIMPLE " + " ON UPDATE CASCADE ON DELETE CASCADE ) " + " WITH ( OIDS = FALSE ); " + " ALTER TABLE public.\"NameType\" OWNER TO postgres; " + " CREATE TABLE public.\"NameTypeAuthority\"" + " ( nta_pkey uuid NOT NULL, " + " nta_name character varying, " + " nta_description character varying NOT NULL, " + " CONSTRAINT nta_pkey PRIMARY KEY (nta_pkey), " + " CONSTRAINT nta_ntkey FOREIGN KEY (nta_pkey) " + " REFERENCES public.\"NameType\" (nt_pkey) MATCH SIMPLE " + " ON UPDATE CASCADE ON DELETE CASCADE )" + " WITH ( OIDS = FALSE ); " + " ALTER TABLE public.\"NameTypeAuthority\" " + " OWNER TO postgres;";
        stmt.executeUpdate(usql);
        stmt.close();
        c.close();
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.getClass().getName() + ": " + e.getMessage());
        System.exit(0);
    }
    JOptionPane.showMessageDialog(null, "Table created successfully!");
}
Also used : Window(java.awt.Window) JPasswordField(javax.swing.JPasswordField) HierarchyEvent(java.awt.event.HierarchyEvent) Statement(java.sql.Statement) WindowEvent(java.awt.event.WindowEvent) Connection(java.sql.Connection) WindowAdapter(java.awt.event.WindowAdapter) Component(java.awt.Component) HierarchyListener(java.awt.event.HierarchyListener)

Example 12 with HierarchyListener

use of java.awt.event.HierarchyListener in project cuba by cuba-platform.

the class DesktopFrame method detachFrame.

@Override
public void detachFrame(String caption) {
    if (isDetached()) {
        throw new RuntimeException("Frame already detached");
    }
    final java.awt.Container parent = impl.getParent();
    detachedFrame = new DetachedFrame(caption, parent);
    for (int i = 0; i < parent.getComponentCount(); i++) {
        if (impl == parent.getComponent(i)) {
            componentPosition = i;
            break;
        }
    }
    hierarchyListener = new HierarchyListener() {

        @Override
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) == HierarchyEvent.DISPLAYABILITY_CHANGED && !parent.isDisplayable()) {
                parent.removeHierarchyListener(this);
                attachFrame();
            }
        }
    };
    detachedFrame.setLocationRelativeTo(DesktopComponentsHelper.getTopLevelFrame(impl));
    detachedFrame.setSize(impl.getSize());
    detachedFrame.add(impl);
    detachedFrame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            parent.removeHierarchyListener(hierarchyListener);
            attachFrame();
        }
    });
    parent.revalidate();
    parent.repaint();
    parent.addHierarchyListener(hierarchyListener);
    detachedFrame.setVisible(true);
    detached = true;
    for (DetachListener listener : detachListeners) {
        listener.frameDetached(this);
    }
}
Also used : HierarchyEvent(java.awt.event.HierarchyEvent) WindowEvent(java.awt.event.WindowEvent) DetachedFrame(com.haulmont.cuba.desktop.DetachedFrame) WindowAdapter(java.awt.event.WindowAdapter) HierarchyListener(java.awt.event.HierarchyListener)

Example 13 with HierarchyListener

use of java.awt.event.HierarchyListener in project omegat by omegat-org.

the class SecureStoreController method initGui.

private void initGui() {
    panel = new SecureStorePanel();
    panel.resetPasswordButton.addActionListener(e -> resetMasterPassword());
    panel.addHierarchyListener(new HierarchyListener() {

        @Override
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                updateMasterPasswordStatus();
            }
        }
    });
}
Also used : HierarchyEvent(java.awt.event.HierarchyEvent) HierarchyListener(java.awt.event.HierarchyListener)

Example 14 with HierarchyListener

use of java.awt.event.HierarchyListener in project netbeans-mmd-plugin by raydac.

the class UiUtils method makeOwningDialogResizable.

public static void makeOwningDialogResizable(@Nonnull final Component component, @Nonnull @MustNotContainNull final Runnable... extraActions) {
    final HierarchyListener listener = new HierarchyListener() {

        @Override
        public void hierarchyChanged(@Nonnull final HierarchyEvent e) {
            final Window window = SwingUtilities.getWindowAncestor(component);
            if (window instanceof Dialog) {
                final Dialog dialog = (Dialog) window;
                if (!dialog.isResizable()) {
                    dialog.setResizable(true);
                    component.removeHierarchyListener(this);
                    for (final Runnable r : extraActions) {
                        r.run();
                    }
                }
            }
        }
    };
    component.addHierarchyListener(listener);
}
Also used : Window(java.awt.Window) JWindow(javax.swing.JWindow) Nonnull(javax.annotation.Nonnull) HierarchyEvent(java.awt.event.HierarchyEvent) JDialog(javax.swing.JDialog) Dialog(java.awt.Dialog) HierarchyListener(java.awt.event.HierarchyListener)

Example 15 with HierarchyListener

use of java.awt.event.HierarchyListener in project mylizzie by aerisnju.

the class Lizzie method setFileChooserAutoFocusOnTextField.

private static void setFileChooserAutoFocusOnTextField(JFileChooser chooser) {
    chooser.addHierarchyListener(new HierarchyListener() {

        public void hierarchyChanged(HierarchyEvent he) {
            grabFocusForTextField(chooser.getComponents());
        }

        // Loop to find the JTextField, the first
        // JTextField in JFileChooser
        // Even if you setAccessory which contains a JTextField
        // or which is JTextField itself, it will not get focus
        private void grabFocusForTextField(Component[] components) {
            for (Component component : components) {
                if (component instanceof JTextField) {
                    JTextField textField = (JTextField) component;
                    textField.grabFocus();
                    break;
                } else if (component instanceof JPanel) {
                    JPanel panel = (JPanel) component;
                    grabFocusForTextField(panel.getComponents());
                }
            }
        }
    });
}
Also used : HierarchyEvent(java.awt.event.HierarchyEvent) HierarchyListener(java.awt.event.HierarchyListener)

Aggregations

HierarchyListener (java.awt.event.HierarchyListener)20 HierarchyEvent (java.awt.event.HierarchyEvent)19 Window (java.awt.Window)5 WindowEvent (java.awt.event.WindowEvent)5 Component (java.awt.Component)4 WindowAdapter (java.awt.event.WindowAdapter)4 DetachedFrame (com.haulmont.cuba.desktop.DetachedFrame)2 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 JComboBox (javax.swing.JComboBox)2 JDialog (javax.swing.JDialog)2 RenderResult (com.android.tools.idea.rendering.RenderResult)1 ButtonTabComponent (com.haulmont.cuba.desktop.sys.ButtonTabComponent)1 DisabledGlassPane (com.haulmont.cuba.desktop.sys.DisabledGlassPane)1 Editor (com.intellij.openapi.editor.Editor)1 com.intellij.openapi.fileEditor (com.intellij.openapi.fileEditor)1 PsiFile (com.intellij.psi.PsiFile)1 Update (com.intellij.util.ui.update.Update)1 java.awt (java.awt)1 Dialog (java.awt.Dialog)1