Search in sources :

Example 11 with ExporterFactory

use of org.hibernate.eclipse.console.model.impl.ExporterFactory in project jbosstools-hibernate by jbosstools.

the class ExporterSettingsTab method createPropertySheet.

private Control createPropertySheet(Composite exportersComposite) {
    propertySheet = new PropertySheetPage() {

        public void handleEntrySelection(ISelection selection) {
            super.handleEntrySelection(selection);
            IStructuredSelection iss = (IStructuredSelection) selection;
            IPropertyDescriptor propertyDescriptor = null;
            if (!iss.isEmpty()) {
                MyPropertySheetEntry mse = (MyPropertySheetEntry) iss.getFirstElement();
                propertyDescriptor = mse.getMyDescriptor();
            }
            updateCurrentDescriptor(propertyDescriptor);
        }
    };
    propertySheet.createControl(exportersComposite);
    final PropertySheetEntry propertySheetEntry = new MyPropertySheetEntry();
    propertySheetEntry.setPropertySourceProvider(new IPropertySourceProvider() {

        public IPropertySource getPropertySource(Object object) {
            if (object instanceof ExporterFactory) {
                return new ExporterFactoryPropertySource((ExporterFactory) object) {

                    public void setPropertyValue(Object id, Object value) {
                        super.setPropertyValue(id, value);
                        dialogChanged();
                    }
                };
            } else {
                return null;
            }
        }
    });
    propertySheet.setRootEntry(propertySheetEntry);
    // propertySheetEntry.setValues( new Object[] { this });
    getExporterTable().addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection s = (IStructuredSelection) event.getSelection();
            if (s.isEmpty()) {
                if (add != null)
                    add.setEnabled(false);
                if (remove != null)
                    remove.setEnabled(false);
                if (edit != null)
                    edit.setEnabled(false);
                propertySheetEntry.setValues(new Object[0]);
            } else {
                if (add != null)
                    add.setEnabled(true);
                boolean hasSelection = false;
                if (currentDescriptor != null) {
                    hasSelection = true;
                }
                if (remove != null)
                    remove.setEnabled(hasSelection);
                if (edit != null)
                    edit.setEnabled(hasSelection);
                ExporterFactory ep = (ExporterFactory) s.getFirstElement();
                propertySheetEntry.setValues(new Object[] { ep });
            // if(ep.isEnabled( configuration ))
            }
        }
    });
    Control control = propertySheet.getControl();
    if (control instanceof Tree && !control.isDisposed()) {
        Tree tree = (Tree) control;
        tree.addSelectionListener(new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {
            }

            public void widgetSelected(SelectionEvent e) {
                IPropertyDescriptor propertyDescriptor = null;
                if (e.item != null && e.item.getData() != null) {
                    MyPropertySheetEntry mse = (MyPropertySheetEntry) e.item.getData();
                    propertyDescriptor = mse.getMyDescriptor();
                }
                updateCurrentDescriptor(propertyDescriptor);
            }
        });
    }
    return control;
}
Also used : PropertySheetPage(org.eclipse.ui.views.properties.PropertySheetPage) IPropertySourceProvider(org.eclipse.ui.views.properties.IPropertySourceProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IPropertySource(org.eclipse.ui.views.properties.IPropertySource) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PropertySheetEntry(org.eclipse.ui.views.properties.PropertySheetEntry) Control(org.eclipse.swt.widgets.Control) ExporterFactory(org.hibernate.eclipse.console.model.impl.ExporterFactory) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 12 with ExporterFactory

use of org.hibernate.eclipse.console.model.impl.ExporterFactory in project jbosstools-hibernate by jbosstools.

the class ExporterSettingsTab method createExporterTable.

private void createExporterTable(Composite parent) {
    exporterUpDown = new UpDownListComposite(parent, SWT.NONE, HibernateConsoleMessages.ExporterSettingsTab_exporters, true, new ExporterLabelProvider(), new ExporterContentProvider()) {

        protected Object[] handleAdd(int idx) {
            switch(idx) {
                case 0:
                    Object[] selectExporters = selectExporters(getShell(), HibernateConsoleMessages.ExporterSettingsTab_add_exporter, HibernateConsoleMessages.ExporterSettingsTab_select_exporter_you_want_to_add);
                    for (int i = 0; i < selectExporters.length; i++) {
                        ExporterDefinition exporterDefinition = (ExporterDefinition) selectExporters[i];
                        addDef(exporterDefinition);
                    }
                    // { exporterFactory };
                    return new Object[0];
                case 1:
                    getExporterTable().setAllChecked(true);
                    selectedExporters.clear();
                    observableFactoryList.copyUnderlyingList(selectedExporters);
                    dialogChanged();
                    break;
                case 2:
                    getExporterTable().setAllChecked(false);
                    selectedExporters.clear();
                    dialogChanged();
                    break;
                default:
                    break;
            }
            return null;
        }

        private void addDef(ExporterDefinition expDef) {
            int initialCount = getTable().getItemCount();
            boolean duplicate = false;
            do {
                duplicate = false;
                initialCount++;
                for (ExporterFactory def : observableFactoryList.getList()) {
                    if (def.getId().equals("" + initialCount)) {
                        // $NON-NLS-1$
                        duplicate = true;
                    }
                }
            } while (duplicate);
            // $NON-NLS-1$
            String initialName = "" + initialCount;
            ExporterFactory exporterFactory = new ExporterFactory(expDef, initialName);
            observableFactoryList.add(exporterFactory);
            selectedExporters.add(exporterFactory);
            ((CheckboxTableViewer) getTableViewer()).setChecked(exporterFactory, true);
        }

        @SuppressWarnings("unchecked")
        protected void handleRemove() {
            IStructuredSelection selection = (IStructuredSelection) getTableViewer().getSelection();
            if (selection != null) {
                Iterator<Object> iterator = selection.iterator();
                while (iterator.hasNext()) {
                    Object item = iterator.next();
                    observableFactoryList.remove((ExporterFactory) item);
                    deletedExporterIds.add(((ExporterFactory) item).getId());
                }
                // getTableViewer().setSelection(StructuredSelection.EMPTY);
                listChanged();
            }
        }

        protected void moveSelectionDown() {
            Table table = getTableViewer().getTable();
            int[] indices = table.getSelectionIndices();
            if (indices.length < 1) {
                return;
            }
            int[] newSelection = new int[indices.length];
            int max = table.getItemCount() - 1;
            for (int i = indices.length - 1; i >= 0; i--) {
                int index = indices[i];
                if (index < max) {
                    ExporterFactory data = (ExporterFactory) getTableViewer().getElementAt(index);
                    observableFactoryList.moveTo(index + 1, data);
                    newSelection[i] = index + 1;
                }
            }
            table.setSelection(newSelection);
            listChanged();
        }

        protected void moveSelectionUp() {
            Table table = getTableViewer().getTable();
            int[] indices = table.getSelectionIndices();
            int[] newSelection = new int[indices.length];
            for (int i = 0; i < indices.length; i++) {
                int index = indices[i];
                if (index > 0) {
                    ExporterFactory data = (ExporterFactory) getTableViewer().getElementAt(index);
                    observableFactoryList.moveTo(index - 1, data);
                    newSelection[i] = index - 1;
                }
            }
            table.setSelection(newSelection);
            listChanged();
        }

        protected String[] getAddButtonLabels() {
            return new String[] { HibernateConsoleMessages.ExporterSettingsTab_add, HibernateConsoleMessages.ExporterSettingsTab_select_all, HibernateConsoleMessages.ExporterSettingsTab_deselect_all };
        }

        protected void listChanged() {
            dialogChanged();
        }
    };
    getExporterTable().addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            ExporterFactory factory = (ExporterFactory) event.getElement();
            if (!event.getChecked() && selectedExporters.contains(factory)) {
                selectedExporters.remove(factory);
            } else if (event.getChecked() && !selectedExporters.contains(factory)) {
                selectedExporters.add(factory);
            }
            dialogChanged();
        }
    });
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.verticalAlignment = GridData.FILL;
    gd.horizontalAlignment = GridData.FILL;
    exporterUpDown.setLayoutData(gd);
}
Also used : Table(org.eclipse.swt.widgets.Table) ExporterDefinition(org.hibernate.eclipse.console.model.impl.ExporterDefinition) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) UpDownListComposite(org.hibernate.eclipse.console.wizards.UpDownListComposite) ExporterFactory(org.hibernate.eclipse.console.model.impl.ExporterFactory) Iterator(java.util.Iterator) GridData(org.eclipse.swt.layout.GridData) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 13 with ExporterFactory

use of org.hibernate.eclipse.console.model.impl.ExporterFactory in project jbosstools-hibernate by jbosstools.

the class ExporterSettingsTab method dialogChanged.

private void dialogChanged() {
    // TODO: only active if configname in
    boolean configSelected = true;
    if (!configSelected) {
        updateStatus(HibernateConsoleMessages.ExporterSettingsTab_console_configuration_must_be_specified);
        return;
    }
    if (selectedExporters.size() == 0) {
        updateStatus(HibernateConsoleMessages.ExporterSettingsTab_at_least_one_exporter_option_must_be_selected);
        return;
    }
    String msg = null;
    // Iterator iterator = observableFactoryList.getList().iterator(); // check all exporters
    for (ExporterFactory ef : selectedExporters) {
        // check only selected exporters
        String str = ef.getProperties().get(ExporterFactoryStrings.OUTPUTDIR);
        if (str != null) {
            // $NON-NLS-1$
            msg = PathHelper.checkDirectory(str, HibernateConsoleMessages.ExporterSettingsTab_output_directory_for + " " + ef.getExporterDefinition().getDescription(), true);
            if (msg != null) {
                break;
            }
        }
        str = ef.getProperties().get(ExporterFactoryStrings.TEMPLATE_PATH);
        if (str != null) {
            // $NON-NLS-1$
            msg = PathHelper.checkDirectory(str, HibernateConsoleMessages.ExporterSettingsTab_template_directory_for + " " + ef.getExporterDefinition().getDescription(), true);
            if (msg != null) {
                break;
            }
        }
        str = ef.getProperties().get(ExporterFactoryStrings.QUERY_STRING);
        if (str != null) {
            str = str.trim();
            if (str.length() == 0) {
                msg = NLS.bind(HibernateConsoleMessages.ExporterSettingsTab_query_should_have_not_empty_value, ef.getExporterDefinition().getDescription());
                break;
            }
        }
    }
    updateStatus(msg);
}
Also used : ExporterFactory(org.hibernate.eclipse.console.model.impl.ExporterFactory)

