Search in sources :

Example 6 with WizardNewFileCreationPage

use of org.eclipse.ui.dialogs.WizardNewFileCreationPage in project jbosstools-hibernate by jbosstools.

the class HibernatePropertiesComposite method createSetupAction.

private Runnable createSetupAction() {
    return new Runnable() {

        @Override
        public void run() {
            IPath initialPath = getConfigurationFilePath();
            int defaultChoice = 0;
            if (initialPath != null) {
                defaultChoice = 1;
            }
            MessageDialog dialog = createSetupDialog(HibernateConsoleMessages.ConsoleConfigurationMainTab_setup_configuration_file, HibernateConsoleMessages.ConsoleConfigurationMainTab_do_you_want_to_create_new_cfgxml, defaultChoice);
            int answer = dialog.open();
            IPath cfgFile = null;
            if (answer == 0) {
                // create new
                cfgFile = handleConfigurationFileCreate();
            } else if (answer == 1) {
                // use existing
                cfgFile = handleConfigurationFileBrowse();
            }
            if (cfgFile != null) {
                HibernatePropertiesComposite.this.cfgFile.setText(makeClassPathRelative(cfgFile).toString());
            }
        }

        protected IPath makeClassPathRelative(IPath cfgFile) {
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            IResource res = root.findMember(cfgFile);
            if (res != null && res.exists() && res.getType() == IResource.FILE) {
                IPackageFragmentRoot[] allPackageFragmentRoots = getSourcePackageFragmentRoots();
                for (IPackageFragmentRoot iPackageFragmentRoot : allPackageFragmentRoots) {
                    if (iPackageFragmentRoot.getResource().getFullPath().isPrefixOf(cfgFile)) {
                        cfgFile = cfgFile.removeFirstSegments(iPackageFragmentRoot.getResource().getFullPath().segmentCount());
                        return cfgFile;
                    }
                }
            }
            return res.getLocation();
        }

        private MessageDialog createSetupDialog(String title, String question, int defaultChoice) {
            return new MessageDialog(getShell(), title, null, question, MessageDialog.QUESTION, new String[] { HibernateConsoleMessages.ConsoleConfigurationMainTab_create_new, HibernateConsoleMessages.ConsoleConfigurationMainTab_use_existing, IDialogConstants.CANCEL_LABEL }, defaultChoice);
        }

        private IPath handleConfigurationFileBrowse() {
            IPath[] paths = chooseFileEntries();
            if (paths != null && paths.length == 1) {
                return paths[0];
            }
            return null;
        }

        public IPath[] chooseFileEntries() {
            TypedElementSelectionValidator validator = new TypedElementSelectionValidator(new Class[] { IFile.class }, false);
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            IResource focus = getConfigurationFilePath() != null ? root.findMember(getConfigurationFilePath()) : null;
            ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider() {

                public Object[] getElements(Object element) {
                    IPackageFragmentRoot[] sourcePackageFragmentRoots = getSourcePackageFragmentRoots();
                    IResource[] ress = new IResource[sourcePackageFragmentRoots.length];
                    for (int i = 0; i < sourcePackageFragmentRoots.length; i++) {
                        ress[i] = sourcePackageFragmentRoots[i].getResource();
                    }
                    return ress;
                }
            });
            dialog.setValidator(validator);
            dialog.setAllowMultiple(false);
            dialog.setTitle(HibernateConsoleMessages.ConsoleConfigurationMainTab_select_hibernate_cfg_xml_file);
            dialog.setMessage(HibernateConsoleMessages.ConsoleConfigurationMainTab_choose_file_to_use_as_hibernate_cfg_xml);
            dialog.addFilter(new FileFilter(new String[] { HibernateConsoleMessages.ConsoleConfigurationMainTab_cfg_xml }, null, true, false));
            dialog.setInput(root);
            dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
            dialog.setInitialSelection(focus);
            if (dialog.open() == Window.OK) {
                Object[] elements = dialog.getResult();
                IPath[] res = new IPath[elements.length];
                for (int i = 0; i < res.length; i++) {
                    IResource elem = (IResource) elements[i];
                    res[i] = elem.getFullPath();
                }
                return res;
            }
            return null;
        }

        private IPath handleConfigurationFileCreate() {
            NewConfigurationWizard wizard = new NewConfigurationWizard();
            wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
            IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            WizardDialog wdialog = new WizardDialog(win.getShell(), wizard);
            wdialog.create();
            IWizardPage configPage = wizard.getPage(HibernateConsoleMessages.ConsoleConfigurationMainTab_wizard_page);
            if (configPage != null && configPage instanceof NewConfigurationWizardPage) {
                ((NewConfigurationWizardPage) configPage).setCreateConsoleConfigurationVisible(false);
            }
            // This opens a dialog
            if (wdialog.open() == Window.OK) {
                WizardNewFileCreationPage createdFilePath = ((WizardNewFileCreationPage) wizard.getStartingPage());
                if (createdFilePath != null) {
                    // createNewFile() does not creates new file if it was created by wizard (OK was pressed)
                    return createdFilePath.createNewFile().getFullPath();
                }
            }
            return null;
        }
    };
}
Also used : ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IPath(org.eclipse.core.runtime.IPath) NewConfigurationWizard(org.hibernate.eclipse.console.wizards.NewConfigurationWizard) WizardNewFileCreationPage(org.eclipse.ui.dialogs.WizardNewFileCreationPage) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) TypedElementSelectionValidator(org.eclipse.jdt.internal.ui.wizards.TypedElementSelectionValidator) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) NewConfigurationWizardPage(org.hibernate.eclipse.console.wizards.NewConfigurationWizardPage) IWizardPage(org.eclipse.jface.wizard.IWizardPage) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) FileFilter(org.hibernate.eclipse.console.FileFilter) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IResource(org.eclipse.core.resources.IResource)

