Remove old legacy project and project conversion code
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension
|
||||
point="org.eclipse.ui.startup">
|
||||
<startup
|
||||
class="org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion.LegacySTSChecker">
|
||||
</startup>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.popupMenus">
|
||||
<!-- Deal with legacy projects -->
|
||||
<objectContribution
|
||||
objectClass="org.eclipse.core.resources.IProject"
|
||||
adaptable="true"
|
||||
id="iprojectcontributions">
|
||||
<visibility>
|
||||
<or>
|
||||
<objectState name="nature" value="com.springsource.sts.grails.core.nature"/>
|
||||
<objectState name="nature" value="com.springsource.sts.gradle.core.nature"/>
|
||||
</or>
|
||||
</visibility>
|
||||
<action
|
||||
label="Migrate legacy STS projects..."
|
||||
class="org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion.ConvertLegacyProjectAction"
|
||||
menubarPath="org.eclipse.ui.projectConfigure/additions"
|
||||
id="convertLegacy">
|
||||
</action>
|
||||
</objectContribution>
|
||||
</extension>
|
||||
</plugin>
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pivotal Software, Inc.
|
||||
* Copyright (c) 2012, 2023 Pivotal Software, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -14,7 +14,6 @@ import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion.LegacyProjectListener;
|
||||
|
||||
/**
|
||||
* @author Nieraj Singh
|
||||
@@ -50,7 +49,6 @@ public class FrameworkUIActivator extends AbstractUIPlugin {
|
||||
*/
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
plugin = null;
|
||||
LegacyProjectListener.LISTENER.dispose();
|
||||
super.stop(context);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pivotal Software, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal Software, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion;
|
||||
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IObjectActionDelegate;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
|
||||
/**
|
||||
* Convert all legacy maven projects in the workspace
|
||||
*
|
||||
* @author Andrew Eisenberg
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public class ConvertLegacyProjectAction implements IObjectActionDelegate {
|
||||
|
||||
public void run(IAction action) {
|
||||
LegacyProjectsJob job = new LegacyProjectsJob(true);
|
||||
job.schedule();
|
||||
}
|
||||
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
// we don't care about the actual selection
|
||||
}
|
||||
|
||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pivotal Software, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal Software, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceChangeEvent;
|
||||
import org.eclipse.core.resources.IResourceChangeListener;
|
||||
import org.eclipse.core.resources.IResourceDelta;
|
||||
import org.eclipse.core.resources.IResourceDeltaVisitor;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.springsource.ide.eclipse.commons.frameworks.core.FrameworkCoreActivator;
|
||||
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.IConversionConstants;
|
||||
|
||||
/**
|
||||
* Listens for legacy STS projects appearing in the workspace
|
||||
*
|
||||
* @author Andrew Eisenberg
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class LegacyProjectListener implements IResourceChangeListener, IConversionConstants {
|
||||
|
||||
public static final LegacyProjectListener LISTENER = new LegacyProjectListener();
|
||||
|
||||
private boolean shouldPerformCheck() {
|
||||
return FrameworkCoreActivator.getDefault().getPreferenceStore().getBoolean(AUTO_CHECK_FOR_LEGACY_STS_PROJECTS);
|
||||
}
|
||||
|
||||
public void resourceChanged(IResourceChangeEvent event) {
|
||||
if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
|
||||
List<IProject> projects = getProjects(event.getDelta());
|
||||
if (!projects.isEmpty() && shouldPerformCheck()) {
|
||||
LegacyProjectsJob job = new LegacyProjectsJob(projects, false);
|
||||
job.schedule();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<IProject> getProjects(IResourceDelta delta) {
|
||||
final List<IProject> projects = new ArrayList<IProject>();
|
||||
try {
|
||||
delta.accept(new IResourceDeltaVisitor() {
|
||||
public boolean visit(IResourceDelta innerDelta) throws CoreException {
|
||||
if (innerDelta.getKind() == IResourceDelta.ADDED && innerDelta.getResource().getType() == IResource.PROJECT) {
|
||||
IProject project = (IProject) innerDelta.getResource();
|
||||
if (LegacyProjectsJob.isLegacyProject(project, false)) {
|
||||
projects.add(project);
|
||||
}
|
||||
}
|
||||
// only continue for the workspace root
|
||||
return innerDelta.getResource().getType() == IResource.ROOT;
|
||||
}
|
||||
});
|
||||
} catch (CoreException e) {
|
||||
FrameworkCoreActivator.getDefault().getLog().log(e.getStatus());
|
||||
}
|
||||
return projects;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
ResourcesPlugin.getWorkspace().removeResourceChangeListener(LegacyProjectListener.LISTENER);
|
||||
}
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pivotal Software, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal Software, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.progress.UIJob;
|
||||
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.IConversionConstants;
|
||||
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.LegacyProjectConverter;
|
||||
|
||||
/**
|
||||
* Checks entire workspace for legacy projects
|
||||
*
|
||||
* @author Andrew Eisenberg
|
||||
* @author Leo Dos Santos
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class LegacyProjectsJob extends UIJob implements IConversionConstants {
|
||||
|
||||
private final boolean warnIfNone;
|
||||
private List<IProject> legacyProjects;
|
||||
|
||||
public LegacyProjectsJob(boolean warnIfNone) {
|
||||
super("Legacy STS Project Checker"); //$NON-NLS-1$
|
||||
this.warnIfNone = warnIfNone;
|
||||
}
|
||||
public LegacyProjectsJob(List<IProject> legacyProjects, boolean warnIfNone) {
|
||||
this(warnIfNone);
|
||||
this.legacyProjects = legacyProjects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus runInUIThread(IProgressMonitor monitor) {
|
||||
monitor.beginTask("Checking for legacy STS projects", 100); //$NON-NLS-1$
|
||||
IStatus status = doCheck(monitor, getDisplay().getActiveShell());
|
||||
monitor.done();
|
||||
return status;
|
||||
}
|
||||
|
||||
private IStatus doCheck(IProgressMonitor monitor, Shell shell) {
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
|
||||
SubMonitor sub = SubMonitor.convert(monitor, 100);
|
||||
if (legacyProjects == null) {
|
||||
legacyProjects = findLegacyProjects();
|
||||
}
|
||||
sub.worked(30);
|
||||
if (legacyProjects.size() > 0) {
|
||||
LegacyProjectConverter converter = new LegacyProjectConverter(legacyProjects);
|
||||
if (askToConvert(shell, converter)) {
|
||||
return converter.convert(sub.newChild(70));
|
||||
}
|
||||
} else if (warnIfNone && !LegacySTSChecker.NON_BLOCKING) {
|
||||
MessageDialog.openInformation(shell, "No legacy projects found", "No legacy projects found."); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
private List<IProject> findLegacyProjects() {
|
||||
List<IProject> legacyProjectsList = new ArrayList<IProject>();
|
||||
IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
||||
for (IProject project : allProjects) {
|
||||
try {
|
||||
if (isLegacyProject(project, true)) {
|
||||
legacyProjectsList.add(project);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
// shouldn't happen since we already know project is accessible
|
||||
// don't want to use the regular logging mechanism since that may
|
||||
// load the bundle.
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return legacyProjectsList;
|
||||
}
|
||||
|
||||
public boolean askToConvert(Shell shell, LegacyProjectConverter converter) {
|
||||
if (LegacySTSChecker.NON_BLOCKING) {
|
||||
return false;
|
||||
}
|
||||
|
||||
converter.setSelectedLegacyProjects(ListMessageDialog.openViewer(shell, converter.getAllLegacyProjects().toArray(new IProject[0])));
|
||||
return converter.getSelectedLegacyProjects() != null;
|
||||
}
|
||||
|
||||
public static boolean isLegacyProject(IProject project, boolean isWorkspaceMigration) throws CoreException{
|
||||
return project.isAccessible() &&
|
||||
(
|
||||
// only migrate grails projects at workspace migration time.
|
||||
// imported grails projects are handled by the GrailsProjectVersionFixer
|
||||
(project.hasNature(GRAILS_OLD_NATURE) && isWorkspaceMigration) ||
|
||||
(project.hasNature(ROO_OLD_NATURE) && needsRooPrefMigration(project)) ||
|
||||
//only migrate gradle projects at workspace migration time, GradleImportOperation deals with old natures etc. during project import.
|
||||
(project.hasNature(GRADLE_OLD_NATURE) && isWorkspaceMigration)
|
||||
);
|
||||
}
|
||||
|
||||
private static boolean needsRooPrefMigration(IProject project) {
|
||||
IFolder preferencesFolder = project.getFolder(".settings/"); //$NON-NLS-1$
|
||||
File settingsFile = preferencesFolder.getFile(ROO_NEW_PLUGIN_NAME + ".prefs").getLocation().toFile(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return !settingsFile.exists();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pivotal Software, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal Software, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion;
|
||||
|
||||
import org.eclipse.core.resources.IResourceChangeEvent;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.MultiStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.ui.IPerspectiveDescriptor;
|
||||
import org.eclipse.ui.IPerspectiveRegistry;
|
||||
import org.eclipse.ui.IStartup;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.progress.UIJob;
|
||||
import org.springsource.ide.eclipse.commons.frameworks.core.FrameworkCoreActivator;
|
||||
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.IConversionConstants;
|
||||
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.LegacyWorkspaceConverter;
|
||||
import org.springsource.ide.eclipse.commons.frameworks.ui.FrameworkUIActivator;
|
||||
|
||||
/**
|
||||
* Checks for legacy STS projects in the workspace at startup.
|
||||
* Must be very careful not to accidentally load the rest of STS if
|
||||
* no legacy projects are found
|
||||
*
|
||||
* @author Andrew Eisenberg
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class LegacySTSChecker implements IStartup, IConversionConstants {
|
||||
// set to true during testing mode
|
||||
public static boolean NON_BLOCKING = false;
|
||||
private static final IPreferenceStore PREFERENCE_STORE = FrameworkCoreActivator.getDefault().getPreferenceStore();
|
||||
|
||||
/**
|
||||
* This entry to the checker comes at the startup of the workbench
|
||||
*/
|
||||
public void earlyStartup() {
|
||||
PREFERENCE_STORE.setDefault(AUTO_CHECK_FOR_LEGACY_STS_PROJECTS, true);
|
||||
|
||||
if (shouldPerformProjectCheck()) {
|
||||
Job job = new LegacyProjectsJob(false);
|
||||
job.schedule();
|
||||
ResourcesPlugin.getWorkspace().addResourceChangeListener(LegacyProjectListener.LISTENER, IResourceChangeEvent.POST_CHANGE);
|
||||
}
|
||||
|
||||
if (shouldPerformWorkspaceMigration()) {
|
||||
new UIJob("Convert legacy STS 2.x preferences") { //$NON-NLS-1$
|
||||
@Override
|
||||
public IStatus runInUIThread(IProgressMonitor monitor) {
|
||||
|
||||
IStatus status = new LegacyWorkspaceConverter().convert(monitor);
|
||||
IStatus status2 = new PerspectiveMigrator().migratePerspective(GRAILS_OLD_PERSPECTIVE_ID, GRAILS_NEW_PERSPECTIVE_ID, monitor);
|
||||
MultiStatus statuses = new MultiStatus(FrameworkUIActivator.PLUGIN_ID, 0, new IStatus[] { status, status2 }, "Legacy workspace migration", null);
|
||||
return statuses;
|
||||
}
|
||||
|
||||
}.schedule();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldPerformProjectCheck() {
|
||||
return FrameworkCoreActivator.getDefault().getPreferenceStore().getBoolean(AUTO_CHECK_FOR_LEGACY_STS_PROJECTS);
|
||||
}
|
||||
|
||||
private boolean shouldPerformWorkspaceMigration() {
|
||||
return ! PREFERENCE_STORE.getBoolean(LEGACY_MIGRATION_ALREADY_DONE);
|
||||
}
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pivotal Software, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal Software, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.viewers.CheckboxTableViewer;
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.model.WorkbenchLabelProvider;
|
||||
import org.springsource.ide.eclipse.commons.frameworks.core.FrameworkCoreActivator;
|
||||
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.IConversionConstants;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Andrew Eisenberg
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class ListMessageDialog extends MessageDialogWithToggle implements IConversionConstants {
|
||||
|
||||
class TableContentProvider implements IStructuredContentProvider {
|
||||
public Object[] getElements(Object inputElement) {
|
||||
if (inputElement instanceof IProject[]) {
|
||||
return (IProject[]) inputElement;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void dispose() { }
|
||||
public void inputChanged(Viewer viewer2, Object oldInput, Object newInput) { }
|
||||
}
|
||||
private static final IPreferenceStore PREFERENCE_STORE = FrameworkCoreActivator.getDefault().getPreferenceStore();
|
||||
private static final String PREFERENCE_QUESTION = "Don't show this dialog again."; //$NON-NLS-1$
|
||||
private static final String TITLE = "Should convert legacy STS projects?"; //$NON-NLS-1$
|
||||
|
||||
private final IProject[] legacyProjects;
|
||||
private IProject[] checkedLegacyProjects;
|
||||
|
||||
private CheckboxTableViewer viewer;
|
||||
|
||||
/**
|
||||
* Opens the legacy maven project conversion dialog focusing on the selected projects
|
||||
* @param legacyProjects
|
||||
* @return
|
||||
*/
|
||||
public static IProject[] openViewer(Shell shell, IProject[] legacyProjects) {
|
||||
ListMessageDialog dialog = new ListMessageDialog(shell, legacyProjects);
|
||||
int res = dialog.open();
|
||||
PREFERENCE_STORE.setValue(AUTO_CHECK_FOR_LEGACY_STS_PROJECTS, ! dialog.getToggleState());
|
||||
if (res == IDialogConstants.YES_ID) {
|
||||
return dialog.getAllChecked();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buttonPressed(int buttonId) {
|
||||
if (buttonId == IDialogConstants.YES_ID) {
|
||||
Object[] checkedElements = viewer.getCheckedElements();
|
||||
checkedLegacyProjects = new IProject[checkedElements.length];
|
||||
System.arraycopy(checkedElements, 0, checkedLegacyProjects, 0, checkedElements.length);
|
||||
|
||||
// don't want to do workspace preferences again
|
||||
PREFERENCE_STORE.setValue(LEGACY_MIGRATION_ALREADY_DONE, true);
|
||||
}
|
||||
super.buttonPressed(buttonId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isResizable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public ListMessageDialog(Shell shell, IProject[] legacyProjects) {
|
||||
super(shell, TITLE, null, createMessage(legacyProjects), QUESTION, new String[] { IDialogConstants.YES_LABEL,
|
||||
IDialogConstants.NO_LABEL }, 0, PREFERENCE_QUESTION,
|
||||
PREFERENCE_STORE.getBoolean(AUTO_CHECK_FOR_LEGACY_STS_PROJECTS));
|
||||
this.legacyProjects = legacyProjects;
|
||||
}
|
||||
|
||||
protected Control createCustomArea(Composite parent) {
|
||||
((GridLayout) parent.getLayout()).numColumns = 2;
|
||||
((GridLayout) parent.getLayout()).makeColumnsEqualWidth = false;
|
||||
|
||||
viewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER);
|
||||
GridData gd = new GridData(GridData.FILL_BOTH);
|
||||
gd.heightHint = 150;
|
||||
gd.verticalSpan = 2;
|
||||
viewer.getTable().setLayoutData(gd);
|
||||
viewer.setContentProvider(new TableContentProvider());
|
||||
viewer.setLabelProvider(new WorkbenchLabelProvider());
|
||||
viewer.setInput(legacyProjects);
|
||||
viewer.setAllChecked(true);
|
||||
applyDialogFont(viewer.getControl());
|
||||
createButton(parent, "Select all", new SelectionAdapter() { //$NON-NLS-1$
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
viewer.setAllChecked(true);
|
||||
}
|
||||
});
|
||||
createButton(parent, "Select none", new SelectionAdapter() { //$NON-NLS-1$
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
viewer.setAllChecked(false);
|
||||
}
|
||||
});
|
||||
|
||||
return viewer.getControl();
|
||||
}
|
||||
|
||||
protected Button createButton(Composite parent, String label, SelectionListener listener) {
|
||||
return createButton(parent, label, SWT.PUSH, listener);
|
||||
}
|
||||
|
||||
protected Button createButton(Composite parent, String label, int style, SelectionListener listener) {
|
||||
Button button= new Button(parent, SWT.PUSH);
|
||||
button.setFont(parent.getFont());
|
||||
button.setText(label);
|
||||
button.addSelectionListener(listener);
|
||||
GridData gd= new GridData();
|
||||
gd.horizontalAlignment= GridData.FILL;
|
||||
gd.grabExcessHorizontalSpace= false;
|
||||
gd.verticalAlignment= GridData.BEGINNING;
|
||||
gd.widthHint = 100;
|
||||
|
||||
button.setLayoutData(gd);
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
IProject[] getAllChecked() {
|
||||
return checkedLegacyProjects;
|
||||
}
|
||||
|
||||
private static String createMessage(IProject[] allLegacyProjects) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (allLegacyProjects.length > 1) {
|
||||
sb.append("The following legacy STS projects have been found:\n"); //$NON-NLS-1$
|
||||
} else {
|
||||
sb.append("The following legacy STS project has been found:\n"); //$NON-NLS-1$
|
||||
}
|
||||
if (allLegacyProjects.length > 1) {
|
||||
sb.append("\n** These projects may not compile until they are upgraded to STS 3.0. **\n\n"); //$NON-NLS-1$
|
||||
} else {
|
||||
sb.append("\n** This project may not compile until it is upgraded to STS 3.0. **\n\n"); //$NON-NLS-1$
|
||||
}
|
||||
sb.append("Do you want to upgrade now?\n" + //$NON-NLS-1$
|
||||
"You can choose to upgrade later by going to:\n" + //$NON-NLS-1$
|
||||
"Project -> Configure -> Convert legacy STS projects..."); //$NON-NLS-1$
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 SpringSource, a division of VMware, Inc
|
||||
*
|
||||
* andrew - Initial API and implementation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springsource.ide.eclipse.commons.frameworks.ui.internal.legacyconversion;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.ui.IPerspectiveDescriptor;
|
||||
import org.eclipse.ui.IPerspectiveRegistry;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.internal.WorkbenchPage;
|
||||
import org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.IConversionConstants;
|
||||
import org.springsource.ide.eclipse.commons.frameworks.ui.FrameworkUIActivator;
|
||||
|
||||
/**
|
||||
* Migrates legacy perspectives to new perspectives.
|
||||
*
|
||||
* Actually, we're having a bit of trouble removing the persective from the Perspective bar in the UI, but
|
||||
* this ensures that the new perspective is opened if necessary.
|
||||
* @author Andrew Eisenberg
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class PerspectiveMigrator {
|
||||
public IStatus migratePerspective(String oldPerspectiveId, String newPerspectiveId, IProgressMonitor monitor) {
|
||||
try {
|
||||
monitor = SubMonitor.convert(monitor, "Migrating legacy perspectives", 3);
|
||||
IPerspectiveRegistry registry = PlatformUI.getWorkbench().getPerspectiveRegistry();
|
||||
monitor.worked(1);
|
||||
IWorkbenchPage page = null;
|
||||
try {
|
||||
page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
||||
} catch (NullPointerException e) {
|
||||
// something wasn't initialized...ignore
|
||||
}
|
||||
if (page != null) {
|
||||
if (page.getPerspective() == null || page.getPerspective().getId().equals(oldPerspectiveId)) {
|
||||
IPerspectiveDescriptor newPerspective = registry.findPerspectiveWithId(newPerspectiveId);
|
||||
page.setPerspective(newPerspective);
|
||||
IPerspectiveDescriptor oldPerspective = registry.findPerspectiveWithId(oldPerspectiveId);
|
||||
monitor.worked(1);
|
||||
if (oldPerspective != null) {
|
||||
page.closePerspective(oldPerspective, false, false);
|
||||
registry.deletePerspective(oldPerspective);
|
||||
|
||||
}
|
||||
}
|
||||
// Actually, there is no mechanism to close this kind of perspective
|
||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=381473
|
||||
if (page instanceof WorkbenchPage) {
|
||||
try {
|
||||
Method closePerspectiveMethod = WorkbenchPage.class.getDeclaredMethod("closePerspective", IPerspectiveDescriptor.class, String.class, boolean.class, boolean.class);
|
||||
closePerspectiveMethod.invoke(page, null, IConversionConstants.GRAILS_OLD_PERSPECTIVE_ID, true, false);
|
||||
} catch (Exception e) {
|
||||
// this method doesn't exist on e37. OK to ignore
|
||||
// FrameworkUIActivator.getDefault().getLog().log(new Status(IStatus.INFO, FrameworkUIActivator.PLUGIN_ID, "Cannot use reflection to close legacy perspective on Eclipse 3.7.", e));
|
||||
}
|
||||
}
|
||||
}
|
||||
monitor.worked(1);
|
||||
monitor.done();
|
||||
return new Status(IStatus.OK, FrameworkUIActivator.PLUGIN_ID, "Migrate legacy perspectives.");
|
||||
} catch (Exception e) {
|
||||
return new Status(IStatus.ERROR, FrameworkUIActivator.PLUGIN_ID, "Problem migrating legacy perspectives.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user