Example 14 with ExporterFactory

use of org.hibernate.eclipse.console.model.impl.ExporterFactory in project jbosstools-hibernate by jbosstools.

the class ConsoleExtension method launchExporters.

public Map<String, File[]> launchExporters(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    Assert.isNotNull(configuration);
    Assert.isNotNull(monitor);
    ExporterAttributes attributes = new ExporterAttributes(configuration);
    List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
    for (Iterator<ExporterFactory> iter = exporterFactories.iterator(); iter.hasNext(); ) {
        ExporterFactory exFactory = iter.next();
        if (!exFactory.isEnabled(configuration)) {
            iter.remove();
        }
    }
    try {
        Set<String> outputDirectories = new HashSet<String>();
        ExporterFactory[] exporters = exporterFactories.toArray(new ExporterFactory[exporterFactories.size()]);
        IArtifactCollector collector = runExporters(attributes, exporters, outputDirectories, monitor);
        for (String path : outputDirectories) {
            CodeGenerationUtils.refreshOutputDir(path);
        }
        // eclipse will format the uptodate files!
        if (collector != null) {
            Map<String, File[]> map = new HashMap<String, File[]>();
            Set<String> types = collector.getFileTypes();
            for (String type : types) {
                File[] files = collector.getFiles(type.toString());
                map.put(type, files);
            }
            return map;
        }
    } catch (Exception e) {
        throw new CoreException(HibernatePlugin.throwableToStatus(e, 666));
    } catch (NoClassDefFoundError e) {
        throw new CoreException(HibernatePlugin.throwableToStatus(new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_received_noclassdeffounderror, e), 666));
    } finally {
        monitor.done();
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ExporterAttributes(org.hibernate.eclipse.launch.ExporterAttributes) CoreException(org.eclipse.core.runtime.CoreException) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) CoreException(org.eclipse.core.runtime.CoreException) ExporterFactory(org.hibernate.eclipse.console.model.impl.ExporterFactory) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) File(java.io.File) HashSet(java.util.HashSet)

