/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.utils.ui;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.IStructuredSelection;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
public abstract class DesignResourceSelectionPage extends FolderSelectionPage {
public DesignResourceSelectionPage(String title, String description, IStructuredSelection preSelection) {
super(title, description, preSelection);
}
protected abstract String getPathNameUnderDesign();
protected IStructuredSelection getPreSelection(IResource selectedResource) {
if (selectedResource instanceof IFile) {
selectedResource = (IContainer) selectedResource.getParent();
}
if (selectedResource instanceof IContainer) {
IContainer selectedFolder = (IContainer) selectedResource;
while (!(selectedFolder instanceof IProject) && selectedFolder != null) {
if (WGADesignStructureHelper.isDesignFolder(selectedFolder)) {
return new SingleStructuredSelection(selectedFolder.getFolder(new Path(getPathNameUnderDesign())));
}
if (getFilter().select(selectedFolder)) {
return new SingleStructuredSelection(selectedFolder);
}
selectedFolder = selectedFolder.getParent();
}
if (selectedFolder != null) {
return new SingleStructuredSelection(selectedFolder);
}
}
return new SingleStructuredSelection(selectedResource);
}
}