You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2009/07/13 15:26:06 UTC
svn commit: r793581 [20/23] - in /felix/trunk/sigil: ./ bld-ivy/
bld-ivy/example/ bld-ivy/example/dependence/
bld-ivy/example/dependence/dependee/ bld-ivy/example/dependence/dependee/src/
bld-ivy/example/dependence/dependee/src/standalone/ bld-ivy/exam...
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositorySetDialog.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositorySetDialog.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositorySetDialog.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositorySetDialog.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.preferences.repository;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+import org.cauldron.sigil.SigilCore;
+import org.cauldron.sigil.model.repository.IRepositoryModel;
+import org.cauldron.sigil.ui.util.DefaultLabelProvider;
+import org.cauldron.sigil.ui.util.DefaultTableProvider;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+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.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class RepositorySetDialog extends TitleAreaDialog {
+
+ private CheckboxTableViewer viewer;
+ private Text nameTxt;
+ private Button upBtn;
+ private Button downBtn;
+ private final String setName;
+ private List<IRepositoryModel> repositories;
+ private final boolean nameEditable;
+ private final Set<String> set;
+
+ private String newName;
+
+ public RepositorySetDialog(Shell shell, Set<String> set) {
+ this(shell, null, true, set);
+ }
+
+ public RepositorySetDialog(Shell parent, RepositoryViewData data, boolean nameEditable, Set<String> set) {
+ super(parent);
+ this.set = set;
+ this.setName = data == null ? "" : data.getName();
+ this.repositories = data == null ? new ArrayList<IRepositoryModel>() : new ArrayList<IRepositoryModel>(Arrays.asList(data.getRepositories()));
+ this.nameEditable = nameEditable;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite area = (Composite) super.createDialogArea(parent);
+ createControl(area);
+ return area;
+ }
+
+ public void createControl(Composite parent) {
+ // controls
+ Composite body = new Composite(parent, SWT.NONE);
+ body.setLayoutData( new GridData(GridData.FILL_BOTH) );
+
+ if ( nameEditable ) {
+ new Label( body, SWT.NONE ).setText( "Name" );
+
+ nameTxt = new Text( body, SWT.BORDER );
+
+ nameTxt.setText(setName);
+
+ nameTxt.addKeyListener( new KeyAdapter() {
+ @Override
+ public void keyReleased(KeyEvent e) {
+ checkComplete();
+ }
+ });
+ }
+
+ Composite table = new Composite(body, SWT.NONE);
+ table.setLayout( new GridLayout(2, false ) );
+ createTable( table );
+
+ // layout
+ body.setLayout( new GridLayout( 2, false ) );
+ if ( nameEditable ) {
+ nameTxt.setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, false) );
+ }
+ table.setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1) );
+ }
+
+ public RepositoryViewData getData() {
+ String name = nameEditable ? newName : setName;
+ IRepositoryModel[] reps = repositories.toArray( new IRepositoryModel[repositories.size()]);
+ return new RepositoryViewData( name, reps );
+ }
+
+ private void checkComplete() {
+ if ( nameEditable ) {
+ String name = nameTxt.getText();
+ if ( !name.equals( setName ) && set.contains( name ) ) {
+ setErrorMessage("Set " + name + " already exists" );
+ Button b = getButton(IDialogConstants.OK_ID);
+ b.setEnabled(false);
+ }
+ }
+ setErrorMessage(null);
+ Button b = getButton(IDialogConstants.OK_ID);
+ b.setEnabled(true);
+ }
+
+
+ @Override
+ protected void okPressed() {
+ if ( nameEditable ) {
+ newName = nameTxt.getText();
+ }
+ repositories = getRepositories();
+ super.okPressed();
+ }
+
+ private void createTable(Composite body) {
+ createViewer(body);
+
+ Composite btns = new Composite(body, SWT.NONE);
+ btns.setLayout( new GridLayout( 1, true ) );
+
+ createButtons(btns);
+
+ // layout
+ viewer.getTable().setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
+ btns.setLayoutData( new GridData( SWT.RIGHT, SWT.TOP, false, false ) );
+ }
+
+ private void createButtons(Composite parent) {
+ upBtn = new Button(parent, SWT.PUSH);
+ upBtn.setText( "Up" );
+ upBtn.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ up();
+ }
+ });
+
+ downBtn = new Button(parent, SWT.PUSH);
+ downBtn.setText( "Down" );
+ downBtn.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ down();
+ }
+ });
+
+ setUpDownEnabled(false);
+ }
+
+ private void up() {
+ IRepositoryModel model = (IRepositoryModel) ((StructuredSelection) viewer.getSelection()).getFirstElement();
+ int i = repositories.indexOf(model);
+ if ( i > 0 ) {
+ repositories.remove( i );
+ repositories.add( i - 1, model );
+ viewer.refresh();
+ }
+ }
+
+ private void down() {
+ IRepositoryModel model = (IRepositoryModel) ((StructuredSelection) viewer.getSelection()).getFirstElement();
+ int i = repositories.indexOf(model);
+ if ( i < repositories.size() - 1 ) {
+ repositories.remove( i );
+ repositories.add( i + 1, model );
+ viewer.refresh();
+ }
+ }
+
+ private void createViewer(Composite parent) {
+ viewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER);
+
+ viewer.addSelectionChangedListener( new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ setUpDownEnabled( !viewer.getSelection().isEmpty() );
+ }
+ });
+
+ viewer.setContentProvider( new DefaultTableProvider() {
+ public Object[] getElements(Object inputElement) {
+ return toArray(inputElement);
+ }
+ });
+
+ viewer.setLabelProvider( new DefaultLabelProvider() {
+ public Image getImage(Object element) {
+ return null;
+ }
+
+ public String getText(Object element) {
+ IRepositoryModel m = (IRepositoryModel) element;
+ return m.getName();
+ }
+ });
+
+ viewer.setInput( repositories );
+
+ for ( IRepositoryModel m : repositories ) {
+ viewer.setChecked(m, true);
+ }
+
+ List<IRepositoryModel> allRepositories = SigilCore.getRepositoryConfiguration().loadRepositories();
+
+ for ( IRepositoryModel m : allRepositories ) {
+ if ( !repositories.contains(m) ) {
+ repositories.add(m);
+ }
+ }
+
+ viewer.refresh();
+ }
+
+ private void setUpDownEnabled(boolean enabled) {
+ upBtn.setEnabled(enabled);
+ downBtn.setEnabled(enabled);
+ }
+
+ private List<IRepositoryModel> getRepositories() {
+ ArrayList<IRepositoryModel> reps = new ArrayList<IRepositoryModel>();
+
+ for ( IRepositoryModel m : repositories ) {
+ if ( viewer.getChecked(m) ) {
+ reps.add( m );
+ }
+ }
+
+ return reps;
+ }
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositorySetsView.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositorySetsView.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositorySetsView.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositorySetsView.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.preferences.repository;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.cauldron.sigil.SigilCore;
+import org.cauldron.sigil.model.repository.IRepositoryModel;
+import org.cauldron.sigil.model.repository.IRepositorySet;
+import org.cauldron.sigil.model.repository.RepositorySet;
+import org.cauldron.sigil.ui.util.DefaultLabelProvider;
+import org.cauldron.sigil.ui.util.DefaultTableProvider;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+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.swt.widgets.Table;
+
+public class RepositorySetsView {
+ private static final String DEFAULT = "default";
+
+ private final RepositoriesPreferencePage page;
+
+ private ArrayList<RepositoryViewData> sets = new ArrayList<RepositoryViewData>();
+
+ private TableViewer setView;
+
+ private RepositoryViewData defaultSet;
+
+ public RepositorySetsView(RepositoriesPreferencePage page) {
+ this.page = page;
+ }
+
+ public Control createContents(Composite parent) {
+ // Create Controls
+ Composite composite = new Composite(parent, SWT.NONE);
+
+ Table table = new Table(composite, SWT.SINGLE | SWT.BORDER);
+
+ // Table Viewer Setup
+ setView = new TableViewer(table);
+
+ setView.setContentProvider( new DefaultTableProvider() {
+ public Object[] getElements(Object inputElement) {
+ return toArray(inputElement);
+ }
+ } );
+
+ defaultSet = new RepositoryViewData(DEFAULT, SigilCore.getRepositoryConfiguration().getDefaultRepositorySet().getRepositories());
+
+ sets.add( defaultSet );
+
+ for( Map.Entry<String, IRepositorySet> e : SigilCore.getRepositoryConfiguration().loadRepositorySets().entrySet() ) {
+ IRepositorySet s = e.getValue();
+ sets.add( new RepositoryViewData( e.getKey(), s.getRepositories() ) );
+ }
+
+ setView.setLabelProvider( new DefaultLabelProvider() {
+ public Image getImage(Object element) {
+ return null;
+ }
+
+ public String getText(Object element) {
+ RepositoryViewData data = (RepositoryViewData) element;
+ return data.getName();
+ }
+ });
+
+ setView.setInput(sets);
+
+ // Layout
+ composite.setLayout(new GridLayout(2, false));
+ table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 6));
+
+ createButtons(composite);
+
+ return composite;
+ }
+
+ private void createButtons(final Composite composite) {
+ final Button add = new Button(composite, SWT.PUSH);
+ add.setText("Add...");
+ add.setEnabled(true);
+
+ final Button edit = new Button(composite, SWT.PUSH);
+ edit.setText("Edit...");
+ edit.setEnabled(false);
+
+ final Button remove = new Button(composite, SWT.PUSH);
+ remove.setText("Remove");
+ remove.setEnabled(false);
+ // Listeners
+ add.addSelectionListener( new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ add(composite);
+ }
+ });
+
+ edit.addSelectionListener( new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ IStructuredSelection sel = (IStructuredSelection) setView.getSelection();
+ edit(composite, sel);
+ }
+ });
+
+ remove.addSelectionListener( new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ IStructuredSelection sel = (IStructuredSelection) setView.getSelection();
+ remove(sel);
+ }
+ });
+
+ setView.addSelectionChangedListener( new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ boolean enabled = !event.getSelection().isEmpty();
+ if ( enabled ) {
+ RepositoryViewData element = (RepositoryViewData) ((IStructuredSelection) event.getSelection()).getFirstElement();
+ edit.setEnabled(true);
+ remove.setEnabled( element != defaultSet );
+ }
+ else {
+ edit.setEnabled(false);
+ remove.setEnabled(false);
+ }
+ }
+ });
+
+ add.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
+ edit.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
+ remove.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
+ }
+
+ private void add(Control parent) {
+ RepositorySetDialog wizard = new RepositorySetDialog(getShell(parent), getNames());
+ if ( wizard.open() == Window.OK ) {
+ sets.add( wizard.getData() );
+ updated();
+ }
+ }
+
+ private void edit(Control parent, IStructuredSelection sel) {
+ RepositoryViewData data = (RepositoryViewData) sel.getFirstElement();
+ RepositorySetDialog wizard = new RepositorySetDialog(getShell(parent), data, data != defaultSet, getNames());
+ if ( wizard.open() == Window.OK ) {
+ if ( data != defaultSet ) {
+ data.setName( wizard.getData().getName() );
+ }
+ data.setRepositories( wizard.getData().getRepositories() );
+ updated();
+ }
+ }
+
+ private Set<String> getNames() {
+ HashSet<String> names = new HashSet<String>();
+
+ for ( RepositoryViewData view : sets ) {
+ if ( view != defaultSet ) {
+ names.add( view.getName() );
+ }
+ }
+
+ return names;
+ }
+
+ private Shell getShell(Control parent) {
+ return parent.getShell();
+ }
+
+ private void remove(IStructuredSelection sel) {
+ if ( sets.remove(sel.getFirstElement())) {
+ updated();
+ }
+ }
+
+ private void updated() {
+ setView.refresh();
+ page.changed();
+ }
+
+ public Map<String, IRepositorySet> getSets() {
+ HashMap<String, IRepositorySet> ret = new HashMap<String, IRepositorySet>();
+
+ for ( RepositoryViewData data : sets ) {
+ if ( data != defaultSet ) {
+ IRepositorySet set = new RepositorySet(data.getRepositories());
+ ret.put( data.getName(), set );
+ }
+ }
+
+ return ret;
+ }
+
+ public IRepositoryModel[] getDefaultRepositories() {
+ return defaultSet.getRepositories();
+ }
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositoryTypeSelectionPage.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositoryTypeSelectionPage.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositoryTypeSelectionPage.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositoryTypeSelectionPage.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.preferences.repository;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.cauldron.sigil.SigilCore;
+import org.cauldron.sigil.model.repository.IRepositoryModel;
+import org.cauldron.sigil.model.repository.IRepositoryType;
+import org.cauldron.sigil.ui.util.DefaultTableProvider;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardSelectionPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+
+public class RepositoryTypeSelectionPage extends WizardSelectionPage implements IWizardPage {
+
+ private static final String TITLE = "Select Repository";
+
+ private TableViewer repositoryView;
+ private IRepositoryModel repositoryElement;
+
+ public RepositoryTypeSelectionPage() {
+ super(TITLE);
+ setTitle(TITLE);
+ }
+
+ public void createControl(Composite parent) {
+ Composite control = new Composite(parent, SWT.NONE);
+
+ // components
+ new Label(control, SWT.NONE).setText("Repositories" );
+ Table table = new Table(control, SWT.SINGLE | SWT.BORDER);
+
+ // layout
+ control.setLayout( new GridLayout(1, true) );
+ table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ // view
+ repositoryView = new TableViewer(table);
+ repositoryView.setLabelProvider( new LabelProvider() {
+ @Override
+ public String getText(Object element) {
+ IRepositoryType rep = (IRepositoryType) element;
+ return rep.getType();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ IRepositoryType rep = (IRepositoryType) element;
+ return rep.getIcon();
+ }
+ });
+
+ repositoryView.setContentProvider( new DefaultTableProvider() {
+ public Object[] getElements(Object inputElement) {
+ return toArray(inputElement);
+ }
+ } );
+
+ repositoryView.addSelectionChangedListener( new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ if ( !event.getSelection().isEmpty() ) {
+ IStructuredSelection sel = (IStructuredSelection) event.getSelection();
+ IRepositoryType type = (IRepositoryType) sel.getFirstElement();
+ repositoryElement = SigilCore.getRepositoryConfiguration().newRepositoryElement(type);
+ selectWizardNode(new RepositoryWizardNode(repositoryElement));
+ }
+ }
+ });
+
+ ArrayList<IRepositoryType> descriptors = new ArrayList<IRepositoryType>(SigilCore.getRepositoryConfiguration().loadRepositoryTypes());
+
+ for ( Iterator<IRepositoryType> i = descriptors.iterator(); i.hasNext(); ) {
+ if ( !i.next().isDynamic() ) {
+ i.remove();
+ }
+ }
+
+ repositoryView.setInput( descriptors );
+
+ setControl(control);
+ }
+
+ public void selectWizardNode(RepositoryWizardNode node) {
+ setSelectedNode(node);
+ }
+
+ public RepositoryWizardNode getSelectedWizardNode() {
+ return (RepositoryWizardNode) getSelectedNode();
+ }
+
+ public IRepositoryModel getRepository() {
+ return repositoryElement;
+ }
+
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositoryViewData.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositoryViewData.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositoryViewData.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositoryViewData.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.preferences.repository;
+
+import org.cauldron.sigil.model.repository.IRepositoryModel;
+
+class RepositoryViewData {
+ private String name;
+ private IRepositoryModel[] reps;
+
+ RepositoryViewData(String name, IRepositoryModel[] reps) {
+ this.name = name;
+ this.reps = reps;
+ }
+
+ String getName() {
+ return name;
+ }
+
+ IRepositoryModel[] getRepositories() {
+ return reps;
+ }
+
+ void setName(String name) {
+ this.name = name;
+ }
+
+ void setRepositories(IRepositoryModel[] reps) {
+ this.reps = reps;
+ }
+
+}
\ No newline at end of file
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositoryWizardNode.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositoryWizardNode.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositoryWizardNode.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/RepositoryWizardNode.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.preferences.repository;
+
+import org.cauldron.sigil.SigilCore;
+import org.cauldron.sigil.model.repository.IRepositoryModel;
+import org.cauldron.sigil.ui.wizard.repository.RepositoryWizard;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.IWizardNode;
+import org.eclipse.swt.graphics.Point;
+
+public class RepositoryWizardNode implements IWizardNode {
+
+ private IRepositoryModel repository;
+
+ private RepositoryWizard wizard;
+
+ public RepositoryWizardNode(IRepositoryModel repository) {
+ this.repository = repository;
+ }
+
+ public void dispose() {
+ if ( wizard != null ) {
+ wizard.dispose();
+ wizard = null;
+ }
+ }
+
+ public Point getExtent() {
+ return new Point(-1, -1);
+ }
+
+ public IWizard getWizard() {
+ if ( wizard == null ) {
+ try {
+ wizard = WizardHelper.loadWizard(repository.getType());
+ wizard.init( repository );
+ } catch (CoreException e) {
+ SigilCore.error( "Failed to create wizard for " + repository.getType(), e);
+ }
+ }
+ return wizard;
+ }
+
+ public IRepositoryModel getRepository() {
+ return repository;
+ }
+
+ public boolean isContentCreated() {
+ return wizard != null;
+ }
+
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/WizardHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/WizardHelper.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/WizardHelper.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/preferences/repository/WizardHelper.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.preferences.repository;
+
+import org.cauldron.sigil.SigilCore;
+import org.cauldron.sigil.model.repository.IRepositoryType;
+import org.cauldron.sigil.ui.SigilUI;
+import org.cauldron.sigil.ui.wizard.repository.RepositoryWizard;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+
+public class WizardHelper {
+ public static RepositoryWizard loadWizard(IRepositoryType type) throws CoreException {
+ IConfigurationElement e = findWizardConfig(type.getId());
+
+ if ( e == null ) {
+ throw SigilCore.newCoreException("No wizard registered for repository " + type, null);
+ }
+
+ return (RepositoryWizard) e.createExecutableExtension("class");
+ }
+
+ public static boolean hasWizard(IRepositoryType type) {
+ return findWizardConfig(type.getId()) != null;
+ }
+
+ private static IConfigurationElement findWizardConfig(String id) {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint p = registry.getExtensionPoint(SigilUI.REPOSITORY_WIZARD_EXTENSION_POINT_ID);
+
+ for ( IExtension e : p.getExtensions() ) {
+ for ( IConfigurationElement c : e.getConfigurationElements() ) {
+ if ( id.equals( c.getAttribute("repository") ) ) {
+ return c;
+ }
+ }
+ }
+
+ return null;
+ }
+
+
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportPackageProposal.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportPackageProposal.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportPackageProposal.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportPackageProposal.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.quickfix;
+
+import org.cauldron.sigil.SigilCore;
+import org.cauldron.sigil.model.ModelElementFactory;
+import org.cauldron.sigil.model.ModelElementFactoryException;
+import org.cauldron.sigil.model.common.VersionRange;
+import org.cauldron.sigil.model.common.VersionRangeBoundingRule;
+import org.cauldron.sigil.model.osgi.IPackageExport;
+import org.cauldron.sigil.model.osgi.IPackageImport;
+import org.cauldron.sigil.model.project.ISigilProjectModel;
+import org.cauldron.sigil.ui.SigilUI;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.osgi.framework.Version;
+
+public class ImportPackageProposal implements IJavaCompletionProposal {
+
+ private IPackageExport e;
+ private ISigilProjectModel n;
+
+ public ImportPackageProposal(IPackageExport e, ISigilProjectModel n) {
+ this.e = e;
+ this.n = n;
+ }
+
+ public int getRelevance() {
+ return 100;
+ }
+
+ public void apply(IDocument document) {
+ try {
+
+ final IPackageImport i = ModelElementFactory.getInstance().newModelElement(IPackageImport.class);
+ i.setPackageName(e.getPackageName());
+ IPreferenceStore store = SigilCore.getDefault().getPreferenceStore();
+ VersionRangeBoundingRule lowerBoundRule = VersionRangeBoundingRule.valueOf(store.getString(SigilCore.DEFAULT_VERSION_LOWER_BOUND));
+ VersionRangeBoundingRule upperBoundRule = VersionRangeBoundingRule.valueOf(store.getString(SigilCore.DEFAULT_VERSION_UPPER_BOUND));
+
+ Version version = e.getVersion();
+ VersionRange selectedVersions = VersionRange.newInstance(version, lowerBoundRule, upperBoundRule);
+ i.setVersions( selectedVersions );
+
+ WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
+ @Override
+ protected void execute(IProgressMonitor monitor)
+ throws CoreException {
+ n.getBundle().getBundleInfo().addImport( i );
+ n.save(null);
+ }
+ };
+
+ SigilUI.runWorkspaceOperation(op, null);
+ } catch (ModelElementFactoryException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public String getAdditionalProposalInfo() {
+ return null;
+ }
+
+ public IContextInformation getContextInformation() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getDisplayString() {
+ return "Import package " + e.getPackageName() + " version " + e.getVersion() + " to bundle";
+ }
+
+ public Image getImage() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Point getSelection(IDocument document) {
+ return null;
+ }
+
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportQuickFixProcessor.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportQuickFixProcessor.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportQuickFixProcessor.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportQuickFixProcessor.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,253 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.quickfix;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.cauldron.sigil.SigilCore;
+import org.cauldron.sigil.model.osgi.IPackageExport;
+import org.cauldron.sigil.model.project.ISigilProjectModel;
+import org.cauldron.sigil.model.util.JavaHelper;
+import org.cauldron.sigil.search.ISearchResult;
+import org.cauldron.sigil.search.SigilSearch;
+import org.cauldron.sigil.ui.SigilUI;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ArrayType;
+import org.eclipse.jdt.core.dom.ClassInstanceCreation;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.SimpleType;
+import org.eclipse.jdt.core.dom.Type;
+import org.eclipse.jdt.internal.corext.dom.ASTNodes;
+import org.eclipse.jdt.ui.text.java.IInvocationContext;
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
+import org.eclipse.jdt.ui.text.java.IProblemLocation;
+import org.eclipse.jdt.ui.text.java.IQuickFixProcessor;
+
+@SuppressWarnings("restriction")
+public class ImportQuickFixProcessor implements IQuickFixProcessor {
+
+ private static final Object SYNC_FLAG = new Object();
+
+ public boolean hasCorrections(ICompilationUnit unit, int problemId) {
+ switch ( problemId ) {
+ case IProblem.ImportNotFound:
+ case IProblem.ForbiddenReference:
+ case IProblem.NotVisibleType:
+ case IProblem.UndefinedType:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ public IJavaCompletionProposal[] getCorrections(IInvocationContext context,
+ IProblemLocation[] locations) throws CoreException {
+ try {
+ HashMap<Object, IJavaCompletionProposal> results = new HashMap<Object, IJavaCompletionProposal>();
+
+ ISigilProjectModel project = findProject(context);
+
+ if ( project != null ) {
+ for ( int i = 0; i < locations.length; i++ ) {
+ switch ( locations[i].getProblemId() ) {
+ case IProblem.ForbiddenReference:
+ handleImportNotFound(project, context, locations[i], results);
+ break;
+ case IProblem.ImportNotFound:
+ handleImportNotFound(project, context, locations[i], results);
+ break;
+ case IProblem.IsClassPathCorrect:
+ handleIsClassPathCorrect(project, context, locations[i], results);
+ break;
+ case IProblem.UndefinedType:
+ handleUndefinedType(project, context, locations[i], results);
+ break;
+ case IProblem.UndefinedName:
+ handleUndefinedName(project, context, locations[i], results);
+ break;
+ }
+ }
+ }
+
+ return (IJavaCompletionProposal[])results.values().toArray(new IJavaCompletionProposal[results.size()]);
+ }
+ catch ( RuntimeException e ) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ private void handleUndefinedName(ISigilProjectModel project,
+ IInvocationContext context, IProblemLocation problem,
+ HashMap<Object, IJavaCompletionProposal> results) {
+ Name node = findNode(context, problem);
+
+ if ( node == null ) {
+ return;
+ }
+ addSearchResults(node, project, results);
+ }
+
+ private void handleIsClassPathCorrect(ISigilProjectModel project, final IInvocationContext context,
+ IProblemLocation problemLocation,
+ final HashMap<Object, IJavaCompletionProposal> results) {
+ for ( final String type : problemLocation.getProblemArguments() ) {
+ final String iPackage = type.substring(0, type.lastIndexOf("."));
+
+ for ( IPackageExport pe : JavaHelper.findExportsForPackage(project, iPackage) ) {
+ results.put( type, new ImportPackageProposal( pe, project ) );
+ }
+ }
+
+ if ( !results.containsKey(SYNC_FLAG) ) {
+ //results.put( SYNC_FLAG, null);
+ }
+ }
+
+ private void handleUndefinedType(ISigilProjectModel project, IInvocationContext context,
+ IProblemLocation problem,
+ HashMap<Object, IJavaCompletionProposal> results) throws CoreException {
+ Name node = findNode(context, problem);
+
+ if ( node == null ) {
+ return;
+ }
+ addSearchResults(node, project, results);
+ }
+
+ private void handleImportNotFound(ISigilProjectModel project, final IInvocationContext context, IProblemLocation location, final HashMap<Object, IJavaCompletionProposal> results) throws CoreException {
+ ASTNode selectedNode= location.getCoveringNode(context.getASTRoot());
+ if (selectedNode == null) return;
+
+ if ( selectedNode instanceof ClassInstanceCreation ) {
+ ClassInstanceCreation c = (ClassInstanceCreation) selectedNode;
+ Type t = c.getType();
+ Name node = findName( t );
+ if ( node != null ) {
+ addSearchResults(node, project, results);
+ }
+ }
+ else {
+ for ( final String iPackage : readPackage(selectedNode, location) ) {
+ if ( !results.containsKey(iPackage) ) {
+ for ( IPackageExport pe : JavaHelper.findExportsForPackage(project, iPackage) ) {
+ results.put( iPackage, new ImportPackageProposal( pe, project ) );
+ }
+ }
+ }
+ }
+ }
+
+ private void addSearchResults(Name node, ISigilProjectModel project,
+ HashMap<Object, IJavaCompletionProposal> results) {
+ for ( ISearchResult result : SigilSearch.findProviders( node.getFullyQualifiedName(), project, null) ) {
+ if ( project.getBundle().findImport( result.getPackageName() ) == null ) {
+ String type = result.getPackageName() + "." + node.getFullyQualifiedName();
+ results.put( type, new ImportSearchResultProposal( SigilUI.getActiveWorkbenchShell(), result, node, project ) );
+ }
+ }
+ }
+
+ private Name findName(Type t) {
+ if ( t.isSimpleType() ) {
+ SimpleType st = (SimpleType) t;
+ return st.getName();
+ }
+ else if ( t.isArrayType() ) {
+ ArrayType at = (ArrayType) t;
+ return findName(at.getElementType());
+ }
+ else {
+ return null;
+ }
+ }
+
+ private Name findNode(IInvocationContext context, IProblemLocation problem) {
+ ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
+ if (selectedNode == null) {
+ return null;
+ }
+
+ while (selectedNode.getLocationInParent() == QualifiedName.NAME_PROPERTY) {
+ selectedNode= selectedNode.getParent();
+ }
+
+ Name node= null;
+
+ if (selectedNode instanceof Type) {
+ node = findName( (Type) selectedNode );
+ } else if (selectedNode instanceof Name) {
+ node= (Name) selectedNode;
+ }
+
+ return node;
+ }
+
+ private ISigilProjectModel findProject(IInvocationContext context) throws CoreException {
+ IProject project = context.getCompilationUnit().getJavaProject().getProject();
+ if ( project.hasNature( SigilCore.NATURE_ID ) ) {
+ return SigilCore.create(project);
+ }
+ else {
+ return null;
+ }
+ }
+
+ private String[] readPackage(ASTNode selectedNode, IProblemLocation location) {
+ ArrayList<String> packages = new ArrayList<String>();
+
+ ImportDeclaration id = (ImportDeclaration) ASTNodes.getParent(selectedNode, ASTNode.IMPORT_DECLARATION);
+
+ if ( id == null ) {
+ MethodInvocation m = (MethodInvocation) ASTNodes.getParent(selectedNode, ASTNode.METHOD_INVOCATION);
+
+ if (m != null) {
+ packages.add( readPackage( m ) );
+ while ( m.getExpression() != null && m.getExpression() instanceof MethodInvocation) {
+ m = (MethodInvocation) m.getExpression();
+ packages.add( readPackage( m ) );
+ }
+ }
+ }
+ else {
+ if ( id.isOnDemand() ) {
+ packages.add(id.getName().toString());
+ }
+ else {
+ String iStr = id.getName().toString();
+ packages.add(iStr.substring(0, iStr.lastIndexOf( "." ) ));
+ }
+ }
+
+ return packages.toArray( new String[packages.size()] );
+ }
+
+ private String readPackage(MethodInvocation m) {
+ return m.resolveMethodBinding().getDeclaringClass().getPackage().getName();
+ }
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportSearchResultProposal.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportSearchResultProposal.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportSearchResultProposal.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportSearchResultProposal.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.quickfix;
+
+import org.cauldron.sigil.SigilCore;
+import org.cauldron.sigil.model.ModelElementFactory;
+import org.cauldron.sigil.model.ModelElementFactoryException;
+import org.cauldron.sigil.model.common.VersionRange;
+import org.cauldron.sigil.model.common.VersionRangeBoundingRule;
+import org.cauldron.sigil.model.osgi.IPackageExport;
+import org.cauldron.sigil.model.osgi.IPackageImport;
+import org.cauldron.sigil.model.project.ISigilProjectModel;
+import org.cauldron.sigil.search.ISearchResult;
+import org.cauldron.sigil.ui.SigilUI;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.internal.corext.dom.ASTNodes;
+import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
+import org.eclipse.jdt.ui.CodeStyleConfiguration;
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.osgi.framework.Version;
+
+public class ImportSearchResultProposal implements IJavaCompletionProposal {
+
+ private ISigilProjectModel project;
+ private ICompilationUnit fCompilationUnit;
+ private final ISearchResult result;
+ private final Shell shell;
+
+ public ImportSearchResultProposal(Shell shell, ISearchResult result, Name node, ISigilProjectModel project) {
+ this.shell = shell;
+ this.result = result;
+ this.project = project;
+ if ( node != null ) {
+ CompilationUnit cu = (CompilationUnit) ASTNodes.getParent(node, ASTNode.COMPILATION_UNIT);
+ this.fCompilationUnit = (ICompilationUnit) cu.getJavaElement();
+ }
+ }
+
+ public int getRelevance() {
+ return 100;
+ }
+
+ public void apply(IDocument document) {
+ IPackageExport e = result.getExport();
+ if ( result.getExport() == null ) {
+ if ( MessageDialog.openQuestion(shell, "Modify " + result.getProvider().getBundleInfo().getSymbolicName(), result.getPackageName() + " is not exported. Do you want to export it now?" ) ) {
+ final IPackageExport pe = ModelElementFactory.getInstance().newModelElement(IPackageExport.class);
+ pe.setPackageName(result.getPackageName());
+ //e.setVersion(version)
+ final ISigilProjectModel mod = result.getProvider().getAncestor(ISigilProjectModel.class);
+ if ( mod == null ) {
+ throw new IllegalStateException( "Attempt to modify binary package export" );
+ }
+ WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
+ @Override
+ protected void execute(IProgressMonitor monitor)
+ throws CoreException {
+ mod.getBundle().getBundleInfo().addExport(pe);
+ mod.save(null);
+ }
+ };
+
+ SigilUI.runWorkspaceOperation(op, null);
+ e = pe;
+ }
+ }
+
+ final IPackageImport i = ModelElementFactory.getInstance().newModelElement(IPackageImport.class);
+ i.setPackageName(e.getPackageName());
+ IPreferenceStore store = SigilCore.getDefault().getPreferenceStore();
+ VersionRangeBoundingRule lowerBoundRule = VersionRangeBoundingRule.valueOf(store.getString(SigilCore.DEFAULT_VERSION_LOWER_BOUND));
+ VersionRangeBoundingRule upperBoundRule = VersionRangeBoundingRule.valueOf(store.getString(SigilCore.DEFAULT_VERSION_UPPER_BOUND));
+
+ Version version = e.getVersion();
+ VersionRange selectedVersions = VersionRange.newInstance(version, lowerBoundRule, upperBoundRule);
+ i.setVersions( selectedVersions );
+
+ WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
+ @Override
+ protected void execute(IProgressMonitor monitor)
+ throws CoreException {
+ project.getBundle().getBundleInfo().addImport( i );
+ project.save(null);
+ }
+ };
+
+ SigilUI.runWorkspaceOperation(op, null);
+ addSourceImport();
+ }
+
+ private void addSourceImport() {
+ // add import
+ try {
+ ImportRewrite rewrite= CodeStyleConfiguration.createImportRewrite(fCompilationUnit, true);
+ rewrite.addImport(result.getClassName());
+ JavaModelUtil.applyEdit(fCompilationUnit, rewrite.rewriteImports(null), false, null);
+ } catch (CoreException e) {
+ SigilCore.error( "Failed to add import", e);
+ }
+ }
+
+ public String getAdditionalProposalInfo() {
+ return null;
+ }
+
+ public IContextInformation getContextInformation() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getDisplayString() {
+ String type = result.getClassName();
+ String loc = result.getExport() == null ? " from " + result.getProvider().getBundleInfo().getSymbolicName() : " version " + result.getExport().getVersion();
+ return "Import " + type + loc;
+ }
+
+ public Image getImage() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Point getSelection(IDocument document) {
+ return null;
+ }
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportedClassReference.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportedClassReference.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportedClassReference.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/quickfix/ImportedClassReference.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.quickfix;
+
+import org.cauldron.sigil.model.osgi.IPackageImport;
+
+public class ImportedClassReference {
+ private IPackageImport pi;
+ private String type;
+
+ public ImportedClassReference(IPackageImport packageImport, String typeName) {
+ this.pi = packageImport;
+ this.type = typeName;
+ }
+
+ public IPackageImport getPackageImport() {
+ return pi;
+ }
+
+ public String getFullType() {
+ return type;
+ }
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/refactor/RenameCompositeRefactoring.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/refactor/RenameCompositeRefactoring.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/refactor/RenameCompositeRefactoring.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/refactor/RenameCompositeRefactoring.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.refactor;
+
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.Refactoring;
+import org.eclipse.ltk.core.refactoring.RefactoringContribution;
+import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+
+public class RenameCompositeRefactoring extends Refactoring {
+
+ @Override
+ public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Change createChange(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/AccumulatorAdapter.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/AccumulatorAdapter.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/AccumulatorAdapter.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/AccumulatorAdapter.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.util;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+public abstract class AccumulatorAdapter<E> implements IAccumulator<E> {
+ public void addElement(E element) {
+ LinkedList<E> list = new LinkedList<E>();
+ list.add(element);
+ addElements(list);
+ };
+
+ public void addElements(Collection<? extends E> elements) {
+ }
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/BackgroundLoadingSelectionDialog.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/BackgroundLoadingSelectionDialog.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/BackgroundLoadingSelectionDialog.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/BackgroundLoadingSelectionDialog.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,487 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.cauldron.sigil.ui.editors.project.IElementDescriptor;
+import org.cauldron.sigil.ui.editors.project.WrappedContentProposal;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.fieldassist.ContentProposalAdapter;
+import org.eclipse.jface.fieldassist.ControlDecoration;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.fieldassist.IContentProposal;
+import org.eclipse.jface.fieldassist.IContentProposalListener;
+import org.eclipse.jface.fieldassist.TextContentAdapter;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTError;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+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.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.progress.IJobRunnable;
+
+public class BackgroundLoadingSelectionDialog<E> extends TitleAreaDialog implements IAccumulator<E> {
+
+ private final ILabelProvider DEFAULT_LABEL_PROVIDER = new LabelProvider() {
+ @SuppressWarnings("unchecked")
+ public String getText(Object element) {
+ String result;
+ if(element instanceof WrappedContentProposal<?>) {
+ WrappedContentProposal<E> contentProposal = (WrappedContentProposal<E>) element;
+ result = contentProposal.getLabel();
+ } else {
+ result = descriptor.getLabel((E) element);
+ }
+ return result;
+ }
+ };
+
+ private final IElementDescriptor<E> DEFAULT_DESCRIPTOR = new IElementDescriptor<E>() {
+ public String getLabel(E element) {
+ return getName(element);
+ }
+ public String getName(E element) {
+ return element == null ? "null" : element.toString();
+ }
+ };
+
+ private final String selectionLabel;
+ private IFilter<? super E> filter;
+ private IElementDescriptor<? super E> descriptor = DEFAULT_DESCRIPTOR;
+ private ILabelProvider labelProvider = DEFAULT_LABEL_PROVIDER;
+ private final boolean multi;
+
+ private final List<E> elements;
+
+ private List<E> selection = null;
+ private String selectedName = null;
+
+ private TableViewer viewer = null;
+ private Comparator<? super E> comparator;
+
+ private HashMap<String, IJobRunnable> background = new HashMap<String, IJobRunnable>();
+
+ public BackgroundLoadingSelectionDialog(Shell parentShell, String selectionLabel, boolean multi) {
+ super(parentShell);
+ elements = new ArrayList<E>();
+ this.selectionLabel = selectionLabel;
+ this.multi = multi;
+ }
+
+ public void setFilter(IFilter<? super E> filter) {
+ this.filter = filter;
+ }
+
+ public void setDescriptor(final IElementDescriptor<? super E> descriptor) {
+ if(descriptor != null) {
+ this.descriptor = descriptor;
+ } else {
+ this.descriptor = DEFAULT_DESCRIPTOR;
+ }
+ }
+
+ public IElementDescriptor<? super E> getDescriptor() {
+ return descriptor;
+ }
+
+ public void setComparator(Comparator<? super E> comparator) {
+ this.comparator = comparator;
+ }
+
+ public void setLabelProvider(ILabelProvider labelProvider) {
+ if(labelProvider != null) {
+ this.labelProvider = labelProvider;
+ } else {
+ this.labelProvider = DEFAULT_LABEL_PROVIDER;
+ }
+ }
+
+ public void addBackgroundJob(String name, IJobRunnable job) {
+ background.put(name, job);
+ }
+
+ @Override
+ public int open() {
+ Job[] jobs = scheduleJobs();
+ try {
+ return super.open();
+ }
+ finally {
+ for ( Job j : jobs ) {
+ j.cancel();
+ }
+ }
+ }
+
+ private Job[] scheduleJobs() {
+ if ( background.isEmpty() ) {
+ return new Job[] {};
+ }
+ else {
+ ArrayList<Job> jobs = new ArrayList<Job>(background.size());
+ for ( Map.Entry<String, IJobRunnable> e : background.entrySet() ) {
+ final IJobRunnable run = e.getValue();
+ Job job = new Job(e.getKey()) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ return run.run(monitor);
+ }
+ };
+ job.schedule();
+ }
+
+ return jobs.toArray( new Job[jobs.size()] );
+ }
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ // Create Controls
+ Composite container = (Composite) super.createDialogArea(parent);
+ Composite composite = new Composite(container, SWT.NONE);
+
+ new Label(composite, SWT.NONE).setText(selectionLabel);
+
+ ContentProposalAdapter proposalAdapter = null;
+ Text txtSelection = null;
+
+ Table table = null;
+ if(multi) {
+ table = new Table(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
+ viewer = new TableViewer(table);
+ viewer.setContentProvider(new ArrayContentProvider());
+ viewer.addFilter(new ViewerFilter() {
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ @SuppressWarnings("unchecked") E castedElement = (E) element;
+ return filter == null || filter.select(castedElement);
+ }
+ });
+ if(comparator != null) {
+ viewer.setSorter(new ViewerSorter() {
+ @Override
+ public int compare(Viewer viewer, Object o1, Object o2) {
+ @SuppressWarnings("unchecked")
+ E e1 = (E) o1;
+ @SuppressWarnings("unchecked")
+ E e2 = (E) o2;
+ return comparator.compare(e1, e2);
+ }
+ });
+ }
+ synchronized (elements) {
+ viewer.setInput(elements);
+ }
+
+ if(labelProvider != null) {
+ viewer.setLabelProvider(labelProvider);
+ }
+ } else {
+ txtSelection = new Text(composite, SWT.BORDER);
+ ControlDecoration selectionDecor = new ControlDecoration(txtSelection, SWT.LEFT | SWT.TOP);
+ FieldDecoration proposalDecor = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
+ selectionDecor.setImage(proposalDecor.getImage());
+ selectionDecor.setDescriptionText(proposalDecor.getDescription());
+
+ ExclusionContentProposalProvider<E> proposalProvider = new ExclusionContentProposalProvider<E>(elements, filter, descriptor);
+
+ proposalAdapter = new ContentProposalAdapter(txtSelection, new TextContentAdapter(), proposalProvider, null, null);
+ proposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
+ if(labelProvider != null) {
+ proposalAdapter.setLabelProvider(labelProvider);
+ }
+
+ if(selectedName != null) {
+ txtSelection.setText(selectedName);
+ }
+ }
+ updateSelection();
+ updateButtons();
+
+ // Hookup listeners
+ if(proposalAdapter != null) {
+ proposalAdapter.addContentProposalListener(new IContentProposalListener() {
+ public void proposalAccepted(IContentProposal proposal) {
+ @SuppressWarnings("unchecked")
+ WrappedContentProposal<E> valueProposal = (WrappedContentProposal<E>) proposal;
+ E selected = valueProposal.getElement();
+ selection = new ArrayList<E>(1);
+ selection.add(selected);
+
+ elementSelected(selected);
+
+ updateButtons();
+ }
+ });
+ }
+ if(txtSelection != null) {
+ txtSelection.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ selectedName = ((Text) e.widget).getText();
+ updateButtons();
+ }
+ });
+ }
+ if(viewer != null) {
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection sel = (IStructuredSelection) event.getSelection();
+ selection = new ArrayList<E>(sel.size());
+ for(Iterator<?> iter = sel.iterator(); iter.hasNext(); ) {
+ @SuppressWarnings("unchecked")
+ E element = (E) iter.next();
+ selection.add(element);
+ }
+ updateButtons();
+ }
+ });
+ viewer.addOpenListener(new IOpenListener() {
+ public void open(OpenEvent event) {
+ if(canComplete()) {
+ setReturnCode(IDialogConstants.OK_ID);
+ close();
+ }
+ }
+ });
+ }
+
+ // Layout
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ if(multi) {
+ composite.setLayout(new GridLayout(1, false));
+ GridData layoutTable = new GridData(SWT.FILL, SWT.FILL, true, true);
+ layoutTable.heightHint = 200;
+ table.setLayoutData(layoutTable);
+ } else {
+ composite.setLayout(new GridLayout(2, false));
+ txtSelection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ }
+
+ return container;
+ }
+
+ protected void elementSelected(E selection) {
+ }
+
+ @Override
+ protected Control createButtonBar(Composite parent) {
+ Control bar = super.createButtonBar(parent);
+ updateButtons();
+ return bar;
+ }
+
+ /**
+ * Can be called from any thread
+ */
+ protected final void updateButtons() {
+ Runnable updateButtonsRunnable = new Runnable() {
+ public void run() {
+ Shell shell = getShell();
+ if(shell != null && !shell.isDisposed()) {
+ Button okButton = getButton(IDialogConstants.OK_ID);
+ if(okButton != null && !okButton.isDisposed()) {
+ okButton.setEnabled(canComplete());
+ }
+ }
+ }
+ };
+ Shell shell = getShell();
+ if (shell != null) {
+ onUIThread(shell, updateButtonsRunnable);
+ }
+ }
+
+ /**
+ * Subclasses may override but must call super.canComplete
+ * @return
+ */
+ protected synchronized boolean canComplete() {
+ boolean result = false;
+
+ if ( selection != null ) {
+ if(multi) {
+ result = selection.size() > 0;
+ } else {
+ E sel = getSelectedElement();
+ result = sel != null && descriptor.getName(sel).equals(selectedName);
+ }
+ }
+
+ return result;
+ }
+
+ public final void addElement(E added) {
+ addElements(Collections.singleton(added));
+ }
+
+ /**
+ * Can be called from any thread
+ */
+ public final void addElements(Collection<? extends E> added) {
+ final LinkedList<E> toAdd = new LinkedList<E>();
+ synchronized (elements) {
+ for ( E e : added ) {
+ if ( !elements.contains(e) ) {
+ elements.add( e );
+ toAdd.add(e);
+ }
+ }
+ Collections.sort(elements, comparator);
+ }
+ if(viewer != null) {
+ onUIThread(viewer.getControl(), new Runnable() {
+ public void run() {
+ if(!viewer.getControl().isDisposed()) {
+ viewer.add( toAdd.toArray() );
+ viewer.refresh();
+ }
+ }
+ });
+ }
+ else {
+
+ }
+ updateSelection();
+ updateButtons();
+ }
+
+ protected void updateSelection() {
+ onUIThread(getShell(), new Runnable() {
+ public void run() {
+ if(selectedName != null) {
+ ArrayList<E> newSelection = new ArrayList<E>();
+ synchronized (elements) {
+ for (E e : elements) {
+ if(selectedName.equals(descriptor.getName(e))) {
+ newSelection.add(e);
+ break;
+ }
+ }
+ }
+ selection = newSelection;
+ }
+ else {
+ selection = Collections.emptyList();
+ }
+ if(viewer != null && !viewer.getControl().isDisposed()) {
+ viewer.setSelection(selection.isEmpty() ? StructuredSelection.EMPTY : new StructuredSelection(selection));
+ }
+ }
+ });
+ }
+
+ private static final void onUIThread(Control control, Runnable r) {
+ if(control != null && !control.isDisposed()) {
+ try {
+ Display display = control.getDisplay();
+ if(Thread.currentThread() == display.getThread()) {
+ // We are on the UI thread already, just do the work
+ r.run();
+ } else {
+ // Not on the UI thread, need to bung over the runnable
+ display.asyncExec(r);
+ }
+ }
+ catch (SWTError e) {
+ if ( e.code == SWT.ERROR_WIDGET_DISPOSED ) {
+ // ignore
+ }
+ else {
+ throw e;
+ }
+ }
+ }
+ }
+
+ public String getSelectedName() {
+ return selectedName;
+ }
+
+ public void setSelectedName(String selectedName) {
+ this.selectedName = selectedName;
+ boolean change = false;
+ if ( selectedName == null ) {
+ if ( selection != null && !selection.isEmpty() ) {
+ change = true;
+ }
+ }
+ else {
+ if ( selection == null ) {
+ change = true;
+ }
+ else if ( selection.size() != 1 || !descriptor.getLabel(selection.get(0)).equals(selectedName)) {
+ change = true;
+ }
+ }
+
+ if ( change ) {
+ updateSelection();
+ updateButtons();
+ }
+ }
+
+ public List<E> getSelectedElements() {
+ return selection;
+ }
+
+ public E getSelectedElement() {
+ E result;
+ if(selection == null || selection.isEmpty()) {
+ result = null;
+ } else {
+ result = selection.get(0);
+ }
+ return result;
+ }
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/ColumnModelLabelProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/ColumnModelLabelProvider.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/ColumnModelLabelProvider.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/ColumnModelLabelProvider.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.util;
+
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+public class ColumnModelLabelProvider extends ColumnLabelProvider {
+
+ private ModelLabelProvider provider = new ModelLabelProvider();
+
+ @Override
+ public Image getImage(Object element) {
+ return provider.getImage(element);
+ }
+
+ @Override
+ public String getText(Object element) {
+ return provider.getText(element);
+ }
+
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultContentProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultContentProvider.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultContentProvider.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultContentProvider.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.util;
+
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+public class DefaultContentProvider implements IContentProvider {
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultLabelProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultLabelProvider.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultLabelProvider.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultLabelProvider.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.util;
+
+import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+
+public abstract class DefaultLabelProvider implements IBaseLabelProvider, ILabelProvider {
+
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ public void dispose() {
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+}
\ No newline at end of file
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultTableProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultTableProvider.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultTableProvider.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultTableProvider.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.util;
+
+import java.util.Collection;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+
+public abstract class DefaultTableProvider extends DefaultContentProvider implements IStructuredContentProvider {
+
+ /**
+ * Utility method to convert the input element to an Object[].
+ *
+ * @param inputElement
+ *
+ * @return if inputElement is null -> empty array <br/>
+ * if inputElement is a {@link Collection} returns {@link Collection#toArray()}<br/>
+ * if inputElement is an Array class cast of inputElement to Object[]<br/>
+ *
+ * @throws IllegalArgumentException if the element cannot be converted.
+ */
+ public Object[] toArray(Object inputElement) {
+ if ( inputElement == null ) {
+ return new Object[] {};
+ }
+ else if ( inputElement instanceof Collection ) {
+ Collection<?> col = (Collection<?>) inputElement;
+ return col.toArray();
+ }
+ else if ( inputElement.getClass().isArray() ) {
+ return (Object[]) inputElement;
+ }
+ else {
+ throw new IllegalArgumentException( "Invalid inputElement " + inputElement.getClass() );
+ }
+ }
+
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultTreeContentProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultTreeContentProvider.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultTreeContentProvider.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/DefaultTreeContentProvider.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.util;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+
+public abstract class DefaultTreeContentProvider extends DefaultContentProvider implements ITreeContentProvider {
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/ExclusionContentProposalProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/ExclusionContentProposalProvider.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/ExclusionContentProposalProvider.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/ExclusionContentProposalProvider.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.cauldron.sigil.ui.editors.project.IElementDescriptor;
+import org.cauldron.sigil.ui.editors.project.WrappedContentProposal;
+import org.cauldron.sigil.utils.GlobCompiler;
+import org.eclipse.jface.fieldassist.IContentProposal;
+import org.eclipse.jface.fieldassist.IContentProposalProvider;
+
+public class ExclusionContentProposalProvider<T> implements
+ IContentProposalProvider {
+
+ private final Collection<? extends T> elements;
+ private final IFilter<? super T> filter;
+ private final IElementDescriptor<? super T> descriptor;
+
+ public ExclusionContentProposalProvider(Collection<? extends T> elements, IFilter<? super T> filter, IElementDescriptor<? super T> descriptor) {
+ this.elements = elements;
+ this.filter = filter;
+ this.descriptor = descriptor;
+ }
+
+ public IContentProposal[] getProposals(String contents, int position) {
+ String matchString = contents.substring(0, position);
+ Pattern pattern = GlobCompiler.compile(matchString);
+
+ // Get a snapshot of the elements
+ T[] elementArray;
+ synchronized (elements) {
+ @SuppressWarnings("unchecked") T[] temp = (T[]) elements.toArray();
+ elementArray = temp;
+ }
+
+ List<IContentProposal> result = new ArrayList<IContentProposal>();
+
+ for (T element : elementArray) {
+ if(filter != null && filter.select(element)) {
+ IContentProposal proposal = WrappedContentProposal.newInstance(element, descriptor);
+ Matcher matcher = pattern.matcher(proposal.getContent());
+ if(matcher.find()) {
+ result.add(proposal);
+ }
+ }
+ }
+
+ return result.toArray(new IContentProposal[result.size()]);
+ }
+
+}
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/ExportedPackageFinder.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/ExportedPackageFinder.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/ExportedPackageFinder.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/ExportedPackageFinder.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.cauldron.sigil.SigilCore;
+import org.cauldron.sigil.model.IModelElement;
+import org.cauldron.sigil.model.IModelWalker;
+import org.cauldron.sigil.model.osgi.IPackageExport;
+import org.cauldron.sigil.model.project.ISigilProjectModel;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.progress.IJobRunnable;
+
+public class ExportedPackageFinder implements IJobRunnable {
+
+ private final IAccumulator<? super IPackageExport> accumulator;
+ private final ISigilProjectModel sigil;
+
+ public ExportedPackageFinder(ISigilProjectModel sigil, IAccumulator<? super IPackageExport> accumulator) {
+ this.sigil = sigil;
+ this.accumulator = accumulator;
+ }
+
+ public IStatus run(final IProgressMonitor monitor) {
+ final List<IPackageExport> exports = new ArrayList<IPackageExport>(ResourcesDialogHelper.UPDATE_BATCH_SIZE);
+ final IModelWalker walker = new IModelWalker() {
+ public boolean visit(IModelElement element) {
+ if ( element instanceof IPackageExport ) {
+ IPackageExport pkgExport = (IPackageExport) element;
+ exports.add(pkgExport);
+
+ if(exports.size() >= ResourcesDialogHelper.UPDATE_BATCH_SIZE) {
+ accumulator.addElements(exports);
+ exports.clear();
+ }
+ }
+ return !monitor.isCanceled();
+ }
+ };
+ SigilCore.getRepositoryManager(sigil).visit(walker);
+ if(exports.size() > 0) {
+ accumulator.addElements(exports);
+ }
+
+ return Status.OK_STATUS;
+ }
+}
\ No newline at end of file
Added: felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/FileUtils.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/FileUtils.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/FileUtils.java (added)
+++ felix/trunk/sigil/org.cauldron.sigil.ui/src/org/cauldron/sigil/ui/util/FileUtils.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cauldron.sigil.ui.util;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class FileUtils {
+ public static void loadFile( Shell shell, Text text, String msg, boolean isDirectory ) {
+ if ( isDirectory ) {
+ DirectoryDialog dialog = new DirectoryDialog(shell, SWT.NONE);
+ dialog.setMessage(msg);
+ String value = dialog.open();
+ if ( value != null ) {
+ text.setText( value );
+ }
+ }
+ else {
+ FileDialog dialog = new FileDialog(shell, SWT.NONE);
+ dialog.setText(msg);
+ String value = dialog.open();
+ if ( value != null ) {
+ text.setText( value );
+ }
+ }
+ }
+
+}