Example 15 with ExporterFactory

use of org.hibernate.eclipse.console.model.impl.ExporterFactory in project jbosstools-hibernate by jbosstools.

the class ExporterAttributes method readExporterFactories.

private List<ExporterFactory> readExporterFactories(ILaunchConfiguration configuration) throws CoreException {
    List<String> exporterNames = configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, (List<String>) null);
    if (exporterNames != null) {
        Map<String, ExporterDefinition> exDefinitions = ExtensionManager.findExporterDefinitionsAsMap();
        List<ExporterFactory> factories = new ArrayList<ExporterFactory>();
        for (String exporterId : exporterNames) {
            // $NON-NLS-1$
            String extensionId = configuration.getAttribute(getLaunchAttributePrefix(exporterId) + ".extension_id", (String) null);
            ExporterDefinition expDef = exDefinitions.get(extensionId);
            if (expDef == null) {
                String out = NLS.bind(HibernateConsoleMessages.ExporterAttributes_could_not_locate_exporter_for_in, extensionId, configuration.getName());
                throw new HibernateConsoleRuntimeException(out);
            } else {
                ExporterFactory exporterFactory = new ExporterFactory(expDef, exporterId);
                exporterFactory.isEnabled(configuration);
                factories.add(exporterFactory);
                Map<String, String> props = configuration.getAttribute(getLaunchAttributePrefix(exporterFactory.getId()) + ".properties", // $NON-NLS-1$
                new HashMap<String, String>());
                exporterFactory.setProperties(props);
            }
        }
        return factories;
    } else {
        // fall back to old way of reading if list of exporters does not exist.
        ExporterDefinition[] exDefinitions = ExtensionManager.findExporterDefinitions();
        List<ExporterFactory> factories = new ArrayList<ExporterFactory>();
        for (int i = 0; i < exDefinitions.length; i++) {
            ExporterDefinition expDef = exDefinitions[i];
            ExporterFactory exporterFactory = new ExporterFactory(expDef, expDef.getId());
            exporterFactory.isEnabled(configuration);
            factories.add(exporterFactory);
            Map<String, String> props = configuration.getAttribute(getLaunchAttributePrefix(exporterFactory.getId()) + ".properties", // $NON-NLS-1$
            new HashMap<String, String>());
            exporterFactory.setProperties(props);
        }
        return factories;
    }
}
Also used : ExporterDefinition(org.hibernate.eclipse.console.model.impl.ExporterDefinition) ExporterFactory(org.hibernate.eclipse.console.model.impl.ExporterFactory) ArrayList(java.util.ArrayList) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException)

Aggregations

ExporterFactory (org.hibernate.eclipse.console.model.impl.ExporterFactory)16 ArrayList (java.util.ArrayList)4 CoreException (org.eclipse.core.runtime.CoreException)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 GridData (org.eclipse.swt.layout.GridData)4 UpDownListComposite (org.hibernate.eclipse.console.wizards.UpDownListComposite)4 HashMap (java.util.HashMap)3 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Properties (java.util.Properties)2 IPath (org.eclipse.core.runtime.IPath)2 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)2 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2