Search in sources :

Example 1 with EditConsoleConfiguration

use of org.hibernate.eclipse.console.actions.EditConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class HibernatePropertyPage method addSecondSection.

private void addSecondSection(Composite parent) {
    // Label for owner field
    Label ownerLabel = new Label(parent, SWT.NONE);
    ownerLabel.setText(HibernateConsoleMessages.HibernatePropertyPage_default_hibernate_console_config);
    Composite settingsPart = createDefaultComposite(parent, 2);
    selectedConfiguration = new Combo(settingsPart, SWT.DROP_DOWN | SWT.READ_ONLY);
    GridData gd = new GridData();
    gd.widthHint = convertWidthInCharsToPixels(50);
    selectedConfiguration.setLayoutData(gd);
    selectedConfiguration.add(NONE);
    // Populate owner text field
    ConsoleConfiguration[] configurations = LaunchHelper.findFilteredSortedConsoleConfigs();
    for (int i = 0; i < configurations.length; i++) {
        ConsoleConfiguration configuration = configurations[i];
        selectedConfiguration.add(configuration.getName());
    }
    details = new Link(settingsPart, SWT.NONE);
    details.setText(HibernateConsoleMessages.HibernatePropertyPage_details);
    details.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            ConsoleConfiguration config = KnownConfigurations.getInstance().find(selectedConfiguration.getText());
            if (config != null) {
                new EditConsoleConfiguration(config).run();
            }
        }
    });
    selectedConfiguration.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            details.setEnabled(selectedConfiguration.getSelectionIndex() != 0);
        }
    });
    Composite settingsPart2 = createDefaultComposite(parent, 2);
    enableNamingStrategy = new Button(settingsPart2, SWT.CHECK);
    enableNamingStrategy.setText(HibernateConsoleMessages.HibernatePropertyPage_use_naming_strategy);
    enableNamingStrategy.setSelection(initNamingStrategy);
    settings = new Control[] { ownerLabel, selectedConfiguration, details, enableNamingStrategy };
}
Also used : EditConsoleConfiguration(org.hibernate.eclipse.console.actions.EditConsoleConfiguration) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EditConsoleConfiguration(org.hibernate.eclipse.console.actions.EditConsoleConfiguration) Combo(org.eclipse.swt.widgets.Combo) Link(org.eclipse.swt.widgets.Link)

Example 2 with EditConsoleConfiguration

use of org.hibernate.eclipse.console.actions.EditConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class KnownConfigurationsView method makeActions.

/**
 */
private void makeActions() {
    this.actionGroup = new ConfigurationsViewActionGroup(this, viewer);
    this.doubleAction = new Action() {

        public void run() {
            // TODO: make action dependent on having a connected console configuration!
            ISelection selection = viewer.getSelection();
            if (selection == null || selection.isEmpty()) {
                return;
            }
            Object firstElement = ((IStructuredSelection) selection).getFirstElement();
            if (firstElement instanceof ConsoleConfiguration) {
                new EditConsoleConfiguration((ConsoleConfiguration) firstElement).run();
            } else if (firstElement instanceof BaseNode) {
                BaseNode node = (BaseNode) firstElement;
                ConsoleConfiguration consoleConfiguration = node.getConsoleConfiguration();
                if (consoleConfiguration.isSessionFactoryCreated()) {
                    String hql = node.getHQL();
                    // open HQL Editor
                    HibernateConsolePlugin.getDefault().openScratchHQLEditor(consoleConfiguration.getName(), hql);
                /**
                 * /
                 *						// execute query and show results in
                 *						// Hibernate Query result view - commented cause old version
                 *						if(StringHelper.isNotEmpty( hql )) {
                 *							try {
                 *								if (getSite() != null && getSite().getPage() != null) {
                 *									getSite().getPage().showView(QueryPageTabView.ID);
                 *								}
                 *							} catch (PartInitException e) {
                 *								HibernateConsolePlugin.getDefault().logErrorMessage("Can't show QueryPageTabView.", e);	//$NON-NLS-1$
                 *							}
                 *							consoleConfiguration.executeHQLQuery( hql );
                 *						}
                 *						/*
                 */
                }
            } else if (selection instanceof TreeSelection) {
                TreePath[] paths = ((TreeSelection) selection).getPaths();
                TreePath path = paths[0];
                Object last = path.getLastSegment();
                ConsoleConfiguration consoleConfig = (ConsoleConfiguration) (path.getSegment(0));
                if (last instanceof IPersistentClass || (last instanceof IProperty && ((IProperty) last).classIsPropertyClass())) {
                    try {
                        OpenMappingAction.run(consoleConfig, path);
                    } catch (PartInitException e) {
                        // $NON-NLS-1$
                        HibernateConsolePlugin.getDefault().logErrorMessage("Can't find mapping file.", e);
                    } catch (JavaModelException e) {
                        // $NON-NLS-1$
                        HibernateConsolePlugin.getDefault().logErrorMessage("Can't find mapping file.", e);
                    } catch (FileNotFoundException e) {
                        // $NON-NLS-1$
                        HibernateConsolePlugin.getDefault().logErrorMessage("Can't find mapping file.", e);
                    }
                } else {
                    for (int i = 0; i < paths.length; i++) {
                        if (viewer.getExpandedState(paths[i])) {
                            viewer.collapseToLevel(paths[i], 1);
                        } else {
                            viewer.expandToLevel(paths[i], 1);
                        }
                    }
                }
            }
        }
    };
}
Also used : Action(org.eclipse.jface.action.Action) OpenMappingAction(org.hibernate.eclipse.console.actions.OpenMappingAction) JavaModelException(org.eclipse.jdt.core.JavaModelException) EditConsoleConfiguration(org.hibernate.eclipse.console.actions.EditConsoleConfiguration) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) BaseNode(org.hibernate.console.node.BaseNode) FileNotFoundException(java.io.FileNotFoundException) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) TreePath(org.eclipse.jface.viewers.TreePath) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ISelection(org.eclipse.jface.viewers.ISelection) EditConsoleConfiguration(org.hibernate.eclipse.console.actions.EditConsoleConfiguration) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)2 EditConsoleConfiguration (org.hibernate.eclipse.console.actions.EditConsoleConfiguration)2 FileNotFoundException (java.io.FileNotFoundException)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 Action (org.eclipse.jface.action.Action)1 ISelection (org.eclipse.jface.viewers.ISelection)1 TreePath (org.eclipse.jface.viewers.TreePath)1 TreeSelection (org.eclipse.jface.viewers.TreeSelection)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Link (org.eclipse.swt.widgets.Link)1 PartInitException (org.eclipse.ui.PartInitException)1 BaseNode (org.hibernate.console.node.BaseNode)1 OpenMappingAction (org.hibernate.eclipse.console.actions.OpenMappingAction)1 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)1