aboutsummaryrefslogtreecommitdiffstats
path: root/rule_api/src
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2011-11-13 03:23:53 -0800
committerTor Norbye <tnorbye@google.com>2011-11-15 13:10:43 +0100
commit326c61cbd946e77d4de08130d9bde55f7785daf0 (patch)
tree418793aa67d2fbb01fa1b3c22afc7091fb71bf48 /rule_api/src
parent0ff515a76142ce48794bdfb098df37f899886535 (diff)
downloadsdk-326c61cbd946e77d4de08130d9bde55f7785daf0.zip
sdk-326c61cbd946e77d4de08130d9bde55f7785daf0.tar.gz
sdk-326c61cbd946e77d4de08130d9bde55f7785daf0.tar.bz2
Support for custom view rule jars
The layout editor already supports providing a classpath of jar files to check for custom views (via the layoutrules.jars property in project.properties). However, once a view rule has been initialized it is never updated. This changeset makes the view rule loader more dynamic, such that it checks the file timestamps of the jar files, and when the jar files are changed it unloads the old rule instances and creates new instances. This makes it a lot easier to develop view rules since you can just update the .jar file and the layout editor automatically picks up the changes (within a couple of seconds; for performance reasons it checks the filestamps at most every couple of seconds (and this is only done lazily of course, so there isn't a file change listener; it just makes sure that if rule loading requests come in more frequently than that it just uses the current class loader). This changeset also adds an AbstractViewRule which implements the IViewRule interface. Without this, implementing a custom view rule will require dozens of methods to be stubbed out (and for the developer to figure out what the methods are and what to do with them). Change-Id: I5f2b84e32e47611fff2d4211411f3039d16eb815
Diffstat (limited to 'rule_api/src')
-rw-r--r--rule_api/src/com/android/ide/common/api/AbstractViewRule.java108
1 files changed, 108 insertions, 0 deletions
diff --git a/rule_api/src/com/android/ide/common/api/AbstractViewRule.java b/rule_api/src/com/android/ide/common/api/AbstractViewRule.java
new file mode 100644
index 0000000..aa0a7fc
--- /dev/null
+++ b/rule_api/src/com/android/ide/common/api/AbstractViewRule.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
+ *
+ * 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 com.android.ide.common.api;
+
+import java.util.List;
+
+/**
+ * Default implementation of an {@link IViewRule}. This is a convenience
+ * implementation which makes it easier to supply designtime behavior for a
+ * custom view and just override the methods you are interested in.
+ */
+public class AbstractViewRule implements IViewRule {
+ public boolean onInitialize(String fqcn, IClientRulesEngine engine) {
+ return true;
+ }
+
+ public void onDispose() {
+ }
+
+ public String getDisplayName() {
+ // Default is to not override the selection display name.
+ return null;
+ }
+
+ // ==== Selection ====
+
+ public List<String> getSelectionHint(INode parentNode, INode childNode) {
+ return null;
+ }
+
+ public void addLayoutActions(List<RuleAction> actions, INode parentNode,
+ List<? extends INode> children) {
+ }
+
+ public void addContextMenuActions(List<RuleAction> actions, INode node) {
+ }
+
+ public void paintSelectionFeedback(IGraphics graphics, INode parentNode,
+ List<? extends INode> childNodes, Object view) {
+ }
+
+ // ==== Drag & drop support ====
+
+ // By default Views do not accept drag'n'drop.
+ public DropFeedback onDropEnter(INode targetNode, Object targetView, IDragElement[] elements) {
+ return null;
+ }
+
+ public DropFeedback onDropMove(INode targetNode, IDragElement[] elements,
+ DropFeedback feedback, Point p) {
+ return null;
+ }
+
+ public void onDropLeave(INode targetNode, IDragElement[] elements, DropFeedback feedback) {
+ // ignore
+ }
+
+ public void onDropped(
+ INode targetNode,
+ IDragElement[] elements,
+ DropFeedback feedback,
+ Point p) {
+ // ignore
+ }
+
+
+ public void onPaste(INode targetNode, Object targetView, IDragElement[] pastedElements) {
+ }
+
+ // ==== Create/Remove hooks ====
+
+ public void onCreate(INode node, INode parent, InsertType insertType) {
+ }
+
+ public void onChildInserted(INode child, INode parent, InsertType insertType) {
+ }
+
+ public void onRemovingChildren(List<INode> deleted, INode parent) {
+ }
+
+ // ==== Resizing ====
+
+ public DropFeedback onResizeBegin(INode child, INode parent, SegmentType horizontalEdge,
+ SegmentType verticalEdge, Object childView, Object parentView) {
+ return null;
+ }
+
+ public void onResizeUpdate(DropFeedback feedback, INode child, INode parent, Rect newBounds,
+ int modifierMask) {
+ }
+
+ public void onResizeEnd(DropFeedback feedback, INode child, final INode parent,
+ final Rect newBounds) {
+ }
+}