Commit 339978f0 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

af3.micro refactoring

refs 190
parent fdd67e87
......@@ -11,7 +11,11 @@ Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: fortiss
Export-Package: org.fortiss.af3.project.ui,
org.fortiss.af3.project.ui.compositor,
org.fortiss.af3.project.ui.editor,
org.fortiss.af3.project.ui.execution,
org.fortiss.af3.project.ui.handler,
org.fortiss.af3.project.ui.perspective,
org.fortiss.af3.project.ui.properties,
org.fortiss.af3.project.ui.utils,
org.fortiss.af3.project.ui.wizard
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| 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 |
| |
| http://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.fortiss.af3.project.ui.utils;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ContainerSelectionDialog;
import org.eclipse.ui.dialogs.ISelectionValidator;
/**
* Folder dialog utility class.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public final class FolderDialogUtils {
/**
* Open a folder dialog so that the user can select the output path.
*/
public static final IFolder openFolderDialog() {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell();
ContainerSelectionDialog dialog = new ContainerSelectionDialog(shell,
null, true, "Select target folder or enter path to create it.");
dialog.showClosedProjects(false);
dialog.setValidator(VALIDATOR);
if (dialog.open() == Window.OK) {
final Object[] result = dialog.getResult();
if (result.length != 0) {
Assert.isTrue(result[0] instanceof IPath,
"Expected result[0] to be an IPath");
IPath path = (IPath) result[0];
IFolder folder = ResourcesPlugin.getWorkspace().getRoot()
.getFolder(path);
return folder;
}
}
// User abortion.
return null;
}
/**
* Folder selection validator.
*/
private static final ISelectionValidator VALIDATOR = new ISelectionValidator() {
/** {@inheritDoc} */
@Override
public String isValid(Object selection) {
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace()
.getRoot();
final IProject[] projects = root.getProjects();
// Check for empty path.
if (selection == null || !(selection instanceof IPath)
|| ((IPath) selection).toString().equals("")) {
return "Nothing selected.";
}
// Now we are sure to have a syntactically correct path.
final IPath path = (IPath) selection;
// Check if project exists.
try {
boolean found = false;
for (final IProject p : projects) {
if (root.getProject(path.segment(0)).equals(p)) {
found = true;
}
}
if (!found) {
throw new RuntimeException();
}
} catch (final Exception e) {
return "The given project does not exist.";
}
// Check for folder.
if (path.segmentCount() < 2) {
return "Please select a folder inside of a project.";
}
// All checks passed.
return null;
}
};
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z ratiu $
| |
| Copyright 2011 ForTISS GmbH |
| |
| 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 |
| |
| http://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.fortiss.af3.project.ui.utils;
import org.conqat.lib.commons.string.StringUtils;
/**
* Utility methods for parsing strings into model elements during databinding.
*
* @author ratiu
* @author $Author: ratiu $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class ParsingUtils {
/** Splits a semicolon separated list. */
public static String[] splitList(String text) {
if (StringUtils.isEmpty(text)) {
return new String[0];
}
return text.split(";\\s*");
}
/** Splits a string according to the given separator. */
public static String[] splitString(String text, String separator) {
if (StringUtils.isEmpty(text)) {
return new String[0];
}
return text.split(separator + "\\s*");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment