--- /dev/null
+/*
+ * Copyright (c) 2003-2004 Christopher Lenz and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Christopher Lenz - initial API and implementation
+ *
+ * $Id: CssPropertyPage.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $
+ */
+
+package net.sourceforge.phpeclipse.css.ui.internal.properties;
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+import net.sourceforge.phpeclipse.css.core.CssCore;
+import net.sourceforge.phpeclipse.css.core.internal.CssCorePreferences;
+import net.sourceforge.phpeclipse.css.core.internal.profiles.ProfileManager;
+import net.sourceforge.phpeclipse.css.core.profiles.IProfileDescriptor;
+import net.sourceforge.phpeclipse.css.core.profiles.IProfileManager;
+import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.Group;
+import org.eclipse.ui.dialogs.PropertyPage;
+
+/**
+ * Property page for CSS projects and files.
+ */
+public class CssPropertyPage extends PropertyPage {
+
+ // Instance Variables ------------------------------------------------------
+
+ private IProfileManager profileManager;
+
+ private boolean useCustomSettings;
+ private Group profileGroup;
+ private Button[] profileButtons;
+ private String selectedProfile;
+
+ // Constructors ------------------------------------------------------------
+
+ /**
+ * Constructor.
+ */
+ public CssPropertyPage() {
+ profileManager = CssCore.getDefault().getProfileManager();
+ }
+
+ // PropertyPage Implementation ---------------------------------------------
+
+ /**
+ * @see org.eclipse.jface.preference.PreferencePage#createContents(Composite)
+ */
+ protected Control createContents(Composite parent) {
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ composite.setLayout(layout);
+
+ Object element = getElement();
+ if (element instanceof IResource) {
+ IResource resource = (IResource) element;
+ try {
+ selectedProfile = resource.getPersistentProperty(
+ ProfileManager.PROFILE_PROPERTY);
+ } catch (CoreException e) {
+ // ignore
+ }
+ }
+ useCustomSettings = (selectedProfile != null);
+ if (selectedProfile == null) {
+ selectedProfile = getInheritedProfile();
+ }
+
+ Button useInheritedSettingsButton =
+ new Button(composite, SWT.RADIO | SWT.LEFT);
+ if (element instanceof IProject) {
+ useInheritedSettingsButton.setText(
+ getString("useWorkspaceSettings")); //$NON-NLS-1$
+ } else if (element instanceof IResource) {
+ useInheritedSettingsButton.setText(
+ getString("useProjectSettings")); //$NON-NLS-1$
+ }
+ useInheritedSettingsButton.setSelection(!useCustomSettings);
+ Button useCustomSettingsButton =
+ new Button(composite, SWT.RADIO | SWT.LEFT);
+ useCustomSettingsButton.setText(
+ getString("useCustomSettings")); //$NON-NLS-1$
+ useCustomSettingsButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ useCustomSettings =
+ ((Button) event.widget).getSelection();
+ updateProfileGroup();
+ }
+ });
+ useCustomSettingsButton.setSelection(useCustomSettings);
+
+ profileGroup = new Group(composite, SWT.SHADOW_ETCHED_IN);
+ layout = new GridLayout();
+ layout.numColumns = 1;
+ profileGroup.setLayout(layout);
+ profileGroup.setText(getString("profile")); //$NON-NLS-1$
+
+ IProfileManager mgr = CssCore.getDefault().getProfileManager();
+ IProfileDescriptor[] profiles = mgr.getProfileDescriptors();
+ Arrays.sort(profiles, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ return ((IProfileDescriptor) o1).getName().compareTo(
+ ((IProfileDescriptor) o2).getName());
+ }
+ });
+
+ profileButtons = new Button[profiles.length];
+ for (int i = 0; i < profiles.length; i++) {
+ Button button = new Button(profileGroup, SWT.RADIO | SWT.LEFT);
+ button.setText(profiles[i].getName());
+ button.setData(profiles[i].getId());
+ if (profiles[i].getId().equals(selectedProfile)) {
+ button.setSelection(true);
+ }
+ button.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ selectedProfile = (String) event.widget.getData();
+ }
+ });
+ profileButtons[i] = button;
+ }
+ updateProfileGroup();
+
+ return composite;
+ }
+
+ /**
+ * @see org.eclipse.jface.preference.IPreferencePage#performOk()
+ */
+ public boolean performOk() {
+ Object element = getElement();
+ if (element instanceof IResource) {
+ IResource resource = (IResource) element;
+ if (useCustomSettings) {
+ profileManager.setProfile(resource, selectedProfile);
+ } else {
+ profileManager.setProfile(resource, null);
+ }
+ }
+ return true;
+ }
+
+ // Private Methods ---------------------------------------------------------
+
+ private String getInheritedProfile() {
+ Object element = getElement();
+ String retVal = null;
+ if (element instanceof IResource) {
+ IProject project = ((IResource) element).getProject();
+ try {
+ retVal = project.getPersistentProperty(
+ ProfileManager.PROFILE_PROPERTY);
+ } catch (CoreException e) {
+ // ignore
+ }
+ }
+ if (retVal == null) {
+ Preferences preferences =
+ CssCore.getDefault().getPluginPreferences();
+ retVal = preferences.getString(CssCorePreferences.PROFILE);
+ }
+ return retVal;
+ }
+
+ private String getString(String key) {
+ return CssUIMessages.getString("CssPropertyPage." + key); //$NON-NLS-1$
+ }
+
+ private void updateProfileGroup() {
+ profileGroup.setEnabled(useCustomSettings);
+ for (int i = 0; i < profileButtons.length; i++) {
+ profileButtons[i].setEnabled(useCustomSettings);
+ }
+ }
+
+}