List of usage examples for com.jgoodies.forms.builder ButtonBarBuilder ButtonBarBuilder
public ButtonBarBuilder()
From source file:Save_As_Dicom.java
License:Open Source License
public int setup(String path, ImagePlus ip) { this.ip = ip; this.path = path; anonDialog = new JDialog(); anonDialog.setModal(true);//from w ww .j a v a 2s.co m anonDialog.setLayout(new BorderLayout()); multiSliceExport = new JCheckBox("Export as Multislice"); anonDialog.add(multiSliceExport, BorderLayout.NORTH); anonDialog.add(anonPanel, BorderLayout.CENTER); f = null; if (path != null && path != "") { f = new File(path); silent = true; } String macroOptions = Macro.getOptions(); if (macroOptions != null) { path = Macro.getValue(macroOptions, "filename", null); if (path != null) { f = new File(path); silent = true; } } anonPanel.setRemovePatient(!silent); anonPanel.setRemoveInstitution(!silent); anonPanel.setRemoveManufacturer(!silent); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); cancelButton = new JButton("cancel"); cancelButton.addActionListener(this); bb.addGridded(cancelButton); bb.addRelatedGap(); okButton = new JButton("run"); okButton.addActionListener(this); bb.addGridded(okButton); JPanel buttonPanel = bb.getPanel(); buttonPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); buttonPanel.setOpaque(false); anonDialog.add(buttonPanel, BorderLayout.SOUTH); anonDialog.pack(); return DOES_8G + DOES_16 + DOES_RGB; }
From source file:ca.sqlpower.architect.swingui.action.ExportDDLAction.java
License:Open Source License
public void actionPerformed(ActionEvent e) { final DDLExportPanel ddlPanel = new DDLExportPanel(getSession()); Callable<Boolean> okCall, cancelCall; okCall = new Callable<Boolean>() { public Boolean call() { if (ddlPanel.applyChanges()) { DDLGenerator ddlg = ddlPanel.getGenerator(); ddlg.setTargetSchema(ddlPanel.getSchemaField().getText()); checkErrorsAndGenerateDDL(ddlg); }//from www. j av a 2 s . c o m return Boolean.FALSE; } /** * This method will run the known critics over the target database * that we want to generate a DDL script for and display a dialog * containing errors if any are found. The user will then have the * choice to fix their data model or continue on ignoring the * current set of errors. * <p> * This method will also generate the DDL script using the * generateAndDisplayDDL method. */ private void checkErrorsAndGenerateDDL(final DDLGenerator ddlg) { List<Criticism> criticisms = getSession().getWorkspace().getCriticManager() .criticize(ddlg.getClass()); if (criticisms.isEmpty()) { try { generateAndDisplayDDL(ddlPanel, ddlg); } catch (Exception ex) { ASUtils.showExceptionDialog(getSession(), Messages.getString("ExportDDLAction.errorGeneratingDDLScript"), ex); //$NON-NLS-1$ } } else { //build warning dialog final JDialog warningDialog = new JDialog(frame); JPanel mainPanel = new JPanel(); DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("pref:grow"), mainPanel); builder.setDefaultDialogBorder(); JTextArea explanation = new JTextArea(GENDDL_WARNINGS_EXPLANATION, 8, 60); explanation.setLineWrap(true); explanation.setWrapStyleWord(true); explanation.setEditable(false); explanation.setBackground(mainPanel.getBackground()); explanation.setPreferredSize(new Dimension(0, 0)); builder.append(explanation); builder.appendRow("10dlu"); builder.nextLine(); builder.appendRow("fill:pref:grow"); builder.nextLine(); final CriticismBucket bucket = new CriticismBucket(); bucket.updateCriticismsToMatch(criticisms); JTable errorTable = CriticSwingUtil.createCriticTable(getSession(), bucket); builder.append(new JScrollPane(errorTable)); builder.nextLine(); JButton quickFixButton = new JButton( new AbstractAction(Messages.getString("ExportDDLAction.quickFixAllOption")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { warningDialog.dispose(); for (Criticism criticism : bucket.getCriticisms()) { if (!criticism.getFixes().isEmpty()) { for (CriticFix fix : criticism.getFixes()) { if (fix.getFixType().equals(FixType.QUICK_FIX)) { fix.apply(); //applying the first quick fix each time as there is no //decision what to apply by the user for this case break; } } } } checkErrorsAndGenerateDDL(ddlg); } }); JButton ignoreButton = new JButton( new AbstractAction(Messages.getString("ExportDDLAction.ignoreWarningsOption")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { warningDialog.dispose(); try { generateAndDisplayDDL(ddlPanel, ddlg); } catch (Exception ex) { ASUtils.showExceptionDialog(getSession(), Messages.getString("ExportDDLAction.errorGeneratingDDLScript"), ex); //$NON-NLS-1$ } } }); JButton cancelButton = new JButton( new AbstractAction(Messages.getString("ExportDDLAction.cancelOption")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { //just dispose of the dialog and end this. warningDialog.dispose(); } }); JButton recheckButton = new JButton( new AbstractAction(Messages.getString("ExportDDLAction.recheckOption")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { warningDialog.dispose(); checkErrorsAndGenerateDDL(ddlg); } }); ButtonBarBuilder buttonBar = new ButtonBarBuilder(); buttonBar.addGlue(); buttonBar.addGriddedButtons( new JButton[] { quickFixButton, ignoreButton, cancelButton, recheckButton }); builder.append(buttonBar.getPanel()); warningDialog.add(mainPanel); warningDialog.pack(); TableUtils.fitColumnWidths(errorTable, 10); errorTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); warningDialog.setLocationRelativeTo(frame); warningDialog.setVisible(true); } } /** * This method is used for generating and displaying the DDL script * for the current target database using the given DDL generator. */ private void generateAndDisplayDDL(final DDLExportPanel ddlPanel, DDLGenerator ddlg) throws SQLException, SQLObjectException { ddlg.generateDDLScript(getSession(), getSession().getTargetDatabase().getTables()); SQLDatabase ppdb = new SQLDatabase(ddlPanel.getTargetDB()); SQLScriptDialog ssd = new SQLScriptDialog(d, Messages.getString("ExportDDLAction.previewSQLScriptDialogTitle"), "", false, //$NON-NLS-1$ //$NON-NLS-2$ ddlg, ppdb.getDataSource(), true, getSession()); SPSwingWorker scriptWorker = ssd.getExecuteTask(); ConflictFinderProcess cfp = new ConflictFinderProcess(ssd, ppdb, ddlg, ddlg.getDdlStatements(), getSession()); ConflictResolverProcess crp = new ConflictResolverProcess(ssd, cfp, getSession()); cfp.setNextProcess(crp); crp.setNextProcess(scriptWorker); ssd.setExecuteTask(cfp); ssd.setVisible(true); } }; cancelCall = new Callable<Boolean>() { public Boolean call() { ddlPanel.discardChanges(); return Boolean.TRUE; } }; d = DataEntryPanelBuilder.createDataEntryPanelDialog(ddlPanel, frame, Messages.getString("ExportDDLAction.forwardEngineerSQLDialogTitle"), //$NON-NLS-1$ Messages.getString("ExportDDLAction.okOption"), //$NON-NLS-1$ okCall, cancelCall); d.pack(); d.setLocationRelativeTo(frame); d.setVisible(true); }
From source file:ca.sqlpower.architect.swingui.action.KettleJobAction.java
License:Open Source License
public void actionPerformed(ActionEvent arg0) { logger.debug("Starting to create a Kettle job."); //$NON-NLS-1$ JDialog d;/*from w ww.j a v a 2s.c om*/ final JPanel cp = new JPanel(new BorderLayout(12, 12)); cp.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); final KettleJobPanel kettleETLPanel = new KettleJobPanel(getSession()); Callable<Boolean> okCall, cancelCall; okCall = new Callable<Boolean>() { public Boolean call() { if (!kettleETLPanel.applyChanges()) { return Boolean.FALSE; } KettleRepositoryDirectoryChooser chooser = new UserRepositoryDirectoryChooser(frame); final KettleJob kettleJob = getSession().getKettleJob(); kettleJob.setRepositoryDirectoryChooser(chooser); final JDialog createKettleJobMonitor = new JDialog(frame); createKettleJobMonitor.setTitle(Messages.getString("KettleJobAction.progressDialogTitle")); //$NON-NLS-1$ FormLayout layout = new FormLayout("pref", ""); //$NON-NLS-1$ //$NON-NLS-2$ DefaultFormBuilder builder = new DefaultFormBuilder(layout); builder.setDefaultDialogBorder(); builder.append(Messages.getString("KettleJobAction.progressDialogTitle")); //$NON-NLS-1$ builder.nextLine(); JProgressBar progressBar = new JProgressBar(); builder.append(progressBar); builder.nextLine(); JButton cancel = new JButton(Messages.getString("KettleJobAction.cancelOption")); //$NON-NLS-1$ cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { kettleJob.setCancelled(true); } }); builder.append(cancel); createKettleJobMonitor.add(builder.getPanel()); SPSwingWorker compareWorker = new SPSwingWorker(getSession()) { @Override public void doStuff() throws Exception { createKettleJobMonitor.pack(); createKettleJobMonitor.setLocationRelativeTo(frame); createKettleJobMonitor.setVisible(true); List<SQLTable> tableList = getSession().getPlayPen().getTables(); kettleJob.doExport(tableList, getSession().getTargetDatabase()); } @Override public void cleanup() throws Exception { createKettleJobMonitor.dispose(); if (getDoStuffException() != null) { Throwable ex = getDoStuffException(); if (ex instanceof SQLObjectException) { ASUtils.showExceptionDialog(getSession(), Messages.getString("KettleJobAction.errorReadingTables"), ex); //$NON-NLS-1$ } else if (ex instanceof RuntimeException || ex instanceof IOException || ex instanceof SQLException) { StringBuffer buffer = new StringBuffer(); buffer.append(Messages.getString("KettleJobAction.runtimeError")).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ for (String task : kettleJob.getTasksToDo()) { buffer.append(task).append("\n"); //$NON-NLS-1$ } ASUtils.showExceptionDialog(getSession(), buffer.toString(), ex); } else if (ex instanceof KettleException) { ASUtils.showExceptionDialog(getSession(), Messages.getString("KettleJobAction.kettleExceptionDuringExport") + //$NON-NLS-1$ "\n" + ex.getMessage().trim(), ex); //$NON-NLS-1$ } else { ASUtils.showExceptionDialog(getSession(), Messages.getString("KettleJobAction.unexpectedExceptionDuringExport"), ex); //$NON-NLS-1$ } return; } final JDialog toDoListDialog = new JDialog(frame); toDoListDialog.setTitle(Messages.getString("KettleJobAction.kettleTasksDialogTitle")); //$NON-NLS-1$ FormLayout layout = new FormLayout("10dlu, 2dlu, fill:pref:grow, 12dlu", //$NON-NLS-1$ "pref, fill:pref:grow, pref"); //$NON-NLS-1$ DefaultFormBuilder builder = new DefaultFormBuilder(layout); builder.setDefaultDialogBorder(); ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder(); JTextArea toDoList = new JTextArea(10, 60); toDoList.setEditable(false); List<String> tasksToDo = kettleJob.getTasksToDo(); for (String task : tasksToDo) { toDoList.append(task + "\n"); //$NON-NLS-1$ } JButton close = new JButton(Messages.getString("KettleJobAction.closeOption")); //$NON-NLS-1$ close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { toDoListDialog.dispose(); } }); builder.nextColumn(2); builder.append(Messages.getString("KettleJobAction.kettleTasksInstructions")); //$NON-NLS-1$ builder.nextLine(); builder.append(""); //$NON-NLS-1$ builder.append(new JScrollPane(toDoList)); builder.nextLine(); builder.append(""); //$NON-NLS-1$ buttonBarBuilder.addGlue(); buttonBarBuilder.addGridded(close); buttonBarBuilder.addGlue(); builder.append(buttonBarBuilder.getPanel()); toDoListDialog.add(builder.getPanel()); toDoListDialog.pack(); toDoListDialog.setLocationRelativeTo(frame); toDoListDialog.setVisible(true); } }; new Thread(compareWorker).start(); ProgressWatcher.watchProgress(progressBar, kettleJob); return Boolean.TRUE; } }; cancelCall = new Callable<Boolean>() { public Boolean call() { return Boolean.TRUE; } }; d = DataEntryPanelBuilder.createDataEntryPanelDialog(kettleETLPanel, getSession().getArchitectFrame(), Messages.getString("KettleJobAction.dialogTitle"), Messages.getString("KettleJobAction.okOption"), //$NON-NLS-1$ //$NON-NLS-2$ okCall, cancelCall); d.pack(); d.setLocationRelativeTo(getSession().getArchitectFrame()); d.setVisible(true); }
From source file:ca.sqlpower.architect.swingui.action.VisualMappingReportAction.java
License:Open Source License
public void actionPerformed(ActionEvent e) { try {/*from w ww . j a v a2s .c om*/ if (getSession() == null) return; final MappingReport mr; final List<SQLTable> selectedTables; final List<TablePane> selectedTablePanes = new ArrayList<TablePane>(); for (ContainerPane<?, ?> cp : getPlaypen().getSelectedContainers()) { if (cp instanceof TablePane) { selectedTablePanes.add((TablePane) cp); } } if (selectedTablePanes.size() == 0) { selectedTables = new ArrayList<SQLTable>(getPlaypen().getTables()); } else { if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(frame, Messages.getString("VisualMappingReportAction.viewOnlySelectedTables", //$NON-NLS-1$ String.valueOf(selectedTablePanes.size())), Messages.getString("VisualMappingReportAction.viewOnlySelectedTablesDialogTitle"), //$NON-NLS-1$ JOptionPane.YES_NO_OPTION)) { selectedTables = new ArrayList<SQLTable>(); for (TablePane tp : selectedTablePanes) { selectedTables.add(tp.getModel()); } } else { selectedTables = new ArrayList<SQLTable>(getPlaypen().getTables()); } } mr = new MappingReport(getSession(), selectedTables); final JFrame f = new JFrame(Messages.getString("VisualMappingReportAction.mappingReportDialogTitle")); //$NON-NLS-1$ f.setIconImage(ASUtils.getFrameIconImage()); // You call this a radar?? -- No sir, we call it Mr. Panel. JPanel mrPanel = new JPanel() { protected void paintComponent(java.awt.Graphics g) { super.paintComponent(g); try { mr.drawHighLevelReport((Graphics2D) g, null); } catch (SQLObjectException e1) { logger.error("ArchitectException while generating mapping diagram", e1); //$NON-NLS-1$ ASUtils.showExceptionDialogNoReport( Messages.getString("VisualMappingReportAction.couldNotGenerateMappingDiagram"), e1); //$NON-NLS-1$ } } }; mrPanel.setDoubleBuffered(true); mrPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); mrPanel.setPreferredSize(mr.getRequiredSize()); mrPanel.setOpaque(true); mrPanel.setBackground(Color.WHITE); ButtonBarBuilder buttonBar = new ButtonBarBuilder(); JButton csv = new JButton(new AbstractAction() { public void actionPerformed(ActionEvent e) { FileWriter output = null; try { ExportCSV export = new ExportCSV(selectedTables); File file = null; JFileChooser fileDialog = new JFileChooser( getSession().getRecentMenu().getMostRecentFile()); fileDialog.setSelectedFile(new File("map.csv")); //$NON-NLS-1$ if (fileDialog.showSaveDialog(f) == JFileChooser.APPROVE_OPTION) { file = fileDialog.getSelectedFile(); } else { return; } output = new FileWriter(file); output.write(export.getCSVMapping()); output.flush(); } catch (IOException e1) { throw new RuntimeException(e1); } catch (SQLObjectException e1) { throw new SQLObjectRuntimeException(e1); } finally { if (output != null) { try { output.close(); } catch (IOException e1) { logger.error("IO Error", e1); //$NON-NLS-1$ } } } } }); csv.setText(Messages.getString("VisualMappingReportAction.exportCSVOption")); //$NON-NLS-1$ buttonBar.addGriddedGrowing(csv); JButton close = new JButton(new AbstractAction() { public void actionPerformed(ActionEvent e) { f.dispose(); } }); close.setText(Messages.getString("VisualMappingReportAction.closeOption")); //$NON-NLS-1$ buttonBar.addRelatedGap(); buttonBar.addGriddedGrowing(close); JPanel basePane = new JPanel(new BorderLayout(5, 5)); basePane.add(new JScrollPane(mrPanel), BorderLayout.CENTER); basePane.add(buttonBar.getPanel(), BorderLayout.SOUTH); f.setContentPane(basePane); f.pack(); f.setLocationRelativeTo(frame); f.setVisible(true); } catch (SQLObjectException e1) { throw new SQLObjectRuntimeException(e1); } }
From source file:ca.sqlpower.architect.swingui.CompareDMFrame.java
License:Open Source License
public JComponent mainFrame() { FormLayout layout = new FormLayout( "4dlu,fill:min(150dlu;default):grow, 6dlu, fill:min(150dlu;default):grow, 4dlu", // columns //$NON-NLS-1$ " min(300dlu;default), 6dlu, min(300dlu;default), 6dlu, min(300dlu;default), 3dlu, fill:min(300dlu;default):grow, 3dlu, 20dlu,6dlu,20dlu"); // rows //$NON-NLS-1$ CellConstraints cc = new CellConstraints(); JLabel titleLabel = new JLabel(title); Font oldFont = titleLabel.getFont(); Font titleFont = new Font(oldFont.getName(), oldFont.getStyle(), oldFont.getSize() * 2); titleLabel.setFont(titleFont);//from w w w.j ava2 s . c o m JLabel subTitleLabel = new JLabel(whatTheHeckIsGoingOn); leftOutputArea = new JTextPane(); leftOutputArea.setMargin(new Insets(6, 10, 4, 6)); leftOutputArea.setDocument(sourceOutputText); leftOutputArea.setEditable(false); JPanel comparePanel = new JPanel(new GridLayout(1, 2)); JScrollPane sp = new JScrollPane(comparePanel); int lineHeight = 16; try { FontMetrics fm = leftOutputArea.getFontMetrics(leftOutputArea.getFont()); lineHeight = fm.getHeight() + 2; } catch (Exception e) { lineHeight = 16; } // If the increments are not set, klicking on the up or down arrow of the scrollbar // will scroll the display by one pixel, which is definitely not what the user wants // by setting unitIncrement to the font's height the display will scroll by approx. one line sp.getVerticalScrollBar().setUnitIncrement(lineHeight); // Clicking in the "empty" area of the scrollbar will scroll by 10 lines sp.getVerticalScrollBar().setBlockIncrement(lineHeight * 10); comparePanel.add(leftOutputArea); Action sourceCopy = new sourceCopyAction(sourceOutputText); Action sourceSave = new AbstractAction() { public void actionPerformed(ActionEvent e) { SPSUtils.saveDocument(CompareDMFrame.this, sourceOutputText, (FileExtensionFilter) SPSUtils.TEXT_FILE_FILTER); } }; CloseAction close = new CloseAction(); close.setDialog(this); SPSUtils.makeJDialogCancellable(this, close); ButtonBarBuilder sourcebbBuilder = new ButtonBarBuilder(); JButton copySource = new JButton(sourceCopy); copySource.setText(Messages.getString("CompareDMFrame.copy")); //$NON-NLS-1$ sourcebbBuilder.addGridded(copySource); sourcebbBuilder.addRelatedGap(); sourcebbBuilder.addGlue(); JButton sourceSaveButton = new JButton(sourceSave); sourceSaveButton.setText(Messages.getString("CompareDMFrame.save")); //$NON-NLS-1$ sourcebbBuilder.addGridded(sourceSaveButton); sourcebbBuilder.addRelatedGap(); sourcebbBuilder.addGlue(); ButtonBarBuilder closeBar = new ButtonBarBuilder(); JButton closeButton = new JButton(close); closeButton.setText(Messages.getString("CompareDMFrame.close")); //$NON-NLS-1$ closeBar.addGridded(closeButton); PanelBuilder pb; layout.setColumnGroups(new int[][] { { 2, 4 } }); JPanel p = logger.isDebugEnabled() ? new FormDebugPanel(layout) : new JPanel(layout); pb = new PanelBuilder(layout, p); pb.setDefaultDialogBorder(); rightOutputArea = new JTextPane(); rightOutputArea.setMargin(new Insets(6, 10, 4, 6)); rightOutputArea.setDocument(targetOutputText); rightOutputArea.setEditable(false); comparePanel.add(rightOutputArea); Action targetCopy = new targetCopyAction(targetOutputText); //Sets the target Buttons ButtonBarBuilder targetbbBuilder = new ButtonBarBuilder(); JButton copyTarget = new JButton(targetCopy); copyTarget.setText(Messages.getString("CompareDMFrame.copy")); //$NON-NLS-1$ targetbbBuilder.addGridded(copyTarget); targetbbBuilder.addRelatedGap(); targetbbBuilder.addGlue(); Action targetSaveAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { SPSUtils.saveDocument(CompareDMFrame.this, targetOutputText, (FileExtensionFilter) SPSUtils.TEXT_FILE_FILTER); } }; JButton targetSave = new JButton(targetSaveAction); targetSave.setText(Messages.getString("CompareDMFrame.save")); //$NON-NLS-1$ targetbbBuilder.addGridded(targetSave); targetbbBuilder.addRelatedGap(); targetbbBuilder.addGlue(); getRootPane().setDefaultButton(targetSave); pb.add(titleLabel, cc.xyw(2, 1, 3, "c,c")); //$NON-NLS-1$ pb.add(subTitleLabel, cc.xyw(2, 3, 3, "c,c")); //$NON-NLS-1$ pb.add(new JLabel(Messages.getString("CompareDMFrame.older")), cc.xy(2, 5)); //$NON-NLS-1$ pb.add(new JLabel(Messages.getString("CompareDMFrame.newer")), cc.xy(4, 5)); //$NON-NLS-1$ pb.add(sp, cc.xyw(2, 7, 3)); pb.add(sourcebbBuilder.getPanel(), cc.xy(2, 9, "l,c")); //$NON-NLS-1$ pb.add(targetbbBuilder.getPanel(), cc.xy(4, 9, "r,c")); //$NON-NLS-1$ pb.add(closeBar.getPanel(), cc.xy(4, 11, "r,c")); //$NON-NLS-1$ return pb.getPanel(); }
From source file:ca.sqlpower.architect.swingui.SQLScriptDialog.java
License:Open Source License
private JPanel buildPanel() { FormLayout sqlLayout = new FormLayout("4dlu, min:grow, 4dlu", //columns //$NON-NLS-1$ "pref, 4dlu, pref, 6dlu, fill:300dlu:grow,6dlu, pref, 6dlu, pref"); //rows //$NON-NLS-1$ CellConstraints cc = new CellConstraints(); sqlDoc = new DefaultStyledDocument(); SimpleAttributeSet att = new SimpleAttributeSet(); StyleConstants.setForeground(att, Color.black); for (DDLStatement ddl : statements) { try {/*from w w w . ja v a2s . c om*/ sqlDoc.insertString(sqlDoc.getLength(), ddl.getSQLText() + ddl.getSqlTerminator(), att); } catch (BadLocationException e) { ASUtils.showExceptionDialogNoReport(parent, Messages.getString("SQLScriptDialog.couldNotCreateDocument"), e); //$NON-NLS-1$ logger.error("Could not create document for results", e); //$NON-NLS-1$ } } sqlScriptArea = new JTextPane(); sqlScriptArea.setMargin(new Insets(6, 10, 4, 6)); sqlScriptArea.setDocument(sqlDoc); sqlScriptArea.setEditable(false); sqlScriptArea.setAutoscrolls(true); JScrollPane sp = new JScrollPane(sqlScriptArea); Action copy = new CopyAction(sqlDoc); Action execute = null; execute = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (targetDataSource.get(JDBCDataSource.PL_UID) != null) { new Thread(executeTask).start(); ProgressWatcher.watchProgress(progressBar, executeTask, statusLabel); } else { JOptionPane.showMessageDialog(SQLScriptDialog.this, Messages.getString("SQLScriptDialog.noTargetDb"), //$NON-NLS-1$ Messages.getString("SQLScriptDialog.couldNotExecuteDialogTitle"), //$NON-NLS-1$ JOptionPane.ERROR_MESSAGE); } } }; Action save = new AbstractAction() { public void actionPerformed(ActionEvent e) { logger.info("SQL_FILE_FILTER:" + ((FileExtensionFilter) SPSUtils.SQL_FILE_FILTER).toString()); //$NON-NLS-1$ SPSUtils.saveDocument(parent, sqlDoc, (FileExtensionFilter) SPSUtils.SQL_FILE_FILTER); } }; CloseAction close = new CloseAction(); close.setWhatToClose(this); SPSUtils.makeJDialogCancellable(this, close); ButtonBarBuilder barBuilder = new ButtonBarBuilder(); JButton copyButton = new JButton(copy); copyButton.setText(Messages.getString("SQLScriptDialog.copyOption")); //$NON-NLS-1$ barBuilder.addGridded(copyButton); barBuilder.addRelatedGap(); barBuilder.addGlue(); executeButton = new JButton(execute); executeButton.setText(Messages.getString("SQLScriptDialog.executeOption")); //$NON-NLS-1$ barBuilder.addGridded(executeButton); barBuilder.addRelatedGap(); barBuilder.addGlue(); JButton saveButton = new JButton(save); saveButton.setText(Messages.getString("SQLScriptDialog.saveOption")); //$NON-NLS-1$ barBuilder.addGridded(saveButton); barBuilder.addRelatedGap(); barBuilder.addGlue(); addWindowListener(new CloseWindowAction()); JButton closeButton = new JButton(close); closeButton.setText(Messages.getString("SQLScriptDialog.closeOption")); //$NON-NLS-1$ barBuilder.addGridded(closeButton); getRootPane().setDefaultButton(executeButton); PanelBuilder pb; JPanel panel = logger.isDebugEnabled() ? new FormDebugPanel(sqlLayout) : new JPanel(sqlLayout); pb = new PanelBuilder(sqlLayout, panel); pb.setDefaultDialogBorder(); pb.add(new JLabel(header), cc.xy(2, 1)); // Prevent the user from being able to execute the script if // an invalid target database is selected. if (targetDataSource != null && targetDataSource.get(JDBCDataSource.PL_UID) != null) { pb.add(new JLabel(Messages.getString("SQLScriptDialog.yourTargetDbIs") + targetDataSource.getName()), //$NON-NLS-1$ cc.xy(2, 3)); executeButton.setEnabled(true); } else { pb.add(new JLabel(Messages.getString("SQLScriptDialog.yourTargetDbIsNotConfigured")), cc.xy(2, 3)); executeButton.setEnabled(false); } pb.add(sp, cc.xy(2, 5)); pb.add(barBuilder.getPanel(), cc.xy(2, 7, "c,c")); //$NON-NLS-1$ pb.add(progressBar, cc.xy(2, 9)); return pb.getPanel(); }
From source file:ca.sqlpower.architect.swingui.UserRepositoryDirectoryChooser.java
License:Open Source License
/** * This method allows the selection of the directory. Null is returned if the user cancelled. *///from www .j a v a 2 s. c o m public RepositoryDirectory selectDirectory(Repository repo) { final JDialog chooserDialog = new JDialog(parent); chooserDialog.setTitle(Messages.getString("UserRepositoryDirectoryChooser.selectRepositoryDialogTitle")); //$NON-NLS-1$ FormLayout layout = new FormLayout("10dlu, 2dlu, fill:pref:grow, 12dlu", "pref, fill:pref:grow, pref"); //$NON-NLS-1$ //$NON-NLS-2$ DefaultFormBuilder builder = new DefaultFormBuilder(layout); builder.setDefaultDialogBorder(); builder.nextColumn(2); builder.append(Messages.getString("UserRepositoryDirectoryChooser.chooseDirectory")); //$NON-NLS-1$ builder.nextLine(); DefaultMutableTreeNode root = populateTree(repo.getDirectoryTree()); final JTree tree = new JTree(root); builder.append(""); //$NON-NLS-1$ JScrollPane scrollPane = new JScrollPane(tree); scrollPane.setPreferredSize(new Dimension(200, 350)); builder.append(scrollPane); ButtonBarBuilder buttonBar = new ButtonBarBuilder(); buttonBar.addGlue(); JButton okButton = new JButton(Messages.getString("UserRepositoryDirectoryChooser.okOption")); //$NON-NLS-1$ okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (tree.getSelectionPath() == null) { return; } directory = (RepositoryDirectory) ((DefaultMutableTreeNode) tree.getSelectionPath() .getLastPathComponent()).getUserObject(); chooserDialog.dispose(); } }); buttonBar.addGridded(okButton); buttonBar.addRelatedGap(); JButton cancelButton = new JButton(Messages.getString("UserRepositoryDirectoryChooser.cancelOption")); //$NON-NLS-1$ cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { directory = null; chooserDialog.dispose(); } }); buttonBar.addGridded(cancelButton); builder.nextLine(); builder.append(""); //$NON-NLS-1$ builder.add(buttonBar.getPanel()); chooserDialog.add(builder.getPanel()); chooserDialog.setModal(true); Runnable promptUser = new Runnable() { public void run() { chooserDialog.pack(); chooserDialog.setLocationRelativeTo(parent); chooserDialog.setVisible(true); } }; if (SwingUtilities.isEventDispatchThread()) { promptUser.run(); } else { try { SwingUtilities.invokeAndWait(promptUser); } catch (InterruptedException e) { ASUtils.showExceptionDialogNoReport(parent, "While queing the dialog's pack, setVisible and setLocation, we were interrupted", e); //$NON-NLS-1$ } catch (InvocationTargetException e) { ASUtils.showExceptionDialogNoReport(parent, "While queing the dialog's pack, setVisible and setLocation, an InvocationTargetException was thrown", //$NON-NLS-1$ e); } } return directory; }
From source file:ca.sqlpower.matchmaker.swingui.action.ShowMatchStatisticInfoAction.java
License:Open Source License
public void actionPerformed(ActionEvent e) { if (project == null) { JOptionPane.showMessageDialog(parent, "No project selected", "Error", JOptionPane.ERROR_MESSAGE); return;//from w w w . ja v a 2s . com } MatchStatisticsPanel p = null; try { p = new MatchStatisticsPanel(swingSession, project); } catch (SQLException e1) { MMSUtils.showExceptionDialog(parent, "Could not get match statistics information", e1); return; } if (p == null) { JOptionPane.showMessageDialog(parent, "No match statistics available", "Error", JOptionPane.ERROR_MESSAGE); return; } if (d == null) { d = new JDialog(parent); JPanel panel = new JPanel(new BorderLayout()); final MatchStatisticsPanel p2 = p; JButton deleteAllButton = new JButton(new AbstractAction("Delete All") { public void actionPerformed(ActionEvent e) { // XXX Nothing to do at the moment since no statistics exist. } }); JButton deleteBackwardButton = new JButton(new AbstractAction("Delete Backward") { public void actionPerformed(ActionEvent e) { // XXX Nothing to do at the moment since no statistics exist. } }); Action closeAction = new CommonCloseAction(d); closeAction.putValue(Action.NAME, "Close"); JButton closeButton = new JButton(closeAction); ButtonBarBuilder bbb = new ButtonBarBuilder(); bbb.addRelatedGap(); bbb.addGridded(deleteAllButton); bbb.addRelatedGap(); bbb.addGridded(deleteBackwardButton); bbb.addGlue(); bbb.addGridded(closeButton); bbb.addRelatedGap(); panel.add(bbb.getPanel(), BorderLayout.SOUTH); SPSUtils.makeJDialogCancellable(d, closeAction); panel.add(p, BorderLayout.CENTER); panel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); d.add(panel); d.setTitle("Match Statistics"); d.setPreferredSize(new Dimension(800, 600)); d.pack(); } d.setVisible(true); }
From source file:ca.sqlpower.matchmaker.swingui.address.AddressValidationEntryPanel.java
License:Open Source License
private void buildUI() { DefaultFormBuilder builder = new DefaultFormBuilder( new FormLayout("fill:pref:grow,4dlu,fill:pref", "pref,4dlu,pref,4dlu,fill:pref:grow"), panel); builder.setDefaultDialogBorder();/* ww w .j av a 2s .c o m*/ CellConstraints cc = new CellConstraints(); try { final Address address1; logger.debug("ADDRESS BEFORE PARSING IS : " + addressResult.getOutputAddress()); address1 = Address.parse(addressResult.getOutputAddress().getAddress(), addressResult.getOutputAddress().getMunicipality(), addressResult.getOutputAddress().getProvince(), addressResult.getOutputAddress().getPostalCode(), addressResult.getOutputAddress().getCountry(), addressDatabase); logger.debug("ADDRESS AFTER PARSING IS : " + address1); logger.debug("The output address is not empty."); logger.debug("The non-empty address is: " + address1); this.addressValidator = new AddressValidator(addressDatabase, address1); JButton saveButton = new JButton("Save"); selectedAddressLabel = new AddressLabel(addressResult.getOutputAddress(), null, true, addressValidator.isAddressValid()); selectedAddressLabel.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("currentAddress")) { // update the suggestionList Address address = (Address) evt.getNewValue(); if (address.getType() == null) { //unparsed address, needs to be parsed, This could also be a failed to parse address, won't hurt to try parsing again try { address = Address.parse(address.getAddress(), address.getMunicipality(), address.getProvince(), address.getPostalCode(), address.getCountry(), addressDatabase); } catch (RecognitionException e) { MMSUtils.showExceptionDialog(panel, "There was an error while trying to parse this address", e); } catch (DatabaseException e) { MMSUtils.showExceptionDialog(panel, "There was a database error while trying to parse this address", e); } } addressValidator = new AddressValidator(addressDatabase, address); suggestionList.setModel(new JList(addressValidator.getSuggestions().toArray()).getModel()); selectedAddressLabel.setAddressValid(addressValidator.isAddressValid()); updateProblemDetails(); save(); } } }); selectedAddressLabel.setFont(selectedAddressLabel.getFont() .deriveFont((float) (selectedAddressLabel.getFont().getSize() + 3))); JButton revertButton = new JButton("Revert"); revertButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { logger.debug("Revert Address: " + addressResult.toString()); Address address = Address.parse(addressResult.getInputAddress().getUnparsedAddressLine1(), addressResult.getInputAddress().getMunicipality(), addressResult.getInputAddress().getProvince(), addressResult.getInputAddress().getPostalCode(), addressResult.getInputAddress().getCountry(), addressDatabase); addressResult.setOutputAddress(selectedAddressLabel.getCurrentAddress()); selectedAddressLabel.setCurrentAddress(address); } catch (RecognitionException e1) { e1.printStackTrace(); } catch (DatabaseException e1) { throw new RuntimeException("A database exception occurred while parsing the address" + e1); } } }); saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { save(); } }); // undoButton = new JButton("Undo"); // redoButton = new JButton("Redo"); JLabel suggestLabel = new JLabel("Suggestions:"); suggestLabel.setFont(suggestLabel.getFont().deriveFont(Font.BOLD)); problemsBuilder = new DefaultFormBuilder(new FormLayout("fill:pref:grow")); updateProblemDetails(); suggestionList = new JList(addressValidator.getSuggestions().toArray()); logger.debug("There are " + addressValidator.getSuggestions().size() + " suggestions."); suggestionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); suggestionList.setCellRenderer(new AddressListCellRenderer(address1, false)); suggestionList.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { logger.debug("Mouse Clicked on suggestion list " + ((JList) e.getSource()).getSelectedValue()); final Address selected = (Address) ((JList) e.getSource()).getSelectedValue(); if (selected != null) { //XXX:This does not update the model currently selectedAddressLabel.setCurrentAddress(selected); } } }); JScrollPane scrollList = new JScrollPane(suggestionList); scrollList.setPreferredSize(new Dimension(230, 1000)); ButtonBarBuilder bbb = new ButtonBarBuilder(); bbb.addRelatedGap(); bbb.addGridded(revertButton); bbb.addRelatedGap(); bbb.addGridded(saveButton); bbb.addRelatedGap(); builder.add(bbb.getPanel(), cc.xy(1, 1)); builder.add(suggestLabel, cc.xy(3, 1)); builder.add(selectedAddressLabel, cc.xy(1, 3)); builder.add(problemsBuilder.getPanel(), cc.xy(1, 5)); builder.add(scrollList, cc.xywh(3, 3, 1, 3)); } catch (RecognitionException e1) { MMSUtils.showExceptionDialog(getPanel(), "There was an error while trying to parse this address", e1); } catch (DatabaseException e1) { MMSUtils.showExceptionDialog(getPanel(), "There was a database error while trying to parse this address", e1); } }
From source file:ca.sqlpower.matchmaker.swingui.engine.EngineOutputPanel.java
License:Open Source License
/** * Creates a new engine output panel GUI. * //from w w w.j a v a 2 s . c om * @param owner The frame that should own any dialogs created by this gui. */ public EngineOutputPanel(final JFrame owner) { progressBar = new JProgressBar(); progressBar.setStringPainted(true); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font[] fonts = ge.getAllFonts(); boolean courierNewExist = false; for (int i = 0; i < fonts.length; i++) { if (fonts[i].getFamily().equalsIgnoreCase("Courier New")) { courierNewExist = true; break; } } engineOutputDoc = new DefaultStyledDocument(); outputTextArea = new JTextArea(10, 80); outputTextArea.setDocument(engineOutputDoc); outputTextArea.setEditable(false); outputTextArea.setWrapStyleWord(true); outputTextArea.setLineWrap(true); outputTextArea.setAutoscrolls(true); engineOutputDoc.addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { // not used. } public void insertUpdate(DocumentEvent e) { outputTextArea.setCaretPosition(outputTextArea.getText().length()); } public void removeUpdate(DocumentEvent e) { // not used. } }); if (courierNewExist) { Font oldFont = outputTextArea.getFont(); Font f = new Font("Courier New", oldFont.getStyle(), oldFont.getSize()); outputTextArea.setFont(f); } outputComponent = new JScrollPane(outputTextArea); outputComponent.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); outputComponent.setAutoscrolls(true); outputComponent.setWheelScrollingEnabled(true); ButtonBarBuilder bbBuilder = new ButtonBarBuilder(); bbBuilder.addGlue(); Action clearAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { outputTextArea.setText(""); } }; JButton clearButton = new JButton(clearAction); clearButton.setText("Clear Log"); bbBuilder.addGridded(clearButton); buttonBar = bbBuilder.getPanel(); }