Author: dgeraskov
Date: 2012-08-02 10:42:27 -0400 (Thu, 02 Aug 2012)
New Revision: 42842
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/RenameAction.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/DynamicSQLPreviewView.java
Log:
https://issues.jboss.org/browse/JBIDE-8237
Rename console configuration with usual Eclipse rename short cuts (F2 in Windows)
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java 2012-08-02
14:34:25 UTC (rev 42841)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java 2012-08-02
14:42:27 UTC (rev 42842)
@@ -83,6 +83,12 @@
public static String OpenSourceAction_open_source_file;
public static String OpenSourceAction_source_file_for_class_not_found;
public static String RefreshAction_refresh;
+ public static String RenameAction_name;
+ public static String RenameAction_dialog_title;
+ public static String RenameAction_dialog_message;
+ public static String RenameAction_error_title;
+ public static String RenameAction_error_name;
+ public static String RenameAction_existing_name;
//
public static String ExporterDefinition_problem_creating_exporter_class;
public static String ExporterFactory_output_dir_in_does_not_exist;
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2012-08-02
14:34:25 UTC (rev 42841)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2012-08-02
14:42:27 UTC (rev 42842)
@@ -76,6 +76,13 @@
OpenSourceAction_open_source_file=Open Source File
OpenSourceAction_source_file_for_class_not_found=Source file for class
''{0}'' not found.
RefreshAction_refresh=Refresh
+RenameAction_name=Rename;
+RenameAction_dialog_title=Rename Dialog
+RenameAction_dialog_message=Please input a new Console Configuration name
+RenameAction_error_title=Error occurred on Console Configuration rename
+RenameAction_error_name=Error occurred on Console Configuration rename
+RenameAction_error_name=Invalid name, please type in a valid name!
+RenameAction_existing_name=This name already in use, please enter another one
ExporterDefinition_problem_creating_exporter_class=Problem while creating exporter class
{0}
ExporterFactory_output_dir_in_does_not_exist=Output directory ''{0}'' in
{1} does not exist.
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/RenameAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/RenameAction.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/RenameAction.java 2012-08-02
14:42:27 UTC (rev 42842)
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.console.actions;
+
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.actions.SelectionListenerAction;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.utils.LaunchHelper;
+
+/**
+ *
+ * @author Dmitry Geraskov (geraskov(a)gmail.com)
+ *
+ */
+public class RenameAction extends SelectionListenerAction {
+
+ public static final String RENAME_ACTIONID = "actionid.rename"; //$NON-NLS-1$
+
+ private final StructuredViewer viewer;
+ private String imageFilePath = "icons/images/refresh_run.gif"; //$NON-NLS-1$
+
+ public RenameAction(StructuredViewer viewer) {
+ super(HibernateConsoleMessages.RenameAction_name);
+ this.viewer = viewer;
+ setImageDescriptor(HibernateConsolePlugin.getImageDescriptor(imageFilePath ));
+ setId(RENAME_ACTIONID);
+ }
+
+ public void run() {
+ for (Iterator<?> i = getSelectedNonResources().iterator(); i.hasNext();) {
+ Object node = i.next();
+ if (!(node instanceof ConsoleConfiguration)) {
+ continue;
+ }
+ if (renameConsoleConfiuration((ConsoleConfiguration) node)){
+ viewer.refresh(node);
+ }
+ break;
+ }
+ }
+
+ public boolean renameConsoleConfiuration(ConsoleConfiguration config){
+ ILaunchConfiguration launchConfiguration = null;;
+ try {
+ launchConfiguration = LaunchHelper.findHibernateLaunchConfig(config.getName());
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().showError(null,
HibernateConsoleMessages.RenameAction_error_title, e);
+ }
+ return launchConfiguration != null ? renameLaunchConfiguration(launchConfiguration) :
false;
+ }
+
+ public boolean renameLaunchConfiguration(ILaunchConfiguration launchConfiguration){
+ Shell mParentShell = null;
+ IInputValidator inputValidator = new NameValidator();
+ InputDialog d = new InputDialog(
+ mParentShell,
+ HibernateConsoleMessages.RenameAction_dialog_title,
+ HibernateConsoleMessages.RenameAction_dialog_message,
+ launchConfiguration.getName(), inputValidator);
+ if (d.open() == Window.OK ){
+ try {
+ ILaunchConfigurationWorkingCopy wc = launchConfiguration.getWorkingCopy();
+ wc.rename(d.getValue());
+ wc.doSave();
+ return true;
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().showError(mParentShell,
HibernateConsoleMessages.RenameAction_error_title, e);
+ }
+ }
+
+ return false;
+ }
+
+}
+
+class NameValidator implements IInputValidator {
+
+ @Override
+ public String isValid(String newText) {
+ ILaunchManager mgr = DebugPlugin.getDefault().getLaunchManager();
+ try {
+ if (mgr.isExistingLaunchConfigurationName(newText))
+ return HibernateConsoleMessages.RenameAction_existing_name;
+ if (mgr.isValidLaunchConfigurationName(newText))
+ return null;
+ }
+ catch(Exception iae) {
+ HibernateConsolePlugin.getDefault().log(iae);
+ }
+ return HibernateConsoleMessages.RenameAction_error_name;
+ }
+
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java 2012-08-02
14:34:25 UTC (rev 42841)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java 2012-08-02
14:42:27 UTC (rev 42842)
@@ -42,6 +42,7 @@
import org.hibernate.eclipse.console.actions.OpenMappingAction;
import org.hibernate.eclipse.console.actions.OpenSourceAction;
import org.hibernate.eclipse.console.actions.RefreshAction;
+import org.hibernate.eclipse.console.actions.RenameAction;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
@@ -89,6 +90,7 @@
private CriteriaEditorAction criteriaEditorAction;
private SelectionListenerAction openMappingAction;
private SelectionListenerAction openSourceAction;
+ private SelectionListenerAction renameAction;
public ConfigurationsViewActionGroup(IViewPart part, StructuredViewer selectionProvider)
{
@@ -100,10 +102,6 @@
deleteConfigurationAction = new DeleteConfigurationAction(selectionProvider);
selectionProvider.addSelectionChangedListener(deleteConfigurationAction);
- IActionBars actionBars= part.getViewSite().getActionBars();
- actionBars.setGlobalActionHandler(
- ActionFactory.DELETE.getId(),
- deleteConfigurationAction);
refreshAction = new RefreshAction(selectionProvider);
selectionProvider.addSelectionChangedListener(refreshAction);
@@ -134,6 +132,8 @@
openSourceAction = new OpenSourceAction();
selectionProvider.addSelectionChangedListener(openSourceAction);
+ renameAction = new RenameAction(selectionProvider);
+ selectionProvider.addSelectionChangedListener(renameAction);
}
public void dispose() {
@@ -191,6 +191,11 @@
actionBars.getToolBarManager().add(addConfigurationAction);
actionBars.getToolBarManager().add(hqlEditorAction);
actionBars.getToolBarManager().add(criteriaEditorAction);
+
+ actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(),
+ renameAction);
+ actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
+ deleteConfigurationAction);
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/DynamicSQLPreviewView.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/DynamicSQLPreviewView.java 2012-08-02
14:34:25 UTC (rev 42841)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/DynamicSQLPreviewView.java 2012-08-02
14:42:27 UTC (rev 42842)
@@ -1,24 +1,4 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
+
package org.hibernate.eclipse.console.views;
import java.util.Collections;