Example 7 with WizardNewFileCreationPage

use of org.eclipse.ui.dialogs.WizardNewFileCreationPage in project webtools.sourceediting by eclipse.

the class ExportXMLCatalogWizard method addPages.

public void addPages() {
    exportPage = new WizardNewFileCreationPage("XML Catalog Export", getSelection());
    exportPage.setTitle(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_EXPORT_TITLE);
    exportPage.setDescription(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_EXPORT_DESCRIPTION);
    // $NON-NLS-1$
    exportPage.setFileExtension("xml");
    addPage(exportPage);
}
Also used : WizardNewFileCreationPage(org.eclipse.ui.dialogs.WizardNewFileCreationPage)

Example 8 with WizardNewFileCreationPage

use of org.eclipse.ui.dialogs.WizardNewFileCreationPage in project bndtools by bndtools.

the class BlueprintXmlFileWizard method addPages.

@Override
public void addPages() {
    mainPage = new WizardNewFileCreationPage("newFilePage", selection) {

        @Override
        protected InputStream getInitialContents() {
            return getTemplateContents();
        }
    };
    mainPage.setTitle("New Blueprint XML Descriptor");
    // $NON-NLS-1$
    mainPage.setFileExtension("xml");
    mainPage.setAllowExistingResources(false);
    setupMainPageLocation();
    bndFileSelector = new WizardBndFileSelector();
    addPage(mainPage);
    addPage(bndFileSelector);
}
Also used : InputStream(java.io.InputStream) WizardNewFileCreationPage(org.eclipse.ui.dialogs.WizardNewFileCreationPage)

Example 9 with WizardNewFileCreationPage

use of org.eclipse.ui.dialogs.WizardNewFileCreationPage in project linuxtools by eclipse.

the class NewSuppressionWizard method addPages.

/**
 * Adding the page to the wizard.
 */
@Override
public void addPages() {
    // $NON-NLS-1$
    page = new WizardNewFileCreationPage("newSuppressionPage", selection);
    // $NON-NLS-1$
    page.setTitle(Messages.getString("NewSuppressionWizard.NewWizard_title"));
    // $NON-NLS-1$
    page.setDescription(Messages.getString("NewSuppressionWizard.NewWizard_description"));
    // $NON-NLS-1$
    page.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(ValgrindEditorPlugin.PLUGIN_ID, "icons/newsupp_wiz.png"));
    page.setFileExtension(EXT_SUPP);
    addPage(page);
}
Also used : WizardNewFileCreationPage(org.eclipse.ui.dialogs.WizardNewFileCreationPage)

Example 10 with WizardNewFileCreationPage

use of org.eclipse.ui.dialogs.WizardNewFileCreationPage in project abstools by abstools.

the class NewABSFileWizard method addPages.

@Override
public void addPages() {
    IStructuredSelection projectSelectionFromModulePath = getProjectSelectionFromModulePath(selection);
    mainPage = new WizardNewFileCreationPage(WIZARD_TITLE, projectSelectionFromModulePath);
    mainPage.setTitle(WIZARD_TITLE);
    mainPage.setFileExtension(ABS_FILE_EXTENSION);
    mainPage.setDescription(WIZARD_DESCRIPTION);
    addPage(mainPage);
}
Also used : WizardNewFileCreationPage(org.eclipse.ui.dialogs.WizardNewFileCreationPage) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

WizardNewFileCreationPage (org.eclipse.ui.dialogs.WizardNewFileCreationPage)11 InputStream (java.io.InputStream)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 WizardDialog (org.eclipse.jface.wizard.WizardDialog)3 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 NewConfigurationWizard (org.hibernate.eclipse.console.wizards.NewConfigurationWizard)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IWizardPage (org.eclipse.jface.wizard.IWizardPage)2 NewConfigurationWizardPage (org.hibernate.eclipse.console.wizards.NewConfigurationWizardPage)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 BuiltInTemplate (org.bndtools.core.ui.wizards.shared.BuiltInTemplate)1 TemplateParamsWizardPage (org.bndtools.core.ui.wizards.shared.TemplateParamsWizardPage)1 TemplateSelectionWizardPage (org.bndtools.core.ui.wizards.shared.TemplateSelectionWizardPage)1 StringResource (org.bndtools.templating.StringResource)1 IContainer (org.eclipse.core.resources.IContainer)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1