001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU General
007: * Public License Version 2 only ("GPL") or the Common Development and Distribution
008: * License("CDDL") (collectively, the "License"). You may not use this file except in
009: * compliance with the License. You can obtain a copy of the License at
010: * http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
011: * License for the specific language governing permissions and limitations under the
012: * License. When distributing the software, include this License Header Notice in
013: * each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP. Sun
014: * designates this particular file as subject to the "Classpath" exception as
015: * provided by Sun in the GPL Version 2 section of the License file that
016: * accompanied this code. If applicable, add the following below the License Header,
017: * with the fields enclosed by brackets [] replaced by your own identifying
018: * information: "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Contributor(s):
021: *
022: * The Original Software is NetBeans. The Initial Developer of the Original Software
023: * is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
024: * Rights Reserved.
025: *
026: * If you wish your version of this file to be governed by only the CDDL or only the
027: * GPL Version 2, indicate your decision by adding "[Contributor] elects to include
028: * this software in this distribution under the [CDDL or GPL Version 2] license." If
029: * you do not indicate a single choice of license, a recipient has the option to
030: * distribute your version of this file under either the CDDL, the GPL Version 2 or
031: * to extend the choice of license to its licensees as provided above. However, if
032: * you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then
033: * the option applies only if the new code is made subject to such option by the
034: * copyright holder.
035: */
036:
037: package org.netbeans.installer.wizard.components.actions;
038:
039: import java.io.File;
040: import java.util.List;
041: import org.netbeans.installer.product.Registry;
042: import org.netbeans.installer.product.components.Product;
043: import org.netbeans.installer.utils.ErrorManager;
044: import org.netbeans.installer.utils.ResourceUtils;
045: import org.netbeans.installer.utils.SystemUtils;
046: import org.netbeans.installer.utils.exceptions.InitializationException;
047: import org.netbeans.installer.utils.helper.Dependency;
048: import org.netbeans.installer.wizard.components.WizardAction;
049:
050: /**
051: *
052: * @author Kirill Sorokin
053: */
054: public class SetInstallationLocationAction extends WizardAction {
055: public static final String SOURCE_UID_PROPERTY = "source.component";//NOI18N
056: public static final String RELATIVE_LOCATION_PROPERTY = "relative.location";//NOI18N
057:
058: public void execute() {
059: final String uid = getProperty(SOURCE_UID_PROPERTY);
060: final String relativeLocation = getProperty(RELATIVE_LOCATION_PROPERTY);
061:
062: if (uid == null) {
063: ErrorManager.notifyError(ResourceUtils.getString(
064: SetInstallationLocationAction.class,
065: ERROR_SOURCE_UID_NOT_SET_KEY));
066: return;
067: }
068:
069: // we do expect the property container of the wizard to be a product, if
070: // it's not we should fail
071: final Product target = (Product) getWizard().getContext().get(
072: Product.class);
073:
074: final List<Dependency> dependencies = target
075: .getDependencyByUid(uid);
076: final Product source = Registry.getInstance().getProducts(
077: dependencies.get(0)).get(0);
078:
079: if (source == null) {
080: ErrorManager.notifyError(ResourceUtils.getString(
081: SetInstallationLocationAction.class,
082: ERROR_CANNOT_FIND_COMPONENT_KEY, uid));
083: return;
084: }
085:
086: File sourceLocation = null;
087: try {
088: final File location = source.getInstallationLocation();
089: if (SystemUtils.isMacOS()
090: && source.getLogic().wrapForMacOs()
091: && location.getName().endsWith(".app")) {
092: sourceLocation = new File(location,
093: "Contents/Resources/"
094: + location.getName().replaceAll(
095: "\\.app$", ""));
096: } else {
097: sourceLocation = location;
098: }
099: } catch (InitializationException e) {
100: ErrorManager.notifyError(ResourceUtils
101: .getString(SetInstallationLocationAction.class,
102: ERROR_CANNOT_GET_LOGIC_KEY, target
103: .getDisplayName()), e);
104: }
105:
106: final File location;
107: if (relativeLocation != null) {
108: location = new File(sourceLocation, relativeLocation);
109: } else {
110: location = sourceLocation;
111: }
112:
113: target.setInstallationLocation(location.getAbsoluteFile());
114: }
115:
116: public WizardActionUi getWizardUi() {
117: return null; // we do not have any ui for this action
118: }
119:
120: public boolean isCancellable() {
121: return false;
122: }
123:
124: private static final String ERROR_SOURCE_UID_NOT_SET_KEY = "SILA.error.source.uid.not.set";//NOI18N
125: private static final String ERROR_CANNOT_FIND_COMPONENT_KEY = "SILA.error.cannot.find.component";//NOI18N
126: private static final String ERROR_CANNOT_GET_LOGIC_KEY = "SILA.error.cannot.get.logic";//NOI18N
127: }
|