Search in sources :

Example 1 with ExporterDefinition

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

the class ExtensionManager method findExporterDefinitionsAsMap.

/**
 * return map of ExporterDefinitions keyed by id
 */
public static Map<String, ExporterDefinition> findExporterDefinitionsAsMap() {
    Map<String, ExporterDefinition> result = new HashMap<String, ExporterDefinition>();
    ExporterDefinition[] findExporterDefinitions = findExporterDefinitions();
    for (int i = 0; i < findExporterDefinitions.length; i++) {
        ExporterDefinition exporterDefinition = findExporterDefinitions[i];
        result.put(exporterDefinition.getId(), exporterDefinition);
    }
    return result;
}
Also used : ExporterDefinition(org.hibernate.eclipse.console.model.impl.ExporterDefinition) HashMap(java.util.HashMap) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 2 with ExporterDefinition

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

the class ExporterSettingsTab method selectExporters.

public static Object[] selectExporters(Shell shell, String title, String description) {
    ILabelProvider labelProvider = new ExporterLabelProvider();
    ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, labelProvider);
    dialog.setTitle(title);
    dialog.setMessage(description);
    dialog.setElements(ExtensionManager.findExporterDefinitionsAsMap().values().toArray());
    dialog.setMultipleSelection(true);
    if (dialog.open() == Window.OK) {
        return dialog.getResult();
    } else {
        return new ExporterDefinition[0];
    }
}
Also used : ExporterDefinition(org.hibernate.eclipse.console.model.impl.ExporterDefinition) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider)

Example 3 with ExporterDefinition

use of org.hibernate.eclipse.console.model.impl.ExporterDefinition 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 4 with ExporterDefinition

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

the class ExtensionManager method findExporterDefinitions.

public static ExporterDefinition[] findExporterDefinitions() {
    List<ExporterDefinition> exporters = new ArrayList<ExporterDefinition>();
    IExtension[] extensions = findExtensions(EXPORTERS_EXTENSION_ID);
    for (int i = 0; i < extensions.length; i++) {
        IConfigurationElement[] elements = extensions[i].getConfigurationElements();
        for (int j = 0; j < elements.length; j++) {
            ExporterDefinition exporter = new ExporterDefinition(elements[j]);
            exporters.add(exporter);
        }
    }
    return exporters.toArray(new ExporterDefinition[exporters.size()]);
}
Also used : ExporterDefinition(org.hibernate.eclipse.console.model.impl.ExporterDefinition) IExtension(org.eclipse.core.runtime.IExtension) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 5 with ExporterDefinition

use of org.hibernate.eclipse.console.model.impl.ExporterDefinition 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

ExporterDefinition (org.hibernate.eclipse.console.model.impl.ExporterDefinition)5 ArrayList (java.util.ArrayList)2 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)2 ExporterFactory (org.hibernate.eclipse.console.model.impl.ExporterFactory)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtension (org.eclipse.core.runtime.IExtension)1 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)1 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 GridData (org.eclipse.swt.layout.GridData)1 Table (org.eclipse.swt.widgets.Table)1 ElementListSelectionDialog (org.eclipse.ui.dialogs.ElementListSelectionDialog)1 HibernateConsoleRuntimeException (org.hibernate.console.HibernateConsoleRuntimeException)1 UpDownListComposite (org.hibernate.eclipse.console.wizards.UpDownListComposite)1